:root {
  color-scheme: light;
  --ink: #211b18;
  --muted: #6f625b;
  --line: #d9ccc2;
  --paper: #fffaf2;
  --panel: #ffffff;
  --berry: #c43f63;
  --cream: #f7e7a6;
  --cream-border: #b58b32;
  --cocoa: #6e3f2a;
  --mint: #1f8a70;
  --gold: #d9a441;
  --shadow: 0 18px 45px rgba(69, 47, 31, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(31, 138, 112, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(196, 63, 99, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 44px 44px;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  min-height: 42px;
  padding: 0 16px;
}

button:hover {
  transform: translateY(-1px);
}

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

.secondary,
.level-btn,
.mode-btn {
  background: #f4ece4;
  color: var(--ink);
  border: 1px solid var(--line);
}

.active {
  background: var(--mint);
  color: #fff;
  border-color: var(--mint);
}

.shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0 42px;
}

.topbar {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  padding: 2px 0 10px;
}

.mode-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  flex: 0 0 auto;
  gap: 2px;
  width: 118px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.72);
}

.mode-toggle-btn {
  min-width: 0;
  min-height: 22px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  padding: 0 5px;
  font-size: 0.62rem;
  white-space: nowrap;
}

.mode-toggle-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.eyebrow,
.player-id,
.panel-heading span,
.level-pill {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.18rem, 2.2vw, 1.55rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
}

.identity {
  width: min(360px, 100%);
}

.identity label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  margin-bottom: 6px;
  text-transform: uppercase;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
}

.player-id {
  display: block;
  margin-top: 6px;
  text-align: right;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(600px, 1fr) minmax(360px, 430px);
  grid-template-areas: "clues play";
  gap: 18px;
  align-items: start;
}

.puzzle-panel {
  grid-area: clues;
}

.play-column {
  grid-area: play;
  display: grid;
  gap: 12px;
  justify-items: center;
}

.play-column > * {
  width: 100%;
}

.mobile-tabs {
  display: none;
}

.mobile-section-title {
  display: none;
}

.action-zone {
  display: grid;
  justify-items: center;
  gap: 8px;
}

.panel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.puzzle-panel,
.pieces-panel {
  padding: 16px;
}

.mode-row,
.practice-row {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-row {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.practice-row {
  grid-template-columns: repeat(2, 1fr);
}

.mode-label {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  font-weight: 900;
  padding: 0 12px;
}

.settings-panel {
  display: grid;
  gap: 14px;
}

.practice-controls {
  display: grid;
  gap: 10px;
}

.compact-btn {
  min-height: 34px;
  padding: 0 12px;
}

.practice-start-btn {
  width: 100%;
}

.level-btn {
  min-height: 34px;
  padding: 0 8px;
  font-size: 0.82rem;
}

.puzzle-meta,
.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.puzzle-meta {
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.puzzle-title {
  font-size: 1.05rem;
  font-weight: 900;
}

.level-pill,
#dailyLevelBadge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #f3e7da;
  color: var(--ink);
  padding: 0 10px;
}

.timer {
  min-width: 78px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  padding: 8px 10px;
  text-align: center;
}

.clues {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.clue-card:has(.line-pattern-clue) {
  grid-column: 1 / -1;
}

.clue-card:has(.line-pattern-clue.embedded-pattern) {
  grid-column: auto;
}

.clue-card {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 104px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
  overflow: hidden;
  padding: 12px 8px;
}

.clue-number {
  position: absolute;
  top: 7px;
  left: 8px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 900;
}

.text-clue {
  margin: 0;
  padding: 0 6px;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 850;
  line-height: 1.25;
  text-align: center;
}

.clue-detail {
  display: none;
}

.mini-tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 88px;
  aspect-ratio: 1;
  gap: 4px;
  padding: 6px;
  border: 6px solid #7f5037;
  border-radius: 8px;
  background: #b9875e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.mini-cell {
  display: grid;
  place-items: center;
  min-width: 0;
  border: 1px solid rgba(80, 45, 28, 0.42);
  border-radius: 4px;
  background: #f8dfbd;
}

.active-mini-cell {
  background: #fff7df;
  box-shadow: inset 0 0 0 2px var(--mint);
}

.blocked-mini-cell {
  position: relative;
  background: #ead7bf;
}

.blocked-mini-cell::before,
.blocked-mini-cell::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 14%;
  width: 72%;
  height: 3px;
  border-radius: 999px;
  background: #b8324f;
}

.blocked-mini-cell::before {
  transform: rotate(45deg);
}

.blocked-mini-cell::after {
  transform: rotate(-45deg);
}

.line-clue,
.corner-clue,
.line-pattern-clue,
.relationship-clue {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
}

.relationship-clue {
  gap: 5px;
  width: fit-content;
  max-width: 100%;
  padding: 8px;
  border: 6px solid #7f5037;
  border-radius: 8px;
  background: #b9875e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.clue-piece-token {
  display: grid;
  place-items: center;
  width: 38px;
  aspect-ratio: 1;
  border-radius: 8px;
  background: transparent;
}

.relationship-clue .clue-piece-token {
  width: 44px;
  border: 1px solid rgba(80, 45, 28, 0.42);
  border-radius: 6px;
  background: #f8dfbd;
}

.relation-symbol {
  position: relative;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
}

.touch .relation-symbol {
  flex-basis: 18px;
  width: 18px;
}

.touch .relation-symbol::before,
.touch .relation-symbol::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: var(--mint);
}

