:root {
  --ink: #172033;
  --muted: #5b6780;
  --paper: #fffdf5;
  --panel: #ffffff;
  --mint: #b9fbc0;
  --sky: #9bf6ff;
  --sun: #ffd166;
  --coral: #ff8fab;
  --leaf: #3bb273;
  --line: #172033;
  --shadow: 0 5px 0 var(--line);
  --soft-shadow: 0 16px 28px rgba(23, 32, 51, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 10% 12%, rgba(255, 209, 102, 0.45), transparent 28%),
    radial-gradient(circle at 88% 8%, rgba(155, 246, 255, 0.55), transparent 30%),
    linear-gradient(135deg, #f8ffe5 0%, #e5fbff 48%, #fff0f3 100%);
  color: var(--ink);
  font-family:
    Arial,
    Helvetica,
    sans-serif;
  overflow: auto;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 12px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.brand-block h1,
.panel-heading h2,
.board-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-block h1 {
  font-size: 26px;
  line-height: 1.05;
}

.eyebrow,
.section-kicker {
  margin: 0 0 3px;
  color: #087f8c;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, 78px);
  gap: 7px;
}

.score-tile {
  min-height: 54px;
  padding: 7px 6px;
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--line);
  text-align: center;
}

.score-tile span {
  display: block;
  margin-bottom: 2px;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.score-tile strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
}

.tile-yellow {
  background: var(--sun);
}

.tile-blue {
  background: var(--sky);
}

.tile-green {
  background: var(--mint);
}

.tile-pink {
  background: var(--coral);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
}

.play-panel,
.tool-panel {
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.play-panel {
  min-height: 0;
  padding: 12px;
  background: #dff7ff;
  overflow: visible;
}

.board-wrap {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  min-height: 0;
}

.board-header,
.panel-heading,
.message-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.board-actions {
  display: flex;
  gap: 6px;
}

.icon-btn,
.mini-btn {
  display: inline-grid;
  place-items: center;
  min-width: 34px;
  height: 34px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 3px 0 var(--line);
  font-weight: 900;
}

.icon-btn:hover,
.mini-btn:hover,
.primary-btn:hover,
.segment:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.board-stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 10px;
  border: 2px dashed rgba(23, 32, 51, 0.55);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.56) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.56) 1px, transparent 1px),
    #bdefff;
  background-size: 32px 32px;
  overflow: hidden;
}

.board-grid {
  display: grid;
  width: min(100%, 560px);
  max-height: 100%;
  aspect-ratio: 1;
  border: 4px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--soft-shadow);
  overflow: hidden;
}

.board-cell {
  position: relative;
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(23, 32, 51, 0.28);
  background:
    linear-gradient(135deg, rgba(23, 32, 51, 0.06), rgba(23, 32, 51, 0.015));
}

.board-cell.is-hint {
  animation: cellPulse 900ms ease-in-out 3;
}

.message-row {
  min-height: 36px;
  padding: 7px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 900;
}

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

.tool-panel {
  padding: 12px;
  background: rgba(255, 255, 255, 0.92);
  overflow: visible;
}

.admin-panel {
  display: block;
  background: #fffdf5;
}

.admin-panel .panel-heading {
  grid-column: auto;
}

.admin-panel .field-label,
.admin-panel .text-input,
.admin-panel .segmented {
  grid-column: auto;
}

.admin-panel .upload-box {
  grid-column: auto;
  grid-row: auto;
}

.admin-panel .primary-btn {
  grid-column: auto;
  align-self: end;
}

.tray-panel {
  background: #f2ffd7;
}

.leaderboard-panel {
  background: #fff5f8;
}

