:root {
  --bg-1: #0a0f1d;
  --bg-2: #101933;
  --panel: rgba(18, 26, 49, 0.92);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text: #f4f7ff;
  --muted: #96a5cc;
  --grid-bg: #0d152b;
  --cell: #1a2442;
  --cell-border: rgba(255, 255, 255, 0.05);
  --accent: #7c5cff;
  --danger: #ff6f91;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
  --safe-top: max(8px, env(safe-area-inset-top));
  --safe-bottom: max(8px, env(safe-area-inset-bottom));
  --piece-size-desktop: 18px;
  --piece-size-mobile: 14px;
}

* {
  box-sizing: border-box;
  min-width: 0;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(124, 92, 255, 0.18), transparent 30%),
    radial-gradient(circle at bottom, rgba(56, 214, 168, 0.08), transparent 30%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2));
  touch-action: manipulation;
}

body {
  padding: 0;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  padding: var(--safe-top) 8px var(--safe-bottom);
  overflow: hidden;
}

.game-layout {
  width: min(100%, 790px);
  max-width: 100%;
  height: 100%;
  margin: 0 auto;
  display: grid;
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.board-card,
.topbar,
.tray-card,
.modal-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.board-card,
.topbar,
.tray-card {
  border-radius: 22px;
}

.layout-board,
.layout-side,
.side-panel {
  min-height: 0;
  min-width: 0;
}

.side-panel {
  display: grid;
  gap: 10px;
  align-content: start;
  z-index: 1;
}

.topbar {
  padding: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  z-index: 5;
  position: relative;
}

.brand-wrap h1,
.tray-header h2,
.modal-card h2 {
  margin: 0;
}

.brand-wrap {
  min-width: 0;
}

.brand-wrap h1 {
  margin-top: 2px;
  font-size: clamp(1.05rem, 2vw, 1.55rem);
  line-height: 1;
}

.eyebrow,
.tray-subtitle,
.score-label,
.hint-text,
.modal-kicker {
  margin: 0;
  color: var(--muted);
}

.eyebrow,
.modal-kicker {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.language-menu {
  position: relative;
  flex-shrink: 0;
}

.language-menu-button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 14px;
  padding: 8px 10px;
  font-weight: 700;
  font-size: 0.76rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.language-caret {
  color: var(--muted);
  line-height: 1;
}

.language-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 150px;
  padding: 6px;
  border-radius: 16px;
  background: rgba(17, 25, 47, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
  display: grid;
  gap: 4px;
}

.language-dropdown.hidden {
  display: none;
}

.language-option {
  appearance: none;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.language-option:hover,
.language-option.active {
  background: rgba(124, 92, 255, 0.16);
}

.score-wrap {
  display: flex;
  gap: 6px;
}

.score-card {
  min-width: 64px;
  padding: 8px 9px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  text-align: center;
}

.score-label {
  font-size: 0.74rem;
}

.score-card strong {
  display: block;
  font-size: 0.98rem;
  margin-top: 2px;
}

.score-card.best strong {
  color: #fff3b0;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hint-text {
  min-height: 1.2em;
  font-size: 0.76rem;
  line-height: 1.2;
}

.restart-button {
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  background: linear-gradient(180deg, #8f74ff, #7050ff);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(112, 80, 255, 0.3);
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
  flex-shrink: 0;
}

.restart-button:hover,
.restart-button:active {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.restart-button.large {
  width: 100%;
  padding: 14px 20px;
}

.tray-card {
  padding: 10px;
  overflow: hidden;
    height: 100%;
}

.tray-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.tray-header h2 {
  font-size: 1rem;
}

.tray-subtitle {
  font-size: 0.72rem;
}

.pieces-tray {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}

.piece-card {
  min-height: 74px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
  padding: 6px;
  cursor: grab;
  position: relative;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease;
  user-select: none;
  touch-action: none;
  min-width: 0;
  overflow: hidden;
}

.piece-card:hover,
.piece-card:active {
  transform: translateY(-2px);
}

.piece-card.selected,
.piece-card.dragging {
  border-color: rgba(124, 92, 255, 0.75);
  background: rgba(124, 92, 255, 0.12);
  box-shadow:
    0 0 0 2px rgba(124, 92, 255, 0.12),
    0 18px 32px rgba(124, 92, 255, 0.16);
}

.piece-card.dragging {
  opacity: 0.18;
  cursor: grabbing;
}

.piece-card.used,
.piece-card.no-fit {
  opacity: 0.35;
}

.piece-card.used {
  pointer-events: none;
}

.piece-card::after {
  content: "";
  position: absolute;
  inset: auto 10px 10px auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
}

.piece-card.selected::after,
.piece-card.dragging::after {
  background: var(--accent);
  box-shadow: 0 0 14px rgba(124, 92, 255, 0.32);
}

.board-space {
    display: grid;
}
@media (min-width: 790px) {
    .board-space {
        grid-template-columns: 1fr 180px;
    }
    .pieces-tray {
        grid-template-columns: 1fr;
    }
}

.board-card {
  min-height: 0;
  overflow: hidden;
}

.board-frame {
  width: 100%;
  min-height: 0;
    max-height: calc(100vh - 110px);
  align-items: center;
  justify-content: center;
  border-radius: 18px;
  overflow: hidden;
}
@media (max-width: 790px) {
    .board-frame {
        max-height: calc(100vh - 250px);
    }
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  aspect-ratio: 1;
  padding: 6px;
  border-radius: 16px;
  background: var(--grid-bg);
  position: relative;
  user-select: none;
  overflow: hidden;
margin: 0 auto;
}

.board.board-invalid {
  animation: boardShake 220ms ease;
}

.board-cell {
  aspect-ratio: 1;
  border-radius: 9px;
  background: var(--cell);
  border: 1px solid var(--cell-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

.board-cell.placeable {
  box-shadow: 0 0 0 2px rgba(124, 92, 255, 0.22), 0 0 18px rgba(124, 92, 255, 0.12);
}

.board-cell.preview-valid {
  transform: scale(1.04);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.08), 0 0 18px rgba(255, 255, 255, 0.08);
}

.board-cell.preview-invalid {
  box-shadow: 0 0 0 2px rgba(255, 111, 145, 0.32);
}

.board-cell.pop {
  animation: popIn 220ms ease;
}

.board-cell.clearing {
  animation: clearOut 180ms ease forwards;
}

.board-cell.coral,
.piece-cell.coral,
.drag-cell.coral { background: linear-gradient(180deg, #ff8f8f, #ff6f91); }
.board-cell.sky,
.piece-cell.sky,
.drag-cell.sky { background: linear-gradient(180deg, #7ed6ff, #4ea8ff); }
.board-cell.mint,
.piece-cell.mint,
.drag-cell.mint { background: linear-gradient(180deg, #6ff0cf, #38d6a8); }
.board-cell.gold,
.piece-cell.gold,
.drag-cell.gold { background: linear-gradient(180deg, #ffe899, #ffc857); }
.board-cell.violet,
.piece-cell.violet,
.drag-cell.violet { background: linear-gradient(180deg, #b298ff, #7c5cff); }
.board-cell.orange,
.piece-cell.orange,
.drag-cell.orange { background: linear-gradient(180deg, #ffba7b, #ff8a3d); }

.piece-grid,
.drag-ghost-grid {
  display: grid;
  gap: 4px;
}

.piece-cell,
.drag-cell {
  width: var(--piece-size-desktop);
  height: var(--piece-size-desktop);
  border-radius: 5px;
  background: transparent;
}

.piece-cell.filled,
.drag-cell.filled {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 6px 12px rgba(0, 0, 0, 0.18);
}

.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 50;
  padding: 8px;
  border-radius: 16px;
  background: rgba(17, 25, 47, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.28);
  pointer-events: none;
  transform: translate(-50%, -50%);
  backdrop-filter: blur(10px);
}

.drag-ghost.invalid {
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.28), 0 0 0 2px rgba(255, 111, 145, 0.35);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 9, 18, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
  backdrop-filter: blur(8px);
}

.overlay.hidden {
  display: none;
}

.modal-card {
  width: min(100%, 360px);
  padding: 24px;
  border-radius: 28px;
  text-align: center;
}

.modal-card h2 {
  margin-top: 6px;
  font-size: 1.55rem;
}

.modal-score {
  color: var(--muted);
  margin: 12px 0 20px;
  font-size: 1rem;
}

@keyframes popIn {
  0% { transform: scale(0.72); }
  75% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes clearOut {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(0.6); opacity: 0; }
}

@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

@media (max-width: 700px) {
  .topbar {
    padding: 10px;
  }

  .topbar-right {
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
  }

  .language-menu-button {
    padding: 7px 9px;
    font-size: 0.72rem;
  }

  .score-card {
    min-width: 58px;
    padding: 7px 8px;
  }

  .score-card strong {
    font-size: 0.92rem;
  }

  .score-label {
    font-size: 0.7rem;
  }
}

@media (max-width: 540px) {
  .eyebrow {
    display: none;
  }

  .topbar {
    padding: 9px;
    gap: 8px;
  }

  .brand-wrap h1 {
    font-size: 1rem;
  }

  .controls-row {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .hint-text {
    font-size: 0.7rem;
    min-height: 1.1em;
    margin-top: 5px;
  }

  .restart-button {
    padding: 9px 12px;
  }

  .tray-card {
    padding: 9px;
  }

  .tray-header h2 {
    font-size: 0.94rem;
  }

  .tray-subtitle {
    font-size: 0.68rem;
  }

  .pieces-tray {
    gap: 6px;
  }

  .piece-card {
    min-height: 62px;
    padding: 4px;
  }

  .piece-cell,
  .drag-cell {
    width: var(--piece-size-mobile);
    height: var(--piece-size-mobile);
    border-radius: 4px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 6px;
    padding-right: 6px;
  }

  .game-layout {
    gap: 8px;
  }

  .topbar,
  .tray-card,
  .board-card {
    border-radius: 18px;
  }

  .topbar {
    padding: 8px;
  }

  .language-menu-button {
    padding: 6px 8px;
    font-size: 0.68rem;
  }

  .score-wrap {
    gap: 4px;
  }

  .score-card {
    min-width: 52px;
    padding: 6px 6px;
  }

  .hint-text {
    display: none;
  }

  .piece-card {
    min-height: 56px;
  }

  .board {
    padding: 5px;
  }
}