* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --cell: min(30px, calc((100vw - 60px) / 17), calc((100vh - 260px) / 22));
  --bg: #0f1220;
  --panel: #1a1f35;
  --border: #2c3354;
  --text: #e8ecff;
  --muted: #8a93b8;
}

html, body { height: 100%; }

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 15%, #182042 0%, var(--bg) 65%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

.game-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 16px;
}

h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 10px;
  text-indent: 10px;
  background: linear-gradient(90deg, #00e5ff, #b061ff, #ff3b5c);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
}

.layout { display: flex; gap: 16px; align-items: flex-start; }

.board-area { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(10, var(--cell));
  grid-auto-rows: var(--cell);
  gap: 1px;
  padding: 2px;
  background: #0a0d1a;
  border: 2px solid var(--border);
  border-radius: 6px;
}

.cell {
  background: #141a33;
  border-radius: 2px;
}

.c-I { background: #00d9f5; }
.c-O { background: #ffd500; }
.c-T { background: #b061ff; }
.c-S { background: #2ee56b; }
.c-Z { background: #ff3b5c; }
.c-J { background: #3b7bff; }
.c-L { background: #ff9f2e; }

.c-I, .c-O, .c-T, .c-S, .c-Z, .c-J, .c-L {
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.3);
}

.cell.ghost {
  background: transparent;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.28);
}

.side { display: flex; flex-direction: column; gap: 10px; width: 190px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.panel h2 {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--muted);
  margin-bottom: 6px;
}

.panel .value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.next {
  display: grid;
  grid-template-columns: repeat(4, 18px);
  grid-auto-rows: 18px;
  gap: 1px;
  width: fit-content;
  padding: 4px;
  background: #0a0d1a;
  border-radius: 4px;
}

.lb {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}

.lb li {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 1px 4px;
  border-radius: 4px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 0;
}

.lb .lb-rank {
  width: 12px;
  text-align: right;
  opacity: 0.7;
  flex-shrink: 0;
}

.lb .lb-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 0 1 auto;
}

.lb .lb-score {
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

.lb .lb-date {
  margin-left: auto;
  font-size: 11px;
  flex-shrink: 0;
}

.lb li.current {
  background: rgba(0, 217, 245, 0.15);
  color: var(--text);
}

.lb li.current .lb-score { color: #00d9f5; }

.lb li.lb-empty {
  font-style: italic;
  color: var(--muted);
}

.name-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: 100%;
  max-width: 280px;
}

.name-row input {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: #0a0d1a;
  border: 1px solid #46538f;
  border-radius: 6px;
  padding: 7px 10px;
  width: 150px;
}

.name-row input::placeholder { color: var(--muted); }

.name-row input:focus {
  outline: 2px solid rgba(0, 217, 245, 0.6);
  outline-offset: 1px;
}

.name-row .small {
  font-size: 12px;
  padding: 7px 10px;
}

.help {
  font-size: 12px;
  line-height: 1.8;
  color: var(--muted);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  text-align: center;
  background: rgba(8, 10, 22, 0.85);
  border-radius: 6px;
}

.overlay.hidden { display: none; }

.overlay h3 { font-size: 20px; letter-spacing: 3px; }

.overlay p { font-size: 13px; color: var(--muted); }

button {
  font: inherit;
  font-weight: 600;
  color: var(--text);
  background: linear-gradient(180deg, #35406f, #232c4e);
  border: 1px solid #46538f;
  border-radius: 6px;
  padding: 8px 22px;
  cursor: pointer;
}

button:hover { filter: brightness(1.2); }

button:active { transform: translateY(1px); }

.touch { display: none; gap: 8px; margin-top: 2px; }

.touch button {
  width: 54px;
  height: 46px;
  font-size: 18px;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

@media (pointer: coarse) {
  .touch { display: flex; }
  .help { display: none; }
}

@media (max-width: 600px) {
  .layout { flex-direction: column; align-items: center; }
  .side {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    width: auto;
    max-width: 340px;
  }
  .panel { flex: 1 1 45%; }
  .help { display: none; }
}

.admin-btn {
  font-size: 11px;
  padding: 5px 10px;
  opacity: 0.6;
}

.admin-btn:hover { opacity: 1; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 7, 15, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 380px;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  font-size: 15px;
  letter-spacing: 1px;
}

button.icon {
  font: inherit;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 8px;
  border-radius: 4px;
}

button.icon:hover {
  color: #ff3b5c;
  filter: none;
}

.admin-list {
  list-style: none;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 60px;
}

.admin-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #131730;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}

.admin-list .a-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.admin-list .a-meta {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.admin-list li.empty {
  color: var(--muted);
  font-style: italic;
  justify-content: center;
}

.modal-foot {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

#admin-clear.armed {
  background: linear-gradient(180deg, #7a2740, #571c2e);
  border-color: #ff3b5c;
}

.hidden { display: none !important; }
