:root {
  color-scheme: light;
  --bg: #eef2f5;
  --ink: #20262d;
  --muted: #64717f;
  --line: #cbd5df;
  --panel: #fbfcfe;
  --cell: #dce4eb;
  --board: #32404c;
  --board-line: #25313b;
  --shadow: 0 18px 48px rgba(35, 45, 55, .13);
  --soft-shadow: 0 8px 24px rgba(35, 45, 55, .09);
  --blue: #1f78b8;
  --green: #2e9569;
  --red: #d85f4c;
  --yellow: #d6a72c;
  --violet: #7a67c4;
  --pink: #d9468f;
  --radius: 8px;
  --board-size: min(82vw, 62vh, 560px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.theme-night {
  --bg: #e7edf3;
  --panel: #f8fbfd;
  --cell: #cfd9e2;
  --line: #b8c6d3;
  --board: #1f2f3d;
  --board-line: #142331;
  --blue: #4f83cc;
  --green: #2f9a78;
  --red: #d35f5f;
  --yellow: #c9952d;
  --violet: #836fd6;
  --pink: #c44f8e;
}

body.theme-candy {
  --bg: #fff5f6;
  --panel: #fffefe;
  --cell: #f2dfe4;
  --line: #e6cbd2;
  --board: #3a3342;
  --board-line: #2b2532;
  --blue: #1982c4;
  --green: #55a630;
  --red: #ff595e;
  --yellow: #ffca3a;
  --violet: #6a4c93;
  --pink: #db2777;
}

body.theme-forest {
  --bg: #eff4ec;
  --panel: #fcfff9;
  --cell: #dce7d5;
  --ink: #202a22;
  --line: #cbd9c4;
  --board: #304437;
  --board-line: #243329;
  --blue: #3c75a6;
  --green: #3f8f4f;
  --red: #b85c45;
  --yellow: #d0a832;
  --violet: #7460a8;
  --pink: #b64282;
}

body.theme-accessible {
  --bg: #f3f3f0;
  --panel: #ffffff;
  --cell: #e0e0dc;
  --line: #bdbdb7;
  --board: #2b2b2b;
  --board-line: #111111;
  --blue: #0072B2;
  --green: #009E73;
  --red: #D55E00;
  --yellow: #F0E442;
  --violet: #CC79A7;
  --pink: #000000;
}

body.dark-mode {
  color-scheme: dark;
  --bg: #111820;
  --ink: #eef4f8;
  --muted: #a8b4bf;
  --line: #33424e;
  --panel: #18222c;
  --cell: #253441;
  --board: #0d141b;
  --board-line: #40505d;
  --shadow: 0 20px 52px rgba(0, 0, 0, .38);
  --soft-shadow: 0 10px 28px rgba(0, 0, 0, .26);
  --blue: #45a3e6;
  --green: #55c58b;
  --red: #ee7867;
  --yellow: #eec554;
  --violet: #a28dea;
  --pink: #f472b6;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(32, 38, 45, .035) 1px, transparent 1px),
    linear-gradient(rgba(32, 38, 45, .035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, .72), rgba(255, 255, 255, 0) 260px),
    var(--bg);
  background-size: 32px 32px;
  color: var(--ink);
  overflow-x: hidden;
  overscroll-behavior: none;
}

body.dark-mode {
  background:
    linear-gradient(90deg, rgba(238, 244, 248, .035) 1px, transparent 1px),
    linear-gradient(rgba(238, 244, 248, .035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, 0) 280px),
    var(--bg);
  background-size: 32px 32px;
}

button,
select {
  border-radius: var(--radius);
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.app {
  width: min(1280px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
}

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

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.mobile-tools {
  display: none;
}

.language-field select {
  width: 62px;
  min-height: 44px;
  padding: 0 8px;
  text-align: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.mark {
  display: grid;
  grid-template-columns: repeat(2, 17px);
  gap: 3px;
  padding: 7px;
  border: 1px solid rgba(32, 38, 45, .86);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, var(--panel));
  box-shadow: 0 8px 18px rgba(35, 45, 55, .14);
}

.mark span {
  width: 17px;
  height: 17px;
  border-radius: 4px;
  background: var(--blue);
}

.mark span:nth-child(2) { background: var(--yellow); }
.mark span:nth-child(3) { background: var(--green); }
.mark span:nth-child(4) { background: var(--red); }

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4vw, 2.45rem);
  line-height: 1;
  letter-spacing: 0;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: .98rem;
}

.game-shell {
  display: grid;
  grid-template-columns: minmax(180px, 230px) minmax(320px, 1fr) minmax(220px, 280px);
  align-items: start;
  gap: 16px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(251, 252, 254, .92);
  box-shadow: var(--soft-shadow);
  padding: 14px;
  backdrop-filter: blur(8px);
}

body.dark-mode .panel {
  background: rgba(24, 34, 44, .9);
}

body.dark-mode .mark {
  border-color: #425463;
  background: linear-gradient(180deg, #24313d, #18222c);
  box-shadow: 0 8px 18px rgba(0, 0, 0, .28);
}

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

.field {
  display: grid;
  gap: 6px;
}

.field span,
.score-row span,
.score-grid span {
  display: block;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f7f9fb);
  color: var(--ink);
  font-weight: 800;
  padding: 0 10px;
}

select option {
  background: #fff;
  color: #20262d;
}

body.dark-mode select,
body.dark-mode .score-row,
body.dark-mode .score-grid > div,
body.dark-mode .text-button.secondary,
body.dark-mode .icon-button,
body.dark-mode .piece-slot,
body.dark-mode .leader-actions input,
body.dark-mode .achievement,
body.dark-mode .theme-button {
  background: linear-gradient(180deg, #202c37, #18222c);
}

body.dark-mode select {
  color: #eef4f8;
}

body.dark-mode select option {
  background: #18222c;
  color: #eef4f8;
}

.score-row,
.score-grid > div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, #f7f9fb);
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9);
}

.score-row strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: .95;
  word-break: break-word;
}

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

