:root {
  color-scheme: dark;
  --bg: #101114;
  --surface: #191c22;
  --surface-2: #222732;
  --line: #343b49;
  --text: #f4f6fb;
  --muted: #a8b0c0;
  --accent: #27d3a2;
  --accent-2: #f0b84f;
  --danger: #ff6767;
  --ok: #76e06d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(39, 211, 162, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(240, 184, 79, 0.12), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  min-height: 44px;
}

button:hover {
  border-color: var(--accent);
}

.app-shell {
  width: min(1100px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: minmax(320px, 520px) minmax(260px, 340px);
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.game-area {
  width: 100%;
  display: flex;
  justify-content: center;
}

.board-wrap {
  position: relative;
  width: min(100%, 420px, calc((100svh - 48px) / 2));
  aspect-ratio: 1 / 2;
  max-height: calc(100svh - 48px);
  margin: 0;
  background: #07090c;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
  overflow: hidden;
}

#board {
  display: block;
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  background: rgba(10, 12, 16, 0.78);
  text-align: center;
}

.overlay.hidden {
  display: none;
}

.overlay h1 {
  margin: 0;
  font-size: clamp(42px, 8vw, 76px);
  line-height: 1;
}

.overlay p {
  margin: 0;
  color: var(--muted);
}

.overlay button,
.actions button:first-child {
  background: var(--accent);
  border-color: var(--accent);
  color: #07100d;
  font-weight: 800;
}

.side-panel {
  width: 100%;
  display: grid;
  gap: 10px;
}

.brand h1 {
  margin: 0;
  font-size: 42px;
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin: 8px 0 0;
  color: var(--muted);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stats-grid div,
.settings-panel,
.preview-panel,
.rank-panel,
.keys {
  background: rgba(25, 28, 34, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-grid div {
  min-height: 66px;
  padding: 12px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.stats-grid span,
.panel-title {
  color: var(--muted);
  font-size: 13px;
}

.stats-grid strong {
  font-size: 24px;
  line-height: 1;
}

.settings-panel,
.preview-panel,
.rank-panel {
  padding: 12px;
}

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.difficulty button {
  min-height: 38px;
  font-size: 13px;
}

.difficulty button.active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #171104;
  font-weight: 800;
}

.piece-panels {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

#next,
#hold {
  display: block;
  width: 96px;
  height: 96px;
  margin-top: 10px;
  background: #0c0f14;
  border: 1px solid #2a303b;
  border-radius: 8px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.actions button:last-child {
  grid-column: 1 / -1;
}

.rankings {
  margin: 6px 0 0;
  padding-left: 22px;
  color: var(--muted);
  font-size: 13px;
}

.rankings li {
  padding: 2px 0;
}

.rankings strong {
  color: var(--text);
}

.rankings .empty {
  list-style: none;
  margin-left: -22px;
}

.keys {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  color: var(--muted);
  font-size: 13px;
}

.touch-controls {
  grid-column: 1 / -1;
  display: none;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.touch-controls button {
  min-height: 54px;
  font-size: 23px;
  touch-action: manipulation;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(7, 9, 12, 0.74);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-header h2 {
  margin: 0;
  font-size: 24px;
}

.icon-button {
  width: 44px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

.settings-group {
  margin-bottom: 12px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.danger-button {
  width: 100%;
  border-color: rgba(255, 103, 103, 0.62);
  color: #ffd8d8;
}

@media (min-width: 761px) and (max-height: 900px) {
  .app-shell {
    align-items: start;
  }
}

@media (max-width: 760px) {
  .app-shell {
    min-height: 100svh;
    padding: 14px;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 14px;
  }

  .board-wrap {
    width: min(100%, 300px, calc((100svh - 96px) / 2));
    min-width: 180px;
    max-height: calc(100svh - 96px);
  }

  .side-panel {
    order: 3;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .brand {
    display: none;
  }

  .stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .stats-grid div {
    min-height: 62px;
    padding: 10px;
  }

  .stats-grid strong {
    font-size: 20px;
  }

  .preview-panel,
  .rank-panel,
  .keys {
    display: none;
  }

  .touch-controls {
    order: 2;
    display: grid;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}
