:root {
  color-scheme: light;
  --ink: #15202b;
  --muted: #5a6673;
  --page: #f6f8fb;
  --panel: #ffffff;
  --line: rgba(21, 32, 43, 0.14);
  --cell: #e8edf4;
  --cell-line: #d6dde7;
  --blue: #2867df;
  --cyan: #1aa6b7;
  --green: #31a66a;
  --yellow: #f2bd45;
  --red: #e65a64;
  --violet: #7a5ce1;
  --shadow: 0 20px 54px rgba(24, 38, 58, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  touch-action: manipulation;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(40, 103, 223, 0.14), transparent 32%),
    linear-gradient(315deg, rgba(49, 166, 106, 0.14), transparent 34%),
    var(--page);
}

button,
a {
  font: inherit;
}

button {
  min-height: 44px;
}

.game-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: 0 12px 32px rgba(24, 38, 58, 0.1);
  backdrop-filter: blur(12px);
}

.home-link {
  color: var(--ink);
  font-weight: 900;
  text-decoration: none;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.stats span,
.combo {
  min-width: 112px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.stats strong,
.combo strong {
  color: var(--ink);
}

.new-button,
.message-panel button {
  padding: 0 18px;
  border: 1px solid rgba(40, 103, 223, 0.35);
  border-radius: 8px;
  background: var(--blue);
  color: #ffffff;
  font-weight: 900;
  cursor: pointer;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 280px);
  gap: 16px;
  align-items: start;
  margin-top: 16px;
}

.board-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: clamp(3px, 0.7vw, 7px);
  width: min(100%, 72vh, 680px);
  aspect-ratio: 1;
  padding: clamp(6px, 1.2vw, 12px);
  border: 1px solid var(--cell-line);
  border-radius: 8px;
  background: #dfe6ef;
  cursor: grab;
  touch-action: none;
}

.board:active {
  cursor: grabbing;
}

.cell {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(21, 32, 43, 0.06);
  border-radius: 6px;
  background: var(--cell);
  transition: background-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.cell.filled {
  background: var(--block-color);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.13), inset 0 3px 0 rgba(255, 255, 255, 0.26);
}

.cell.preview {
  background: var(--block-color);
  opacity: 0.58;
  box-shadow: inset 0 0 0 2px var(--block-color);
}

.cell.bad-preview {
  background: rgba(230, 90, 100, 0.28);
  box-shadow: inset 0 0 0 2px rgba(230, 90, 100, 0.62);
}

.cell.filled.bad-preview {
  background: var(--block-color);
  outline: 3px solid rgba(230, 90, 100, 0.82);
  outline-offset: -3px;
}

.cell.clearing {
  transform: scale(0.68);
  background: #ffffff;
}

.side-panel {
  display: grid;
  gap: 12px;
}

.combo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 54px;
}

.pieces {
  display: grid;
  gap: 12px;
}

.piece {
  display: grid;
  place-items: center;
  min-height: 116px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 12px 30px rgba(24, 38, 58, 0.08);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.piece.next {
  border-color: rgba(40, 103, 223, 0.42);
  box-shadow: 0 14px 32px rgba(40, 103, 223, 0.14);
}

.piece:active {
  cursor: grabbing;
}

.piece.used {
  opacity: 0.28;
  pointer-events: none;
}

.piece-grid {
  display: grid;
  gap: 5px;
}

.mini-cell {
  width: var(--mini-size, 24px);
  height: var(--mini-size, 24px);
  border-radius: 5px;
}

.mini-cell.on {
  background: var(--block-color);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.14), inset 0 2px 0 rgba(255, 255, 255, 0.28);
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  pointer-events: none;
  opacity: 0.92;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 16px 22px rgba(24, 38, 58, 0.22));
}

.message-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(430px, calc(100% - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 18px 48px rgba(24, 38, 58, 0.18);
  text-align: center;
  transform: translate(-50%, -50%);
}

.message-panel[hidden] {
  display: none;
}

.message-kicker {
  margin: 0 0 8px;
  color: var(--blue);
  font-weight: 900;
  text-transform: uppercase;
}

.message-panel h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.message-panel p {
  margin: 0 0 16px;
  color: var(--muted);
  font-weight: 700;
  line-height: 1.45;
}

@media (max-width: 820px) {
  .game-shell {
    width: min(100% - 18px, 1180px);
    padding-top: 10px;
  }

  .topbar {
    flex-wrap: wrap;
  }

  .home-link {
    width: 100%;
  }

  .stats {
    flex: 1 1 auto;
    justify-content: flex-start;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    padding: 8px;
  }

  .board {
    width: min(100%, 92vw);
  }

  .side-panel {
    position: sticky;
    bottom: 0;
    z-index: 10;
    margin: 0 -9px -22px;
    padding: 10px 9px 14px;
    border-top: 1px solid var(--line);
    background: rgba(246, 248, 251, 0.94);
    backdrop-filter: blur(12px);
  }

  .combo {
    min-height: 46px;
  }

  .pieces {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .piece {
    min-height: 98px;
    padding: 8px;
  }

  .mini-cell {
    width: var(--mini-mobile-size, 18px);
    height: var(--mini-mobile-size, 18px);
  }
}

@media (max-width: 430px) {
  .stats span {
    min-width: 0;
    flex: 1 1 128px;
  }

  .new-button {
    flex: 0 0 76px;
    padding: 0 12px;
  }

  .board {
    gap: 3px;
    padding: 6px;
  }

  .cell {
    border-radius: 4px;
  }

  .piece {
    min-height: 88px;
  }
}