.score-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 1.2rem;
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: #ddd8cd;
  overflow: hidden;
}

.meter div {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--red));
  transition: width .22s ease;
}

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

.text-button {
  min-height: 44px;
  background: linear-gradient(180deg, #2d3742, var(--ink));
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 18px rgba(32, 38, 45, .16);
}

body.dark-mode .text-button {
  background: linear-gradient(180deg, #f3f7fa, #dbe5ec);
  color: #121920;
}

body.dark-mode .text-button.secondary {
  color: var(--ink);
}

.text-button.secondary {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f7f9fb);
  color: var(--ink);
  box-shadow: none;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f7f9fb);
  box-shadow: var(--soft-shadow);
}

.icon-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.icon-text-button {
  display: inline-grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #fff, #f7f9fb);
  color: var(--ink);
  font-weight: 900;
  padding: 0 12px;
}

body.dark-mode .icon-text-button {
  background: linear-gradient(180deg, #202c37, #18222c);
}

.icon-text-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.2;
}

.icon-text-button[aria-expanded="true"] {
  outline: 2px solid var(--ink);
  outline-offset: -3px;
}

.board-wrap {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: var(--board-size);
  height: var(--board-size);
  gap: clamp(4px, .8vw, 7px);
  padding: clamp(7px, 1.2vw, 11px);
  border: 1px solid var(--board-line);
  border-radius: var(--radius);
  background: var(--board);
  box-shadow:
    0 22px 45px rgba(35, 45, 55, .22),
    0 4px 12px rgba(35, 45, 55, .14),
    inset 0 1px 0 rgba(255, 255, 255, .14),
    inset 0 0 0 1px rgba(255, 255, 255, .05);
  touch-action: pan-y;
}

.board.shake {
  animation: shake .22s ease;
}

.cell {
  border-radius: 7px;
  background: var(--cell);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .72),
    inset 0 -1px 0 rgba(35, 45, 55, .05);
  transition: background-color .12s ease, transform .12s ease, opacity .12s ease;
}

body.dark-mode .cell {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .1),
    inset 0 -1px 0 rgba(0, 0, 0, .28);
}

.cell.filled {
  background: var(--piece-color);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .24),
    inset 0 -4px 0 rgba(0, 0, 0, .13),
    0 2px 5px rgba(18, 26, 34, .16);
}

.cell.pop {
  animation: pop .18s ease;
}

.cell.ghost {
  background: var(--piece-color);
  opacity: 1;
  outline: 0;
  transform: scale(.9);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .34),
    inset 0 -4px 0 rgba(0, 0, 0, .16),
    0 0 0 2px color-mix(in srgb, var(--piece-color) 55%, #fff),
    0 0 18px color-mix(in srgb, var(--piece-color) 42%, transparent),
    0 8px 14px rgba(0, 0, 0, .18);
}