.status-pill {
  display: inline-grid;
  min-height: 24px;
  place-items: center;
  padding: 3px 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--sun);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.field-label {
  display: block;
  margin: 8px 0 4px;
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.text-input {
  width: 100%;
  height: 34px;
  padding: 6px 9px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-weight: 800;
  outline: none;
}

.text-input + .field-label {
  margin-top: 8px;
}

.text-input:focus,
.segment:focus-visible,
.primary-btn:focus-visible,
.icon-btn:focus-visible,
.mini-btn:focus-visible,
.upload-box:focus-within {
  outline: 3px solid #087f8c;
  outline-offset: 2px;
}

.upload-box {
  display: grid;
  place-items: center;
  gap: 2px;
  min-height: 68px;
  margin-top: 8px;
  padding: 8px;
  border: 2px dashed var(--line);
  border-radius: 8px;
  background: #fff2bf;
  text-align: center;
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 3px 0 var(--line);
  font-size: 19px;
  font-weight: 900;
  line-height: 1;
}

.upload-box small {
  color: var(--muted);
  font-weight: 800;
  font-size: 11px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.segment,
.primary-btn {
  min-height: 34px;
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--line);
  font-weight: 900;
}

.segment {
  background: #ffffff;
}

.segment.is-active {
  background: var(--sky);
}

.primary-btn {
  width: 100%;
  margin-top: 8px;
  background: var(--leaf);
  color: #ffffff;
}

.tray-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  min-height: 0;
  height: auto;
  padding-top: 8px;
}

.tray-slot {
  min-height: 0;
  aspect-ratio: 1;
  border: 2px dashed rgba(23, 32, 51, 0.35);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.5);
}

.piece {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background-repeat: no-repeat;
  background-color: #ffffff;
  box-shadow:
    0 4px 0 var(--line),
    0 10px 16px rgba(23, 32, 51, 0.14);
  touch-action: none;
  user-select: none;
  will-change: transform;
  transition:
    filter 180ms ease,
    transform 180ms cubic-bezier(0.2, 0.9, 0.2, 1),
    box-shadow 180ms ease,
    opacity 180ms ease;
}

.piece:not(.is-locked):hover {
  filter: saturate(1.05) brightness(1.03);
  transform: translateY(-3px);
}

.piece.is-dragging {
  position: fixed;
  z-index: 50;
  width: var(--drag-size);
  height: var(--drag-size);
  min-height: 0;
  box-shadow:
    0 18px 34px rgba(23, 32, 51, 0.28),
    0 0 0 5px rgba(255, 255, 255, 0.72);
  filter: saturate(1.08) brightness(1.04);
  transform: scale(1.045);
}

.piece.is-locked {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  cursor: default;
  animation: snapIn 420ms cubic-bezier(0.16, 1, 0.3, 1);
}

.piece.is-wrong {
  animation: wobble 260ms cubic-bezier(0.36, 0, 0.66, -0.56);
}

.piece.is-hint {
  animation: piecePulse 850ms ease-in-out 3;
}

.leaderboard-list {
  display: grid;
  gap: 4px;
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
  min-height: 27px;
  padding: 4px 6px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 11px;
  font-weight: 900;
}

.rank-badge {
  display: grid;
  width: 21px;
  height: 21px;
  place-items: center;
  border-radius: 50%;
  background: var(--sun);
}

.preview-card {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 4;
  width: clamp(72px, 18%, 116px);
  aspect-ratio: 1;
  padding: 5px;
  border: 2px solid rgba(23, 32, 51, 0.92);
  border-radius: 8px;
  background: #ffffff;
  box-shadow:
    0 6px 0 rgba(23, 32, 51, 0.88),
    0 14px 22px rgba(23, 32, 51, 0.2);
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  transform: translateY(-8px) scale(0.92);
  visibility: hidden;
}

.preview-card.is-visible {
  animation: previewPop 260ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  visibility: visible;
}

.preview-card img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  object-fit: cover;
}

.preview-timer {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 2px solid rgba(23, 32, 51, 0.9);
  border-radius: 50%;
  color: #172033;
  background: #ffd166;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.preview-progress {
  position: absolute;
  right: 5px;
  bottom: 5px;
  left: 5px;
  height: 5px;
  border-radius: 999px;
  background: #45c979;
  transform-origin: left center;
}

.preview-card.is-visible .preview-progress {
  animation: previewDrain 5s linear forwards;
}