.touch .relation-symbol::before {
  top: 50%;
  left: 2px;
  right: 2px;
  height: 3px;
  transform: translateY(-50%);
}

.touch .relation-symbol::after {
  top: 2px;
  bottom: 2px;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
}

.same-row .relation-symbol,
.same-col .relation-symbol {
  border: 2px solid var(--mint);
  border-radius: 5px;
}

.same-row .relation-symbol::before,
.same-col .relation-symbol::before {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: var(--mint);
}

.same-row .relation-symbol::before {
  top: 50%;
  left: 3px;
  right: 3px;
  height: 3px;
  transform: translateY(-50%);
}

.same-col .relation-symbol::before {
  top: 3px;
  bottom: 3px;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
}

.line-pattern-clue.col {
  align-items: center;
}

.line-pattern-clue.embedded-pattern {
  gap: 0;
}

.line-pattern {
  display: grid;
  grid-template-columns: repeat(3, 34px);
  gap: 4px;
  padding: 6px;
  border: 6px solid #7f5037;
  border-radius: 8px;
  background: #b9875e;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.line-pattern.col {
  grid-template-columns: 34px;
  grid-template-rows: repeat(3, 34px);
}

.pattern-cell {
  display: grid;
  place-items: center;
  width: 34px;
  aspect-ratio: 1;
  border: 1px solid rgba(80, 45, 28, 0.42);
  border-radius: 6px;
  background: #f8dfbd;
}

.pattern-cell .piece {
  width: 26px;
}

.wildcard-token {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  aspect-ratio: 1;
  border: 2px dashed rgba(31, 138, 112, 0.82);
  border-radius: 6px;
  color: #0d5f55;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(31, 138, 112, 0.28) 0 3px,
      transparent 3px 7px
    ),
    #e4fff7;
}

.wildcard-token::after {
  content: "?";
  font-size: 0.74rem;
  font-weight: 950;
  line-height: 1;
}

.mini-cell .wildcard-token {
  width: 15px;
  border-width: 1.5px;
  border-radius: 4px;
  background:
    repeating-linear-gradient(
      -45deg,
      rgba(31, 138, 112, 0.32) 0 2px,
      transparent 2px 5px
    ),
    #e4fff7;
}

.mini-cell .wildcard-token::after {
  font-size: 0.48rem;
}

.shape-property-token,
.line-piece-token {
  position: relative;
  display: grid;
  place-items: center;
  width: 30px;
  aspect-ratio: 1;
  background: var(--marker-border, var(--cream-border));
  color: var(--marker-text, var(--ink));
  clip-path: polygon(50% 3%, 61% 34%, 94% 35%, 68% 55%, 78% 88%, 50% 69%, 22% 88%, 32% 55%, 6% 35%, 39% 34%);
  filter: drop-shadow(0 4px 4px rgba(71, 45, 28, 0.16));
  font-size: 0.66rem;
  font-weight: 950;
  line-height: 1;
}

.shape-property-token {
  --marker-border: #0f766d;
  --marker-fill: repeating-linear-gradient(
      -45deg,
      rgba(15, 118, 109, 0.3) 0 3px,
      transparent 3px 6px
    ),
    #dffbf4;
  --marker-text: #073f39;
}