.cell.bad {
  background: var(--piece-color);
  opacity: 1;
  outline: 0;
  transform: scale(.9);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .26),
    inset 0 -4px 0 rgba(0, 0, 0, .16),
    0 0 0 2px rgba(220, 38, 38, .78),
    0 0 18px rgba(220, 38, 38, .42),
    0 8px 14px rgba(0, 0, 0, .2);
}

.cell.overlap {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .28), transparent 58%),
    linear-gradient(rgba(220, 38, 38, .42), rgba(220, 38, 38, .42)),
    var(--piece-color);
  box-shadow:
    inset 0 0 0 3px rgba(220, 38, 38, .78),
    inset 0 3px 0 rgba(255, 255, 255, .22),
    0 0 0 2px rgba(255, 255, 255, .72),
    0 0 22px rgba(220, 38, 38, .58);
}

.cell.clear {
  animation: clearCell .32s ease forwards;
}

.cell.hint {
  outline: 3px solid #fff;
  outline-offset: -5px;
  animation: hintPulse .78s ease-in-out 2;
}

.cell.keyboard-cursor {
  outline: 3px solid #fff;
  outline-offset: -5px;
}

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

.share-panel {
  display: grid;
  width: min(100%, 420px);
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 252, 254, .94);
  box-shadow: var(--soft-shadow);
  padding: 12px;
  text-align: center;
}

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

.share-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.share-meta {
  color: var(--ink);
  font-size: .84rem;
  font-weight: 850;
}

body.dark-mode .share-panel {
  background: rgba(24, 34, 44, .94);
}

.score-pop {
  position: absolute;
  z-index: 8;
  color: var(--ink);
  font-weight: 900;
  pointer-events: none;
  text-shadow: 0 1px 0 #fff;
  animation: scoreRise .72s ease forwards;
}

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

.tray-head,
.mini-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.tray-head h2,
.mini-head h2 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.mini-head {
  margin-bottom: 8px;
}

.mini-head span {
  color: var(--muted);
  font-size: .8rem;
  font-weight: 800;
}

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

.piece-slot {
  display: grid;
  min-height: 132px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, #f7f9fb);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9);
  padding: 14px 10px;
  overflow: visible;
  cursor: grab;
  touch-action: none;
}

.piece-slot.used {
  opacity: .28;
  cursor: default;
}

.piece-slot.selected {
  outline: 3px solid var(--ink);
  outline-offset: -4px;
}

.piece-slot:focus-visible,
.board:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--blue) 75%, #fff);
  outline-offset: 2px;
}

.piece {
  display: grid;
  gap: var(--preview-gap, 5px);
  user-select: none;
  transition: transform .15s ease;
}

.piece:active { cursor: grabbing; }

.mini-cell {
  width: var(--preview-cell, clamp(22px, 5.1vw, 34px));
  height: var(--preview-cell, clamp(22px, 5.1vw, 34px));
  border-radius: 6px;
  background: var(--piece-color);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, .25),
    inset 0 -4px 0 rgba(0, 0, 0, .13),
    0 2px 5px rgba(18, 26, 34, .14);
}

body.theme-accessible .filled:not(.overlap)[data-color-index="0"],
body.theme-accessible .mini-cell[data-color-index="0"] {
  background-image: repeating-linear-gradient(45deg, transparent 0 7px, rgba(255, 255, 255, .58) 7px 10px);
}

body.theme-accessible .filled:not(.overlap)[data-color-index="1"],
body.theme-accessible .mini-cell[data-color-index="1"] {
  background-image: radial-gradient(circle, rgba(255, 255, 255, .7) 0 2px, transparent 2.5px);
  background-size: 11px 11px;
}

body.theme-accessible .filled:not(.overlap)[data-color-index="2"],
body.theme-accessible .mini-cell[data-color-index="2"] {
  background-image: repeating-linear-gradient(0deg, transparent 0 7px, rgba(255, 255, 255, .58) 7px 10px);
}

body.theme-accessible .filled:not(.overlap)[data-color-index="3"],
body.theme-accessible .mini-cell[data-color-index="3"] {
  background-image: repeating-linear-gradient(90deg, transparent 0 7px, rgba(0, 0, 0, .35) 7px 10px);
}