.start-layer {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.64), transparent 38%),
    rgba(21, 32, 52, 0.28);
  backdrop-filter: blur(2px);
}

.start-layer.is-hidden {
  display: none;
}

.start-card {
  display: grid;
  gap: 10px;
  justify-items: center;
  width: min(78%, 260px);
  padding: 18px;
  border: 2px solid rgba(23, 32, 51, 0.94);
  border-radius: 8px;
  background: #ffffff;
  box-shadow:
    0 8px 0 rgba(23, 32, 51, 0.88),
    0 24px 42px rgba(23, 32, 51, 0.25);
  animation: startPop 320ms cubic-bezier(0.16, 1, 0.3, 1);
}

.start-card strong {
  font-size: clamp(22px, 3.4vw, 34px);
  line-height: 1;
}

.start-badge {
  display: grid;
  min-width: 64px;
  min-height: 34px;
  place-items: center;
  padding: 0 12px;
  border: 2px solid rgba(23, 32, 51, 0.9);
  border-radius: 999px;
  color: #172033;
  background: #ffd166;
  box-shadow: 0 3px 0 rgba(23, 32, 51, 0.85);
  font-weight: 900;
}

.start-button {
  max-width: 180px;
  margin-top: 2px;
}

.completion-layer {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: none;
  place-items: center;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 244, 194, 0.72), transparent 36%),
    rgba(21, 32, 52, 0.24);
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.completion-layer.is-visible {
  display: grid;
}

.trophy-burst {
  position: relative;
  display: grid;
  gap: 7px;
  justify-items: center;
  width: min(82%, 320px);
  padding: 18px 18px 16px;
  border: 2px solid rgba(23, 32, 51, 0.9);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 247, 219, 0.96)),
    #fff8d8;
  box-shadow:
    0 8px 0 rgba(23, 32, 51, 0.88),
    0 26px 50px rgba(23, 32, 51, 0.28);
  overflow: hidden;
  animation: trophyPop 680ms cubic-bezier(0.18, 0.95, 0.22, 1.1);
}

.victory-radiance {
  position: absolute;
  inset: -42%;
  background:
    conic-gradient(
      from 8deg,
      rgba(255, 209, 102, 0.08),
      rgba(255, 209, 102, 0.4),
      rgba(255, 209, 102, 0.08),
      rgba(155, 246, 255, 0.28),
      rgba(255, 209, 102, 0.08)
    );
  opacity: 0.8;
  animation: radianceSpin 8s linear infinite;
}

.victory-trophy {
  position: relative;
  z-index: 1;
  width: min(210px, 76%);
  height: auto;
  filter: drop-shadow(0 12px 16px rgba(118, 69, 0, 0.26));
  animation: trophyFloat 2.6s ease-in-out infinite;
}

.trophy-burst strong {
  position: relative;
  z-index: 1;
  font-size: clamp(24px, 4vw, 36px);
  line-height: 1;
}

.victory-score {
  position: relative;
  z-index: 1;
  color: #725118;
  font-size: 13px;
  font-weight: 900;
}

.reward-particle {
  position: fixed;
  left: var(--x);
  top: var(--y);
  z-index: 80;
  width: var(--s);
  height: var(--s);
  border-radius: 999px;
  background: var(--c);
  box-shadow: 0 0 12px var(--c);
  animation: rewardFloat var(--d) cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: none;
}

.sparkle {
  position: fixed;
  z-index: 70;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 209, 102, 0.95);
  box-shadow: 0 0 0 8px rgba(255, 209, 102, 0.22);
  animation: sparklePop 520ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: none;
}