.shape-property-token::before,
.line-piece-token::before {
  content: "";
  position: absolute;
  inset: 3px;
  background: var(--marker-fill, var(--cream));
  clip-path: inherit;
}

.shape-property-token::after,
.line-piece-token::after {
  content: attr(data-shape-label);
  position: relative;
}

.line-piece-token.color-only::after {
  content: "";
}

.line-piece-token.strawberry {
  --marker-border: #8f2e48;
  --marker-fill: var(--berry);
  --marker-text: #fff;
}

.line-piece-token.cocoa {
  --marker-border: #4d2b1d;
  --marker-fill: var(--cocoa);
  --marker-text: #fff;
}

.line-piece-token.vanilla {
  --marker-border: var(--cream-border);
  --marker-fill: var(--cream);
  --marker-text: var(--ink);
}

.line-piece-token.shape-square,
.line-piece-token.shape-circle {
  clip-path: none;
}

.line-piece-token.shape-square {
  border-radius: 5px;
}

.line-piece-token.shape-circle {
  border-radius: 999px;
}

.line-piece-token.shape-square::before,
.line-piece-token.shape-circle::before {
  clip-path: none;
}

.line-piece-token.shape-square::before {
  border-radius: 2px;
}

.line-piece-token.shape-circle::before {
  border-radius: 999px;
}

.line-piece-token.shape-triangle {
  clip-path: polygon(50% 7%, 94% 90%, 6% 90%);
}

.mini-cell .line-piece-token {
  width: 17px;
  font-size: 0;
  filter: drop-shadow(0 2px 2px rgba(71, 45, 28, 0.14));
}

.mini-cell .line-piece-token::before {
  inset: 2px;
}

.clue-joiner {
  position: relative;
  flex: 0 0 20px;
  width: 20px;
  height: 3px;
  border-radius: 999px;
  background: var(--mint);
}

.clue-joiner::after {
  content: "";
  position: absolute;
  right: -2px;
  top: -5px;
  border-left: 9px solid var(--mint);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
}

.not-in .clue-joiner {
  background: #b8324f;
}

.not-in .clue-joiner::before,
.not-in .clue-joiner::after {
  content: "";
  position: absolute;
  top: -8px;
  left: 10px;
  width: 4px;
  height: 20px;
  border-radius: 999px;
  background: #b8324f;
  transform: rotate(45deg);
}

.not-in .clue-joiner::after {
  right: auto;
  border: 0;
  transform: rotate(-45deg);
}

.rightOf {
  flex-direction: row-reverse;
}

.above,
.below {
  flex-direction: column;
  gap: 5px;
}

.below {
  flex-direction: column-reverse;
}

.same-col {
  flex-direction: column;
  gap: 5px;
}

.board-zone {
  display: grid;
  justify-items: center;
  gap: 12px;
}

.tray {
  width: min(100%, 410px);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: clamp(8px, 1.5vw, 14px);
  padding: clamp(12px, 2vw, 18px);
  border: 14px solid #7f5037;
  border-radius: 8px;
  background: #b9875e;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18), var(--shadow);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border: 2px solid rgba(80, 45, 28, 0.42);
  border-radius: 8px;
  background: #f8dfbd;
  min-width: 0;
  touch-action: none;
}

.cell:has(.piece) {
  cursor: grab;
}

.cell.drop-target {
  border-color: var(--mint);
  background: #fff7df;
  box-shadow: inset 0 0 0 4px rgba(31, 138, 112, 0.2);
}

.cell.place-target {
  border-color: rgba(31, 138, 112, 0.7);
  background: #fff7df;
}

.cell.place-target::before {
  content: "";
  position: absolute;
  inset: 14%;
  border: 2px dashed rgba(31, 138, 112, 0.5);
  border-radius: 8px;
}