body.theme-accessible .filled:not(.overlap)[data-color-index="4"],
body.theme-accessible .mini-cell[data-color-index="4"] {
  background-image:
    linear-gradient(45deg, transparent 43%, rgba(255, 255, 255, .52) 44% 56%, transparent 57%),
    linear-gradient(-45deg, transparent 43%, rgba(255, 255, 255, .52) 44% 56%, transparent 57%);
  background-size: 16px 16px;
}

body.theme-accessible .filled:not(.overlap)[data-color-index="5"],
body.theme-accessible .mini-cell[data-color-index="5"] {
  background-image: repeating-linear-gradient(-45deg, transparent 0 5px, rgba(255, 255, 255, .78) 5px 7px);
}

.leaderboard,
.missions-panel,
.progress-panel {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.personal-stats,
.weekly-panel {
  margin-bottom: 12px;
}

.weekly-panel {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

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

.stat-strip div {
  min-width: 0;
  border-left: 3px solid var(--line);
  padding-left: 8px;
}

.stat-strip span,
.stat-strip strong {
  display: block;
}

.stat-strip span {
  color: var(--muted);
  font-size: .72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat-strip strong {
  margin-top: 3px;
  font-size: 1.05rem;
}

.leaderboard ol {
  display: grid;
  gap: 4px;
  min-height: 28px;
  margin: 0;
  padding-left: 24px;
}

.leaderboard li {
  color: var(--muted);
  font-size: .9rem;
  font-weight: 750;
}

.leaderboard-insight {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: .84rem;
  font-weight: 850;
  line-height: 1.35;
}

.leader-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  margin-bottom: 8px;
}

.leader-actions input {
  min-width: 0;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, #f7f9fb);
  color: var(--ink);
  font: inherit;
  font-weight: 750;
  padding: 0 9px;
}

.leader-actions .text-button {
  min-width: 70px;
  min-height: 38px;
}

.missions {
  display: grid;
  gap: 8px;
}

.mission {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, #f7f9fb);
  padding: 9px;
}

body.dark-mode .mission,
body.dark-mode .summary-score,
body.dark-mode .summary-grid > div {
  background: linear-gradient(180deg, #202c37, #18222c);
}

.mission.done {
  border-color: color-mix(in srgb, var(--green) 52%, var(--line));
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--green) 24%, transparent),
    0 8px 18px rgba(46, 149, 105, .12);
  animation: missionDone .28s ease;
}

.mission-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  font-size: .86rem;
  font-weight: 850;
}

.mission-top strong {
  flex: 1;
}

.mission-top span {
  color: var(--muted);
  font-size: .78rem;
  white-space: nowrap;
}

.mission.done .mission-top span {
  border: 1px solid color-mix(in srgb, var(--green) 52%, var(--line));
  border-radius: 999px;
  color: var(--green);
  padding: 2px 6px;
  font-weight: 950;
}

.mission-bar {
  height: 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 72%, transparent);
  overflow: hidden;
}

.mission-bar div {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width .2s ease;
}

.achievements {
  display: grid;
  gap: 6px;
}

.achievement {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, #f7f9fb);
  padding: 7px 9px;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 800;
}

.achievement.unlocked {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--green) 46%, var(--line));
}