.score-pop {
  position: fixed;
  z-index: 72;
  color: #ffffff;
  padding: 4px 8px;
  border: 2px solid rgba(23, 32, 51, 0.9);
  border-radius: 8px;
  background: linear-gradient(180deg, #45c979, #21935f);
  box-shadow: 0 4px 0 rgba(23, 32, 51, 0.8);
  font-size: 12px;
  font-weight: 900;
  animation: scoreRise 760ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
  pointer-events: none;
}

@keyframes snapIn {
  0% {
    filter: brightness(1.18);
    transform: scale(1.08);
  }
  45% {
    filter: brightness(1.08);
    transform: scale(0.985);
  }
  100% {
    filter: brightness(1);
    transform: scale(1);
  }
}

@keyframes wobble {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

@keyframes piecePulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    filter: brightness(1.06);
    transform: scale(1.035);
    box-shadow:
      0 6px 0 var(--line),
      0 0 0 6px rgba(255, 209, 102, 0.34);
  }
}

@keyframes cellPulse {
  0%,
  100% {
    background-color: rgba(255, 255, 255, 0.4);
  }
  50% {
    background-color: rgba(255, 209, 102, 0.7);
  }
}

@keyframes previewPop {
  0% {
    opacity: 0;
    transform: translateY(-8px) scale(0.92);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes previewDrain {
  to {
    transform: scaleX(0);
  }
}

@keyframes startPop {
  0% {
    opacity: 0;
    transform: translateY(12px) scale(0.94);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes trophyPop {
  0% {
    transform: translateY(22px) scale(0.82);
    opacity: 0;
  }
  62% {
    transform: translateY(-4px) scale(1.025);
    opacity: 1;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes radianceSpin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes trophyFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

@keyframes rewardFloat {
  0% {
    transform: translate(-50%, -50%) scale(0.3);
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1);
    opacity: 0;
  }
}

@keyframes sparklePop {
  0% {
    transform: translate(-50%, -50%) scale(0.2);
    opacity: 0;
  }
  35% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.4);
    opacity: 0;
  }
}

@keyframes scoreRise {
  0% {
    transform: translate(-50%, 6px) scale(0.9);
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -34px) scale(1);
    opacity: 0;
  }
}

@media (min-width: 700px) and (min-height: 560px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    height: 100vh;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-bottom: 0;
    padding: 7px 9px;
  }

  .brand-block h1 {
    font-size: clamp(18px, 2.8vw, 25px);
  }

  .eyebrow,
  .section-kicker {
    font-size: 9px;
    margin-bottom: 2px;
  }

  .score-strip {
    grid-template-columns: repeat(4, minmax(52px, 72px));
    gap: 5px;
  }

  .score-tile {
    min-height: 43px;
    padding: 5px 4px;
  }

  .score-tile span {
    font-size: 9px;
  }

  .score-tile strong {
    font-size: 16px;
  }

  .game-layout {
    display: grid;
    grid-template-columns:
      clamp(158px, 21vw, 280px)
      minmax(270px, 1fr)
      clamp(172px, 25vw, 320px);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 8px;
    min-height: 0;
    height: 100%;
  }

  .side-panel {
    display: contents;
  }

  .play-panel {
    grid-column: 2;
    grid-row: 1 / span 2;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
  }

  .admin-panel {
    grid-column: 1;
    grid-row: 1;
    align-self: start;
  }

  .leaderboard-panel {
    grid-column: 1;
    grid-row: 2;
    align-self: end;
  }

  .tray-panel {
    display: grid;
    grid-column: 3;
    grid-row: 1 / span 2;
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
  }

  .board-wrap {
    gap: 7px;
    height: 100%;
  }

  .board-header,
  .panel-heading,
  .message-row {
    gap: 6px;
  }

  .board-header h2,
  .panel-heading h2 {
    font-size: clamp(16px, 2.1vw, 24px);
    line-height: 1.05;
  }

  .admin-panel .section-kicker,
  .leaderboard-panel .section-kicker,
  .admin-panel .field-label,
  .admin-panel .status-pill,
  .upload-box small {
    display: none;
  }

  .icon-btn,
  .mini-btn {
    min-width: 30px;
    height: 30px;
  }

  .board-stage {
    min-height: 0;
    padding: 7px;
    overflow: hidden;
  }

  .board-grid {
    width: min(100%, 620px, calc(100vh - 166px));
  }

  .tray-grid {
    align-content: start;
    gap: 6px;
    overflow: hidden;
  }

  .tray-slot {
    border-width: 2px;
  }

  .tool-panel {
    padding: 8px;
  }

  .field-label {
    margin: 6px 0 3px;
  }

  .text-input {
    height: 30px;
    padding: 5px 8px;
  }

  .admin-panel .text-input {
    margin-top: 8px;
  }

  .upload-box {
    min-height: 42px;
    margin-top: 6px;
    padding: 5px;
  }

  .upload-box strong {
    font-size: 13px;
  }

  .upload-box small {
    font-size: 9px;
  }

  .upload-icon {
    width: 20px;
    height: 20px;
    font-size: 15px;
  }

  .segmented {
    gap: 4px;
    margin-top: 6px;
  }

  .segment,
  .primary-btn {
    min-height: 29px;
  }

  .primary-btn {
    margin-top: 6px;
  }

  .message-row {
    min-height: 34px;
    padding: 6px 9px;
  }

  .leaderboard-list li {
    grid-template-columns: 22px minmax(0, 1fr);
    min-height: 22px;
    padding: 2px 4px;
    font-size: 10px;
  }

  .leaderboard-list li span:last-child {
    display: none;
  }

  .rank-badge {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 699px) {
  body {
    overflow: auto;
  }

  .app-shell {
    width: 100%;
    height: auto;
    min-height: 100svh;
    padding: 8px 8px calc(142px + env(safe-area-inset-bottom));
    overflow: visible;
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    grid-template-columns: 1fr;
    gap: 7px;
    margin-bottom: 8px;
    padding: 8px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 3px 0 var(--line);
    backdrop-filter: blur(8px);
  }

  .eyebrow,
  .board-header .section-kicker,
  .panel-heading .section-kicker,
  .admin-panel .status-pill {
    display: none;
  }

  .score-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
  }

  .score-tile {
    min-height: 42px;
    padding: 5px 3px;
    border-radius: 7px;
    box-shadow: 0 2px 0 var(--line);
  }

  .score-tile span {
    margin-bottom: 1px;
    font-size: 8px;
  }

  .score-tile strong {
    font-size: clamp(14px, 4vw, 17px);
  }

  .brand-block h1 {
    font-size: clamp(18px, 5.3vw, 22px);
    line-height: 1.05;
  }

  .game-layout {
    grid-template-columns: 1fr;
    gap: 8px;
    height: auto;
    min-height: 0;
  }

  .play-panel {
    min-height: 0;
    padding: 8px;
    overflow: visible;
  }

  .board-wrap {
    gap: 7px;
  }

  .board-header,
  .panel-heading {
    align-items: center;
    flex-direction: row;
    gap: 8px;
  }

  .board-header h2,
  .panel-heading h2 {
    font-size: clamp(16px, 4.8vw, 20px);
    line-height: 1.05;
  }

  .board-actions {
    flex: 0 0 auto;
    gap: 5px;
  }

  .icon-btn,
  .mini-btn {
    min-width: 44px;
    height: 44px;
    box-shadow: 0 2px 0 var(--line);
  }

  .board-stage {
    min-height: 0;
    padding: 6px;
    background-size: 24px 24px;
  }

  .board-grid {
    width: min(100%, calc(100vw - 34px), calc(100svh - 312px), 440px);
  }

  .message-row {
    align-items: center;
    flex-direction: row;
    min-height: 32px;
    padding: 6px 8px;
    gap: 6px;
    font-size: 12px;
  }

  .message-row span:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .side-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
  }

  .tool-panel {
    padding: 8px;
    overflow: visible;
    box-shadow: 0 3px 0 var(--line);
  }

  .tray-panel {
    order: 1;
    position: fixed;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 8px;
    z-index: 38;
    display: grid;
    grid-template-rows: auto 1fr;
    padding: 8px;
    border-radius: 8px;
    background: rgba(242, 255, 215, 0.96);
    box-shadow:
      0 3px 0 var(--line),
      0 16px 34px rgba(23, 32, 51, 0.22);
    backdrop-filter: blur(10px);
  }

  .admin-panel {
    order: 2;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 6px 8px;
  }

  .leaderboard-panel {
    order: 3;
  }

  .tray-panel .panel-heading,
  .leaderboard-panel .panel-heading {
    margin-bottom: 4px;
  }

  .tray-panel .panel-heading {
    min-height: 28px;
  }

  .tray-grid {
    display: flex;
    grid-template-columns: none !important;
    gap: 6px;
    height: auto;
    max-width: 100%;
    padding: 4px 2px 7px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-padding-inline: 2px;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .tray-grid::-webkit-scrollbar {
    height: 7px;
  }

  .tray-grid::-webkit-scrollbar-track {
    border-radius: 999px;
    background: rgba(23, 32, 51, 0.12);
  }

  .tray-grid::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(23, 32, 51, 0.58);
  }

  .tray-slot {
    flex: 0 0 clamp(64px, 20vw, 86px);
    width: clamp(64px, 20vw, 86px);
    border-width: 2px;
    border-radius: 7px;
    scroll-snap-align: start;
  }

  .piece {
    border-width: 2px;
    border-radius: 7px;
    box-shadow:
      0 3px 0 var(--line),
      0 8px 12px rgba(23, 32, 51, 0.12);
  }

  .admin-panel .panel-heading,
  .admin-panel .field-label,
  .admin-panel .text-input,
  .admin-panel .primary-btn {
    grid-column: 1 / -1;
  }

  .field-label {
    margin: 2px 0 -2px;
    font-size: 9px;
  }

  .text-input + .field-label {
    margin-top: 2px;
  }

  .text-input {
    height: 36px;
    padding: 7px 8px;
    font-size: 13px;
  }

  .admin-panel .upload-box {
    grid-column: 1;
    min-height: 46px;
    margin-top: 0;
    padding: 5px;
    gap: 1px;
  }

  .upload-icon {
    width: 22px;
    height: 22px;
    font-size: 16px;
  }

  .upload-box strong {
    font-size: 12px;
  }

  .upload-box small {
    display: none;
  }

  .segmented {
    gap: 4px;
    margin-top: 0;
  }

  .admin-panel .segmented {
    grid-column: 2;
  }

  .segment,
  .primary-btn {
    min-height: 44px;
    box-shadow: 0 2px 0 var(--line);
    font-size: 12px;
  }

  .admin-panel .primary-btn {
    margin-top: 0;
  }

  .leaderboard-list {
    gap: 5px;
    margin-top: 6px;
  }

  .leaderboard-list li {
    min-height: 30px;
    padding: 4px 6px;
    font-size: 11px;
  }

  .preview-card {
    top: 10px;
    right: 10px;
    width: 74px;
  }

  .start-layer,
  .completion-layer {
    padding: 14px;
  }

  .start-card {
    width: min(82%, 230px);
    gap: 8px;
    padding: 16px;
  }

  .start-button {
    max-width: 160px;
  }

  .trophy-burst {
    width: min(86%, 280px);
    padding: 14px;
  }

  .victory-trophy {
    width: min(170px, 72%);
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding: 6px 6px calc(132px + env(safe-area-inset-bottom));
  }

  .topbar {
    padding: 7px;
  }

  .brand-block h1 {
    font-size: 17px;
  }

  .score-strip {
    gap: 3px;
  }

  .score-tile {
    min-height: 38px;
    padding: 4px 2px;
  }

  .score-tile span {
    font-size: 7.5px;
  }

  .score-tile strong {
    font-size: 13px;
  }

  .board-grid {
    width: min(100%, calc(100vw - 28px), calc(100svh - 312px));
  }

  .tray-panel {
    right: 6px;
    bottom: max(6px, env(safe-area-inset-bottom));
    left: 6px;
    padding: 7px;
  }

  .tray-slot {
    flex-basis: 64px;
    width: 64px;
  }

  .admin-panel {
    grid-template-columns: 1fr;
  }

  .admin-panel .upload-box,
  .admin-panel .segmented {
    grid-column: 1 / -1;
  }
}