.piece-rack {
  display: grid;
  grid-template-columns: repeat(9, minmax(34px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.piece-btn {
  display: grid;
  place-items: center;
  min-height: auto;
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 8px;
  background: #f4ece4;
  padding: 6px;
  cursor: grab;
  touch-action: none;
}

.piece-btn.selected {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(31, 138, 112, 0.18);
}

.piece-btn.used {
  opacity: 0.32;
}

.piece-btn.dragging,
.cell.dragging {
  cursor: grabbing;
  opacity: 0.5;
  transform: scale(0.98);
}

.piece-drag-ghost {
  position: fixed;
  z-index: 1000;
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  pointer-events: none;
  transform: translate(-50%, -50%);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.82);
  box-shadow: 0 16px 34px rgba(69, 47, 31, 0.26);
}

.piece-drag-ghost .piece {
  width: 76px;
}

.piece {
  position: relative;
  display: grid;
  place-items: center;
  width: min(76%, 76px);
  aspect-ratio: 1;
  color: var(--ink);
  font-size: 0.7rem;
  font-weight: 950;
  filter: drop-shadow(0 8px 8px rgba(71, 45, 28, 0.18));
  box-shadow:
    inset 0 2px 1px rgba(255, 250, 242, 0.22),
    inset 0 -4px 0 rgba(33, 27, 24, 0.16);
}

.cell .piece {
  width: min(84%, 84px);
}

.piece.circle {
  border-radius: 999px;
}

.piece.square {
  border-radius: 6px;
}

.piece.triangle {
  clip-path: polygon(50% 8%, 92% 88%, 8% 88%);
  filter: drop-shadow(0 8px 8px rgba(71, 45, 28, 0.18));
}

.piece span {
  color: var(--ink);
  position: relative;
  z-index: 1;
}

.piece.circle::before,
.piece.square::before {
  content: "";
  position: absolute;
  pointer-events: none;
}

.piece.circle::before {
  inset: 18% 22% auto auto;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 999px;
  background: rgba(255, 250, 242, 0.28);
}

.piece.square::before {
  inset: 11%;
  border: 2px solid rgba(255, 250, 242, 0.28);
  border-right-color: rgba(33, 27, 24, 0.12);
  border-bottom-color: rgba(33, 27, 24, 0.16);
  border-radius: 3px;
}

.piece.strawberry {
  background: var(--berry);
  color: var(--berry);
}

.piece.vanilla {
  background: var(--cream);
  color: var(--cream);
}

.piece.cocoa {
  background: var(--cocoa);
  color: var(--cocoa);
}

.piece.vanilla:not(.triangle) {
  border: 2px solid transparent;
}

.piece.vanilla.square {
  background:
    linear-gradient(145deg, #fff3bb 0 28%, var(--cream) 29% 100%);
  border-color: rgba(181, 139, 50, 0.78);
}

.piece.vanilla.circle {
  border-color: rgba(181, 139, 50, 0.58);
}

.piece.vanilla.square::before {
  inset: 15%;
  border-color: rgba(255, 250, 242, 0.5);
  border-right-color: rgba(181, 139, 50, 0.26);
  border-bottom-color: rgba(181, 139, 50, 0.3);
  background: rgba(255, 244, 196, 0.38);
  box-shadow: none;
}

.piece.vanilla.triangle {
  background: rgba(181, 139, 50, 0.58);
}

.piece.vanilla.triangle::before {
  content: "";
  width: calc(100% - 6px);
  aspect-ratio: 1;
  background: var(--cream);
  clip-path: polygon(50% 8%, 92% 88%, 8% 88%);
}

.piece.wildcard-shape {
  border-radius: 8px;
  outline: 2px dashed rgba(33, 27, 24, 0.35);
  outline-offset: 2px;
}

.piece.wildcard-color {
  background: var(--cream);
  color: var(--cream);
  border: 2px dashed rgba(255, 250, 242, 0.55);
}

.piece.triangle.wildcard-color {
  clip-path: none;
  background: transparent;
  border: 0;
  box-shadow: none;
  filter: none;
}

.piece.triangle.wildcard-color::before,
.piece.triangle.wildcard-color::after {
  content: "";
  position: absolute;
  clip-path: polygon(50% 7%, 94% 90%, 6% 90%);
  pointer-events: none;
}

.piece.triangle.wildcard-color::before {
  inset: 0;
  background: rgba(80, 45, 28, 0.82);
}

.piece.triangle.wildcard-color::after {
  inset: 3px 3px 4px;
  background: #fffaf2;
}

.clue-card .piece {
  width: 32px;
  font-size: 0.52rem;
  filter: drop-shadow(0 4px 4px rgba(71, 45, 28, 0.16));
  box-shadow:
    inset 0 1px 1px rgba(255, 250, 242, 0.24),
    inset 0 -2px 0 rgba(33, 27, 24, 0.16);
}

.clue-card .piece.triangle {
  width: 28px;
  clip-path: polygon(50% 12%, 86% 84%, 14% 84%);
}

.clue-card .piece.vanilla.triangle::before {
  width: calc(100% - 5px);
  clip-path: polygon(50% 12%, 86% 84%, 14% 84%);
}

.mini-cell .piece {
  width: 17px;
  font-size: 0.46rem;
  filter: drop-shadow(0 2px 2px rgba(71, 45, 28, 0.14));
  box-shadow:
    inset 0 1px 0 rgba(255, 250, 242, 0.2),
    inset 0 -1px 0 rgba(33, 27, 24, 0.16);
}

.mini-cell .piece.triangle {
  width: 17px;
}

.mini-cell .piece.triangle.wildcard-color {
  width: 13px;
}

.mini-cell .piece.square {
  border-radius: 3px;
}

.mini-cell .piece.square::before {
  inset: 3px;
  border-width: 1px;
  border-radius: 2px;
}

.mini-cell .piece.vanilla.square::before {
  inset: 2px;
  background: rgba(255, 250, 242, 0.65);
}

.mini-cell .piece.vanilla.triangle::before {
  width: calc(100% - 3px);
}

.mini-cell .piece.circle::before {
  inset: 3px 4px auto auto;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.result {
  min-height: 24px;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.result.good {
  color: var(--mint);
}

.result.bad {
  color: #b8324f;
}

.score-section {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 18px;
  margin-top: 18px;
}

.today-panel,
.totals-panel {
  padding: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td:first-child {
  width: 100%;
  font-weight: 850;
}

@media (max-width: 1040px) {
  .game-layout {
    grid-template-columns: minmax(280px, 0.85fr) minmax(360px, 1.15fr);
    grid-template-areas: "clues play";
  }

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

  .pieces-panel {
    grid-column: auto;
  }

  .piece-rack {
    grid-template-columns: repeat(9, minmax(34px, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    height: 100svh;
    overflow-x: hidden;
    overflow-y: hidden;
  }

  .shell {
    width: min(100% - 20px, 640px);
    height: 100svh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    padding-top: 6px;
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
    overflow: hidden;
  }

  .topbar,
  .game-layout,
  .score-section {
    grid-template-columns: 1fr;
    display: grid;
    min-width: 0;
  }

  .game-layout {
    grid-row: 2;
    grid-template-areas:
      "board"
      "pieces"
      "clues";
    gap: 5px;
    align-content: start;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
  }

  .score-section {
    grid-row: 2;
    align-content: start;
    height: 100%;
    margin-top: 0;
    overflow-x: auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .game-layout > *,
  .board-zone,
  .action-zone,
  .puzzle-panel,
  .pieces-panel,
  .score-section {
    min-width: 0;
    max-width: 100%;
  }

  .topbar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 7px;
    padding-bottom: 6px;
  }

  .mode-toggle {
    flex: none;
    width: 112px;
    min-width: 0;
  }

  .mode-toggle-btn {
    min-height: 22px;
    padding: 0 4px;
    font-size: 0.6rem;
  }

  .play-column {
    display: contents;
  }

  h1 {
    font-size: 1.18rem;
    line-height: 1;
  }

  .eyebrow {
    font-size: 0.72rem;
  }

  .identity label,
  .player-id {
    display: none;
  }

  .name-row {
    grid-template-columns: minmax(0, 1fr) 76px;
  }

  .name-row input,
  .name-row button {
    min-height: 38px;
  }

  .mobile-tabs {
    position: fixed;
    right: 10px;
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 10px;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 250, 242, 0.94);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 30px rgba(69, 47, 31, 0.2);
  }

  .mobile-tab {
    display: grid;
    grid-template-rows: 18px auto;
    place-items: center;
    gap: 2px;
    min-height: 42px;
    padding: 0;
    background: #f4ece4;
    border: 1px solid var(--line);
    color: var(--ink);
  }

  .tab-icon {
    display: block;
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
  }

  .tab-label {
    font-size: 0.58rem;
    font-weight: 900;
    line-height: 1;
  }

  .mobile-tab.active {
    background: var(--mint);
    border-color: var(--mint);
    color: #fff;
  }

  .board-zone {
    display: grid;
    grid-area: board;
    justify-items: center;
    gap: 4px;
    order: 2;
  }

  .action-zone {
    grid-area: actions;
    min-width: 0;
    max-width: 100%;
  }

  .pieces-panel {
    display: grid;
    grid-template-columns: 1fr;
    align-items: start;
    gap: 6px;
    grid-area: pieces;
    grid-column: auto;
    order: 2;
    padding: 6px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    box-shadow: none;
    overflow: hidden;
  }

  .pieces-panel .panel-heading {
    display: flex;
    min-height: 18px;
  }

  .pieces-panel h2 {
    display: block;
    font-size: 0.68rem;
    line-height: 1;
    text-transform: uppercase;
  }

  .pieces-panel .panel-heading span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 18px;
    width: auto;
    padding: 0;
    border-radius: 0;
    background: transparent;
    font-size: 0.62rem;
    white-space: nowrap;
  }

  .puzzle-panel {
    grid-area: clues;
    order: 3;
    padding: 6px;
    overflow: visible;
  }

  .mobile-section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 18px;
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 900;
    line-height: 1;
    text-transform: uppercase;
    width: 100%;
  }

  .mode-row,
  .practice-row {
    gap: 6px;
    margin-bottom: 8px;
  }

  .practice-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .mode-btn {
    min-height: 36px;
    padding: 0 12px;
  }

  .puzzle-meta {
    display: none;
  }

  .puzzle-title {
    font-size: 0.92rem;
  }

  .level-pill,
  #dailyLevelBadge {
    min-height: 22px;
    padding: 0 8px;
    font-size: 0.72rem;
  }

  .timer {
    min-width: 66px;
    font-size: 1rem;
    padding: 6px 8px;
  }

  .clues {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: repeat(3, 76px);
    gap: 6px;
    margin-top: 0;
    max-height: none;
    overflow: hidden;
    padding: 0;
  }

  .clue-card {
    min-width: 0;
    min-height: 0;
    height: 76px;
    padding: 6px 3px;
    overflow: hidden;
  }

  .clue-card:has(.line-pattern-clue) {
    grid-column: auto;
  }

  .clue-number {
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    font-size: 0.52rem;
  }

  .mini-tray {
    width: 40px;
    gap: 1px;
    padding: 3px;
    border-width: 3px;
  }

  .clue-card > .mini-tray {
    width: 50px;
    padding: 2px;
    border-width: 2px;
  }

  .line-clue,
  .corner-clue,
  .line-pattern-clue,
  .relationship-clue {
    gap: 3px;
  }

  .line-clue,
  .corner-clue {
    width: fit-content;
    max-width: 100%;
  }

  .line-clue .mini-tray,
  .corner-clue .mini-tray,
  .line-clue .clue-piece-token,
  .corner-clue .clue-piece-token {
    flex: 0 0 auto;
  }

  .relationship-clue {
    padding: 3px;
    border-width: 2px;
  }

  .clue-piece-token {
    width: 22px;
    overflow: visible;
  }

  .relationship-clue .clue-piece-token {
    width: 22px;
  }

  .relation-symbol {
    flex-basis: 12px;
    width: 12px;
    height: 12px;
  }

  .touch .relation-symbol {
    flex-basis: 10px;
    width: 10px;
  }

  .above,
  .below,
  .same-col {
    gap: 2px;
  }

  .line-pattern-clue {
    gap: 3px;
  }

  .line-pattern-clue.embedded-pattern .mini-tray {
    width: 52px;
    gap: 1px;
    padding: 2px;
    border-width: 2px;
  }

  .line-pattern-clue.embedded-pattern .mini-cell {
    width: auto;
    aspect-ratio: 1;
  }

  .line-pattern {
    grid-template-columns: repeat(3, 19px);
    gap: 2px;
    padding: 3px;
    border-width: 3px;
  }

  .line-pattern.col {
    grid-template-columns: 19px;
    grid-template-rows: repeat(3, 19px);
  }

  .pattern-cell {
    width: 19px;
  }

  .pattern-cell .piece,
  .wildcard-token {
    width: 13px;
  }

  .clue-card .piece {
    width: 17px;
    filter: drop-shadow(0 2px 2px rgba(71, 45, 28, 0.14));
    box-shadow:
      inset 0 1px 0 rgba(255, 250, 242, 0.2),
      inset 0 -1px 0 rgba(33, 27, 24, 0.14);
  }

  .shape-property-token,
  .line-piece-token {
    width: 18px;
    font-size: 0.46rem;
    filter: drop-shadow(0 2px 2px rgba(71, 45, 28, 0.14));
  }

  .shape-property-token::before,
  .line-piece-token::before {
    inset: 2px;
  }

  body[data-mobile-tab="clues"] .shape-property-token,
  body[data-mobile-tab="clues"] .line-piece-token {
    width: 26px;
    font-size: 0.58rem;
  }

  .clue-card .piece.triangle {
    width: 14px;
    clip-path: polygon(50% 12%, 86% 84%, 14% 84%);
  }

  .clue-card .piece.vanilla.triangle::before {
    width: calc(100% - 4px);
    clip-path: polygon(50% 12%, 86% 84%, 14% 84%);
  }

  .mini-cell .piece {
    width: 11px;
  }

  .mini-cell .piece.triangle {
    width: 10px;
    clip-path: polygon(50% 13%, 84% 83%, 16% 83%);
  }

  .mini-cell .piece.triangle.wildcard-color {
    width: 10px;
  }

  .mini-cell .line-piece-token {
    width: 10px;
  }

  .mini-cell .line-piece-token::before {
    inset: 1px;
  }

  body[data-mobile-tab="clues"] .mini-cell .line-piece-token {
    width: 14px;
  }

  .mini-cell .wildcard-token {
    width: 10px;
    border-width: 1px;
    border-radius: 3px;
    background:
      repeating-linear-gradient(
        -45deg,
        rgba(33, 27, 24, 0.18) 0 1px,
        transparent 1px 4px
      ),
      rgba(255, 250, 242, 0.78);
  }

  .clue-joiner {
    flex-basis: 10px;
    width: 10px;
  }

  .clue-joiner::after {
    right: -1px;
    border-left-width: 7px;
    border-top-width: 5px;
    border-bottom-width: 5px;
  }

  .piece-rack {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    grid-template-rows: repeat(2, 48px);
    gap: 6px;
    margin-top: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    padding-bottom: 0;
  }

  .tray {
    width: min(100%, 328px);
    min-width: 270px;
    max-width: calc(100vw - 40px);
    border-width: 7px;
    gap: 6px;
    padding: 7px;
  }

  .piece {
    width: min(72%, 58px);
  }

  .cell .piece {
    width: min(80%, 66px);
  }

  .piece-btn {
    width: 100%;
    height: 48px;
    aspect-ratio: auto;
    padding: 4px;
  }

  .piece-btn .piece {
    width: min(62%, 36px);
  }

  .piece-drag-ghost {
    width: 78px;
    height: 78px;
  }

  .piece-drag-ghost .piece {
    width: 60px;
  }

  .actions {
    display: grid;
    grid-template-columns: repeat(2, 74px);
    justify-content: center;
    width: auto;
    max-width: none;
    gap: 8px;
  }

  .actions button {
    min-width: 0;
    width: 74px;
    min-height: 30px;
    padding: 0 8px;
    font-size: 0.72rem;
  }

  .action-label {
    display: inline;
  }

  .submit-action::before {
    content: none;
  }

  .reset-action::before {
    content: none;
  }

  .reset-action::after {
    content: none;
  }

  .result {
    order: 5;
  }

  .result:empty {
    display: none;
  }

  body[data-mobile-tab="game"] .settings-panel,
  body[data-mobile-tab="game"] .score-section,
  body[data-mobile-tab="clues"] .settings-panel,
  body[data-mobile-tab="clues"] .board-zone,
  body[data-mobile-tab="clues"] .pieces-panel,
  body[data-mobile-tab="clues"] .action-zone,
  body[data-mobile-tab="clues"] .score-section,
  body[data-mobile-tab="settings"] .puzzle-panel .clues,
  body[data-mobile-tab="settings"] .puzzle-panel .mobile-section-title,
  body[data-mobile-tab="settings"] .board-zone,
  body[data-mobile-tab="settings"] .pieces-panel,
  body[data-mobile-tab="settings"] .action-zone,
  body[data-mobile-tab="settings"] .score-section,
  body[data-mobile-tab="scores"] .game-layout {
    display: none;
  }

  body[data-mobile-tab="game"] .game-layout {
    grid-template-areas:
      "clues"
      "board"
      "pieces"
      "actions";
    grid-template-rows: auto auto auto auto;
    gap: 5px;
    overflow-y: auto;
    padding-bottom: 40px;
  }

  body[data-mobile-tab="game"] .puzzle-panel {
    position: static;
    bottom: auto;
    z-index: 20;
    order: 1;
    height: auto;
    padding: 5px;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
    overflow: hidden;
  }

  body[data-mobile-tab="game"] .puzzle-panel .mobile-section-title {
    display: none;
  }

  body[data-mobile-tab="game"] .board-zone {
    display: grid;
    padding: 5px 6px 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.86);
    box-shadow: none;
  }

  body[data-mobile-tab="game"] .pieces-panel {
    order: 3;
    min-height: 124px;
    overflow: hidden;
  }

  body[data-mobile-tab="game"] .clues {
    grid-template-columns: none;
    grid-template-rows: 76px;
    grid-auto-flow: column;
    grid-auto-columns: minmax(88px, 96px);
    height: 82px;
    margin-top: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 1px 4px;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  body[data-mobile-tab="game"] .clue-card {
    scroll-snap-align: start;
  }

  body[data-mobile-tab="clues"] .line-pattern-clue.embedded-pattern .mini-tray {
    width: 58px;
  }

  body[data-mobile-tab="game"] .clue-card.fulfilled {
    border-color: rgba(31, 138, 112, 0.72);
    background: #f4fff9;
    box-shadow: inset 0 0 0 2px rgba(31, 138, 112, 0.14);
  }

  body[data-mobile-tab="game"] .clue-card.fulfilled::after {
    content: "";
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 11px;
    height: 6px;
    border-left: 2px solid var(--mint);
    border-bottom: 2px solid var(--mint);
    transform: rotate(-45deg);
  }

  body[data-mobile-tab="game"] .tray {
    justify-self: center;
    align-self: start;
    width: var(--mobile-board-size, clamp(190px, calc(100svh - 392px), 304px));
    min-width: 0;
  }

  body[data-mobile-tab="game"] .action-zone {
    position: fixed;
    right: 10px;
    bottom: calc(64px + env(safe-area-inset-bottom));
    left: 10px;
    z-index: 29;
    align-self: auto;
    margin-top: 0;
    pointer-events: none;
  }

  body[data-mobile-tab="game"] .action-zone .actions,
  body[data-mobile-tab="game"] .action-zone .result {
    pointer-events: auto;
  }

  body[data-mobile-tab="settings"] .game-layout {
    grid-template-areas: "clues";
  }

  body[data-mobile-tab="clues"] .clues {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    grid-auto-columns: auto;
    max-height: none;
    overflow-x: visible;
    overflow-y: visible;
    padding-bottom: 0;
    scroll-snap-type: none;
  }

  body[data-mobile-tab="clues"] .clue-card {
    display: grid;
    grid-template-columns: 24px minmax(92px, 42%) minmax(0, 1fr);
    gap: 10px;
    min-height: 86px;
    height: auto;
    place-items: center;
    padding: 10px;
    overflow: visible;
  }

  body[data-mobile-tab="clues"] .clue-number {
    position: static;
  }

  body[data-mobile-tab="clues"] .clue-detail {
    display: block;
    justify-self: stretch;
    margin: 0;
    color: var(--ink);
    font-size: 0.9rem;
    font-weight: 800;
    line-height: 1.28;
  }

  body[data-mobile-tab="settings"] .puzzle-panel {
    display: block;
  }

  body[data-mobile-tab="scores"] .score-section {
    display: grid;
  }

}

@media (max-width: 380px) {
  .clues {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  body[data-mobile-tab="clues"] .clues {
    grid-template-columns: 1fr;
    grid-auto-columns: auto;
    max-height: none;
  }

  .clue-card {
    min-height: 0;
    height: 76px;
  }

  body[data-mobile-tab="clues"] .clue-card {
    grid-template-columns: 22px minmax(78px, 42%) minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }

  body[data-mobile-tab="clues"] .clue-detail {
    font-size: 0.84rem;
  }
}