.themes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.theme-label {
  margin-top: 10px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.theme-button {
  display: grid;
  min-height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff, #f7f9fb);
  font-size: .82rem;
  font-weight: 900;
}

.theme-button.active {
  outline: 2px solid var(--ink);
  outline-offset: -3px;
}

.theme-button:disabled {
  background: #e6ebef;
}

body.dark-mode .theme-button:disabled {
  background: #1c2630;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(92vw, 420px);
  transform: translate(-50%, 20px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 252, 254, .96);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
  padding: 11px 14px;
  transition: opacity .18s ease, transform .18s ease;
}

body.dark-mode .toast,
body.dark-mode .install-dialog,
body.dark-mode .help-dialog,
body.dark-mode .summary-dialog,
body.dark-mode .mobile-dialog,
body.dark-mode .confirm-dialog {
  background: rgba(24, 34, 44, .96);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.install-dialog,
.help-dialog,
.summary-dialog,
.mobile-dialog,
.confirm-dialog {
  width: min(92vw, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  padding: 0;
}

.install-dialog::backdrop,
.help-dialog::backdrop,
.summary-dialog::backdrop,
.mobile-dialog::backdrop,
.confirm-dialog::backdrop {
  background: rgba(32, 36, 42, .32);
}

.install-dialog form,
.help-dialog form,
.summary-dialog form,
.mobile-dialog form,
.confirm-dialog form {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 18px;
}

.install-dialog h2,
.install-dialog p,
.help-dialog h2,
.help-dialog p,
.summary-dialog h2,
.summary-dialog p,
.mobile-dialog h2,
.confirm-dialog h2,
.confirm-dialog p {
  margin: 0;
}

.install-dialog p,
.help-dialog p,
.help-dialog li {
  color: var(--muted);
  line-height: 1.45;
}

.help-dialog ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 20px;
}

.summary-dialog {
  width: min(94vw, 520px);
}

.confirm-dialog {
  width: min(92vw, 390px);
}

.confirm-dialog p {
  color: var(--muted);
  line-height: 1.45;
}

.mobile-dialog {
  width: min(94vw, 430px);
  max-height: min(84dvh, 720px);
  overflow: auto;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head .icon-button {
  width: 40px;
  height: 40px;
  box-shadow: none;
}

.mobile-dialog-content {
  display: grid;
  gap: 12px;
}

.settings-icon-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.mobile-dialog .mode-field,
.mobile-dialog .leaderboard,
.mobile-dialog .progress-panel {
  display: grid;
}

.mobile-dialog .leaderboard,
.mobile-dialog .progress-panel {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.mobile-dialog .icon-button {
  display: grid;
  width: 100%;
  box-shadow: none;
}

.summary-score,
.summary-grid > div {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, #f7f9fb);
  padding: 11px;
}

.summary-score span,
.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 850;
  text-transform: uppercase;
}

.summary-score strong {
  display: block;
  margin-top: 4px;
  font-size: 2.45rem;
  line-height: 1;
}

.summary-score small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-weight: 800;
}

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

.summary-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.summary-missions {
  display: grid;
  gap: 6px;
}

.summary-next {
  display: grid;
  gap: 5px;
  border: 1px solid color-mix(in srgb, var(--blue) 32%, var(--line));
  border-radius: 7px;
  background: color-mix(in srgb, var(--blue) 8%, var(--panel));
  padding: 10px 11px;
}

.summary-next strong {
  font-size: .9rem;
}

.summary-next p {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.35;
}

.summary-coach:empty {
  display: none;
}

.summary-coach {
  border-top: 1px solid color-mix(in srgb, var(--blue) 28%, var(--line));
  padding-top: 6px;
}

.summary-name {
  display: grid;
  gap: 6px;
}

.summary-name[hidden] {
  display: none;
}

.summary-name label {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.summary-name input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: linear-gradient(180deg, #fff, #f7f9fb);
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  padding: 0 10px;
}

body.dark-mode .summary-name input {
  background: linear-gradient(180deg, #202c37, #18222c);
}

.summary-missions strong {
  font-size: .9rem;
}

.summary-missions ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-weight: 750;
}

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

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

.summary-streak {
  border-left: 4px solid var(--yellow);
  color: var(--ink);
  font-weight: 850;
  padding-left: 10px;
}

.drag-layer {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 20;
  pointer-events: none;
}

.drag-layer .piece {
  position: fixed;
  opacity: .94;
  transform: none;
  filter: drop-shadow(0 18px 18px rgba(0, 0, 0, .22));
}

.drag-layer .piece.lift-preview {
  gap: var(--drag-gap, 5px);
  transform: none;
}

.drag-layer .piece.lift-preview .mini-cell {
  width: var(--drag-cell, 32px);
  height: var(--drag-cell, 32px);
  border-radius: 7px;
}

@keyframes pop {
  0% { transform: scale(.64); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@keyframes clearCell {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.25) rotate(8deg); opacity: .08; }
}

@keyframes hintPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(.86); }
}

@keyframes scoreRise {
  0% { opacity: 0; transform: translate(-50%, 8px) scale(.86); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -32px) scale(1.08); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  55% { transform: translateX(5px); }
  80% { transform: translateX(-3px); }
}

@keyframes missionDone {
  0% { transform: scale(.98); }
  70% { transform: scale(1.015); }
  100% { transform: scale(1); }
}

@media (min-width: 901px) {
  :root { --board-size: min(64vh, 560px); }

  .topbar {
    max-width: 1180px;
    margin-inline: auto;
  }

  .game-shell {
    grid-template-columns: minmax(210px, 235px) minmax(520px, 560px) minmax(340px, 380px);
    justify-content: center;
    gap: 18px;
  }

  .board-wrap {
    align-self: start;
  }

  .tray-panel {
    align-content: start;
  }

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

  .piece-slot {
    min-height: 166px;
    padding: 10px 6px;
  }

  .leaderboard ol {
    max-height: 132px;
    overflow: auto;
    padding-right: 4px;
  }

  .missions {
    gap: 7px;
  }

  .mission {
    padding: 8px;
  }

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

  .achievement {
    min-height: 32px;
    padding: 6px 8px;
    font-size: .8rem;
  }

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

@media (max-width: 900px) {
  :root { --board-size: min(94vw, 56vh, 560px); }

  .game-shell {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stats-panel {
    grid-template-columns: minmax(110px, 1fr) minmax(150px, 1.4fr) auto;
    align-items: stretch;
  }

  .mode-field,
  .meter {
    grid-column: 1 / -1;
  }

  .score-row,
  .score-grid > div {
    padding: 10px;
  }

  .score-row strong { font-size: 1.8rem; }
  .text-button { min-width: 96px; }

  .actions {
    grid-column: 1 / 3;
  }

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

  .piece-slot {
    min-height: 116px;
    padding: 12px 6px;
  }
}

@media (max-width: 540px) {
  :root { --board-size: clamp(288px, min(92vw, 44dvh), 430px); }

  .app { padding-inline: 10px; }

  .topbar {
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin-bottom: 8px;
  }

  .brand {
    flex: 1 1 auto;
  }

  .brand p { display: none; }

  .top-actions {
    width: auto;
    justify-content: flex-end;
    gap: 6px;
  }

  .mobile-tools {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0 0 8px;
  }

  .top-actions #darkModeBtn,
  .top-actions #installBtn,
  .leaderboard,
  .progress-panel,
  .tray-head .icon-button {
    display: none;
  }

  .stats-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    padding: 9px;
  }

  .mode-field,
  .meter,
  .score-grid {
    grid-column: 1 / -1;
  }

  .score-row {
    grid-column: 1;
  }

  .score-grid {
    grid-column: 2 / 4;
  }

  .actions {
    grid-column: 1 / 3;
    gap: 5px;
  }

  #newGameBtn {
    grid-column: 3;
  }

  .score-row,
  .score-grid > div {
    padding: 7px;
  }

  .score-row strong {
    margin-top: 3px;
    font-size: 1.45rem;
  }

  .score-grid strong {
    margin-top: 3px;
    font-size: 1rem;
  }

  .field span,
  .score-row span,
  .score-grid span {
    font-size: .68rem;
  }

  .text-button {
    width: auto;
    min-width: 0;
    padding-inline: 8px;
  }

  .mini-cell {
    width: var(--preview-cell, clamp(18px, 6vw, 28px));
    height: var(--preview-cell, clamp(18px, 6vw, 28px));
  }

  .piece-slot {
    min-height: 96px;
    padding-block: 8px;
  }

  .message {
    order: -1;
    min-height: 22px;
    margin-bottom: -2px;
  }

  .missions-panel {
    border-top: 0;
    padding-top: 0;
  }

  .leaderboard ol {
    max-height: 132px;
    overflow: auto;
    padding-right: 4px;
  }

  .achievement {
    min-height: 32px;
    padding: 6px 8px;
    font-size: .8rem;
  }

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

  .dialog-actions {
    grid-template-columns: 1fr;
  }

  .summary-dialog {
    width: min(94vw, 420px);
  }

  .summary-dialog form {
    gap: 9px;
    padding: 13px;
  }

  .summary-score,
  .summary-grid > div,
  .summary-next {
    padding: 9px;
  }

  .summary-score strong {
    font-size: 2rem;
  }

  .summary-grid {
    gap: 6px;
  }
}

@media (max-width: 380px) {
  :root { --board-size: clamp(278px, min(91vw, 42dvh), 350px); }

  .app { padding-inline: 7px; }
  .mark { grid-template-columns: repeat(2, 14px); padding: 6px; }
  .mark span { width: 14px; height: 14px; }
  h1 { font-size: 1.3rem; }
  .language-field select { width: 56px; }
  .top-actions .icon-button { width: 42px; height: 42px; }
  .mobile-tools { gap: 6px; }
  .icon-text-button { padding-inline: 7px; }
  .piece-slot { min-height: 88px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
