/* tessel — hand-drawn daily logic puzzle
   All values trace back to assets/data/design-tokens.json */

:root {
  --ink: #3B3A36;
  --paper: #FFFDF6;
  --canvas: #EFEBDF;
  --accent: #F2603D;
  --highlight: #FFF3C4;
  --gold: #FFC94D;
  --muted: #8A8578;
  --muted-line: #D8D2C2;
  --hairline: #EDE8DA;
  --tan: #C9A96A;
  --success: #3E7C33;
  --error: #C9302B;
  --pack-cozy: #F0F7E6;
  --pack-chewy: #FDF6E0;
  --pack-spicy: #FBEFF2;
  --mint: #E9F5F1;
  --blush: #FBEFF2;
  --r0: #F6C28B; --r1: #9BD8C8; --r2: #C3B2EE; --r3: #F5A8BC;
  --r4: #B5DD8F; --r5: #9FC8EE; --r6: #F3D97E;

  --radius-card: 16px 6px 17px 5px / 5px 17px 6px 16px;
  --radius-panel: 22px 8px 24px 9px / 9px 24px 8px 22px;
  --radius-button: 20px 7px 18px 8px / 8px 18px 7px 20px;
  --radius-cell: 9px 4px 10px 5px / 5px 10px 4px 9px;
  --radius-chip: 12px 5px 11px 6px / 6px 11px 5px 12px;

  --stroke-hair: 1.5px;
  --stroke: 2px;
  --stroke-bold: 2.5px;

  --s1: 4px; --s2: 6px; --s3: 8px; --s4: 10px; --s5: 13px;
  --s6: 16px; --s7: 20px; --s8: 26px; --s9: 34px;

  --pop: 0.28s ease;
  --fade-up: 0.35s ease;

  --font: 'Gaegu', 'Patrick Hand', sans-serif;
}

html[lang="ko"] { --font: 'Gaegu', sans-serif; }
html[lang="en"] { --font: 'Patrick Hand', 'Gaegu', sans-serif; }
html[lang="ja"] { --font: 'Yomogi', 'Gaegu', sans-serif; }
html[lang="zh"] { --font: 'Long Cang', 'Gaegu', sans-serif; }

* { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 0 0 var(--stroke-hair) var(--hairline);
}

main {
  flex: 1;
  padding: var(--s6) var(--s6) calc(84px + env(safe-area-inset-bottom));
  animation: fade-up var(--fade-up);
}

main.no-nav { padding-bottom: var(--s8); }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes pop-in {
  0% { transform: scale(0.4); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes wiggle {
  0%, 100% { transform: rotate(-1.6deg); }
  50% { transform: rotate(1.8deg); }
}

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

@keyframes float-star {
  0% { transform: translateY(0) rotate(0) scale(1); opacity: 1; }
  100% { transform: translateY(-90px) rotate(24deg) scale(0.6); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

h1, h2, h3 { font-weight: 700; line-height: 1.25; }
.t-display { font-size: 30px; }
.t-title { font-size: 22px; }
.t-heading { font-size: 19px; }
.t-label { font-size: 15px; }
.t-caption { font-size: 13px; color: var(--muted); }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

button:focus-visible, a:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- shared components ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s6) var(--s6) 0;
}

.topbar .title {
  flex: 1;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
}

.topbar .side { width: 44px; display: flex; justify-content: center; align-items: center; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50% 42% 55% 45%;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 26px; height: 26px; }

.card {
  background: var(--paper);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  padding: var(--s6);
  box-shadow: 2px 3px 0 rgba(59, 58, 54, 0.10);
}

.panel { border-radius: var(--radius-panel); }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  width: 100%;
  padding: var(--s5) var(--s6);
  border: var(--stroke-bold) solid var(--ink);
  border-radius: var(--radius-button);
  font-size: 19px;
  font-weight: 700;
  background: var(--paper);
  box-shadow: 2px 3px 0 rgba(59, 58, 54, 0.14);
  transition: transform var(--pop);
}
.btn:active { transform: translateY(2px); box-shadow: 1px 1px 0 rgba(59, 58, 54, 0.14); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-style: dashed; box-shadow: none; }
.btn-text {
  border: none; background: none; box-shadow: none;
  color: var(--muted); text-decoration: underline; text-underline-offset: 4px;
  font-size: 17px; width: auto; margin: 0 auto;
}

.chip {
  display: inline-block;
  padding: 2px 12px;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-chip);
  font-size: 15px;
  font-weight: 700;
  background: var(--pack-cozy);
}
.chip.cozy { background: var(--pack-cozy); }
.chip.chewy { background: var(--pack-chewy); }
.chip.spicy { background: var(--pack-spicy); }

.bubble-row {
  display: flex;
  align-items: flex-start;
  gap: var(--s4);
  margin: var(--s6) 0;
}
.bubble-row img { width: 72px; height: 72px; flex: none; animation: wiggle 2.8s ease-in-out infinite; }
.bubble-row.compact img { width: 56px; height: 56px; }

.bubble {
  position: relative;
  flex: 1;
  background: var(--highlight);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  padding: var(--s4) var(--s5);
  font-size: 17px;
}
.bubble::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 24px;
  width: 12px;
  height: 14px;
  background: inherit;
  border: var(--stroke) solid var(--ink);
  border-right: none;
  clip-path: polygon(100% 0, 0 50%, 100% 100%);
}
.bubble.mint { background: var(--mint); }
.bubble.blush { background: var(--blush); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(104px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  padding: var(--s4) var(--s7);
  border-radius: var(--radius-button);
  font-size: 17px;
  z-index: 60;
  animation: pop-in var(--pop);
  max-width: 90vw;
  text-align: center;
}

/* ---------- bottom navigation ---------- */

.nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  display: flex;
  background: var(--paper);
  border-top: var(--stroke) solid var(--ink);
  padding: var(--s2) var(--s4) calc(var(--s2) + env(safe-area-inset-bottom));
  z-index: 40;
}

.nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  font-size: 13px;
  color: var(--muted);
  border-radius: var(--radius-chip);
  padding: var(--s2) 0;
}
.nav button svg { width: 24px; height: 24px; }
.nav button.active { color: var(--ink); font-weight: 700; }
.nav button.active .nav-blob {
  background: var(--highlight);
  border: var(--stroke-hair) solid var(--ink);
}
.nav-blob {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 30px;
  border-radius: 50% 45% 55% 48%;
  border: var(--stroke-hair) solid transparent;
}

/* ---------- home ---------- */

.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--s6);
}
.home-header .logo { font-size: 30px; font-weight: 700; letter-spacing: 1px; }

.today-card { padding: var(--s7); margin: var(--s7) 0; }
.today-card .date-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 15px;
}
.today-card h2 { font-size: 30px; margin-top: var(--s2); }
.today-card .underline {
  height: 5px;
  width: 60%;
  margin: 4px 0 var(--s4);
  background: var(--accent);
  border-radius: 3px;
  clip-path: polygon(0 40%, 8% 0, 20% 55%, 33% 10%, 46% 60%, 60% 5%, 72% 50%, 85% 15%, 100% 45%, 100% 100%, 0 100%);
}
.today-card .streak-line { color: var(--muted); margin-bottom: var(--s5); min-height: 1.4em; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: var(--s7) 0 var(--s4);
}
.section-head h3 { font-size: 19px; }
.section-head .t-caption { color: var(--tan); font-weight: 700; font-size: 15px; }

.sticker-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--s3);
}

.sticker {
  aspect-ratio: 1;
  border-radius: var(--radius-cell);
  border: var(--stroke) solid var(--ink);
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  background: var(--paper);
}
.sticker.empty { border-color: var(--muted-line); background: var(--hairline); }
.sticker.today { border-color: var(--accent); border-width: var(--stroke-bold); background: var(--highlight); }
.sticker-row .sticker:nth-child(odd) { transform: rotate(-2deg); }
.sticker-row .sticker:nth-child(even) { transform: rotate(1.6deg); }

.pack-list { display: flex; flex-direction: column; gap: var(--s4); }

.pack-card {
  display: flex;
  align-items: center;
  gap: var(--s5);
  width: 100%;
  text-align: start;
  padding: var(--s5) var(--s6);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  box-shadow: 2px 3px 0 rgba(59, 58, 54, 0.10);
  transition: transform var(--pop);
}
.pack-card:active { transform: scale(0.98); }
.pack-card img { width: 56px; height: 56px; flex: none; }
.pack-card .pack-info { flex: 1; }
.pack-card .pack-info h4 { font-size: 22px; }
.pack-card .pack-info p { color: var(--muted); font-size: 15px; }
.pack-card .pack-side { font-size: 24px; color: var(--success); }
.pack-card .pack-side svg { width: 24px; height: 24px; }
.pack-card:nth-child(odd) { transform: rotate(-0.4deg); }
.pack-card:nth-child(even) { transform: rotate(0.35deg); }

/* ---------- play ---------- */

.play-top {
  display: flex;
  align-items: center;
  gap: var(--s4);
  margin-bottom: var(--s4);
}
.play-top .title { flex: 1; text-align: center; font-size: 22px; font-weight: 700; }
.play-top .timer {
  min-width: 56px;
  text-align: end;
  font-size: 19px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.play-cheer {
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  gap: var(--s3);
  min-height: 76px;
  margin-bottom: var(--s4);
}
.play-cheer img { width: 64px; height: 64px; animation: wiggle 3s ease-in-out infinite; }
.play-cheer .bubble { flex: none; max-width: 70%; background: var(--mint); font-size: 16px; }
.play-cheer .bubble::before {
  left: auto;
  right: -12px;
  border: var(--stroke) solid var(--ink);
  border-left: none;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.board-wrap {
  border: var(--stroke-bold) solid var(--ink);
  border-radius: var(--radius-panel);
  background: var(--paper);
  padding: var(--s4);
  box-shadow: 2px 4px 0 rgba(59, 58, 54, 0.10);
}

.board {
  display: grid;
  gap: var(--s2);
  width: 100%;
  aspect-ratio: 1;
}

.cell {
  position: relative;
  border-radius: var(--radius-cell);
  border: var(--stroke-hair) solid rgba(59, 58, 54, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  min-width: 0;
  padding: 0;
  transition: transform 0.12s ease;
}
.cell:active { transform: scale(0.94); }
.cell .glyph {
  position: absolute;
  top: 3px;
  left: 6px;
  font-size: 11px;
  line-height: 1;
  color: rgba(59, 58, 54, 0.9); /* a11y-contrast-report.json recommended alpha */
  font-family: sans-serif;
}
.cell .mark {
  font-size: clamp(16px, 4.4vw, 24px);
  color: rgba(59, 58, 54, 0.55);
  font-weight: 700;
  font-family: sans-serif;
}
.cell svg.star { width: 62%; height: 62%; animation: pop-in var(--pop); }
.cell svg.star path { fill: var(--gold); stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; }
.cell.conflict svg.star path { fill: var(--error); stroke: var(--ink); }
.cell.conflict { animation: shake 0.3s ease; }
.cell.hinted { box-shadow: inset 0 0 0 3px var(--accent); }

.play-actions {
  display: flex;
  justify-content: center;
  gap: var(--s6);
  margin-top: var(--s7);
}
.play-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--s2);
  font-size: 15px;
  color: var(--ink);
  width: 88px;
}
.play-action .box {
  width: 64px;
  height: 64px;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  box-shadow: 2px 3px 0 rgba(59, 58, 54, 0.12);
  transition: transform var(--pop);
}
.play-action:active .box { transform: translateY(2px); }
.play-action .box svg { width: 30px; height: 30px; }
.play-action .box img { width: 44px; height: 44px; }
.play-action.primary .box { background: var(--highlight); }
.play-action:disabled { opacity: 0.4; }

.float-star {
  position: fixed;
  font-size: 22px;
  pointer-events: none;
  z-index: 70;
  animation: float-star 0.9s ease-out forwards;
}

/* ---------- completion ---------- */

.done-screen {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 520px;
  background: var(--highlight);
  z-index: 50;
  overflow-y: auto;
  padding: var(--s9) var(--s7) var(--s7);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  animation: fade-up var(--fade-up);
}
.done-screen h1 { font-size: 34px; }
.done-screen .underline {
  height: 5px; width: 150px; background: var(--accent); border-radius: 3px;
  margin: 6px auto var(--s8);
  clip-path: polygon(0 40%, 10% 0, 25% 55%, 40% 10%, 55% 60%, 70% 5%, 85% 50%, 100% 20%, 100% 100%, 0 100%);
}

.done-medal { position: relative; margin: var(--s6) 0 var(--s8); }
.done-medal .medal {
  width: 240px;
  height: 240px;
  border-radius: 50%;
  border: var(--stroke-bold) solid var(--ink);
  overflow: hidden;
  display: grid;
  animation: pop-in 0.45s ease;
}
.done-medal .medal > i { display: block; }
.done-medal .time-card {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--paper);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  padding: var(--s3) var(--s6);
  min-width: 120px;
}
.done-medal .time-card .time { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.done-medal .time-card .date { font-size: 14px; color: var(--muted); }
.done-medal .twink {
  position: absolute;
  right: -34px;
  bottom: -18px;
  width: 110px;
  animation: wiggle 2.6s ease-in-out infinite;
}
.done-medal .spark { position: absolute; font-size: 26px; color: var(--accent); }
.done-medal .spark.a { top: -8px; right: -4px; }
.done-medal .spark.b { bottom: 10px; left: -26px; color: #4A90D9; }

.done-line { font-size: 21px; font-weight: 700; }
.done-sub { color: var(--muted); margin-top: var(--s2); }

.done-chars { display: flex; gap: var(--s6); margin: var(--s8) 0; }
.done-chars img { width: 64px; height: 64px; }
.done-chars img:nth-child(1) { animation: wiggle 2.4s ease-in-out infinite; }
.done-chars img:nth-child(2) { animation: wiggle 2.9s ease-in-out infinite; }
.done-chars img:nth-child(3) { animation: wiggle 2.2s ease-in-out infinite; }
.done-chars img:nth-child(4) { animation: wiggle 3.3s ease-in-out infinite; }

.done-screen .btn { margin-top: auto; }

/* ---------- archive ---------- */

.month-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s6);
  margin: var(--s6) 0;
  font-size: 24px;
  font-weight: 700;
}
.month-nav button { font-size: 22px; color: var(--tan); }
.month-nav button:disabled { opacity: 0.3; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--s3);
}
.cal-head {
  text-align: center;
  color: var(--tan);
  font-size: 15px;
  font-weight: 700;
  padding-bottom: var(--s2);
}

.cal-day {
  aspect-ratio: 1;
  position: relative;
  border-radius: var(--radius-cell);
  border: var(--stroke-hair) solid var(--muted-line);
  background: var(--paper);
  font-size: 14px;
  color: var(--muted);
  padding: 0;
  overflow: hidden;
}
.cal-day .num { position: absolute; top: 2px; left: 5px; z-index: 2; line-height: 1; }
.cal-day.done { border: var(--stroke) solid var(--ink); }
.cal-day.done .num { color: var(--ink); font-weight: 700; text-shadow: 0 0 3px rgba(255,255,255,0.8); }
.cal-day.missed { border: var(--stroke-hair) dashed var(--tan); background: var(--paper); }
.cal-day.today { border: var(--stroke-bold) solid var(--accent); background: var(--highlight); }
.cal-day.future, .cal-day.out-of-range { opacity: 0.45; }
.cal-day .quilt {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
}

.cal-legend {
  display: flex;
  justify-content: center;
  gap: var(--s6);
  margin: var(--s6) 0;
  font-size: 15px;
  color: var(--muted);
}
.cal-legend span { display: inline-flex; align-items: center; gap: var(--s2); }
.cal-legend i {
  width: 20px; height: 20px; border-radius: var(--radius-cell); display: inline-block;
}
.cal-legend .l-done { background: var(--r1); border: var(--stroke) solid var(--ink); }
.cal-legend .l-missed { border: var(--stroke-hair) dashed var(--tan); }
.cal-legend .l-today { background: var(--highlight); border: var(--stroke) solid var(--accent); }

/* ---------- stats ---------- */

.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); }
.stat-card { text-align: center; padding: var(--s5) var(--s2); }
.stat-card .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .label { color: var(--muted); font-size: 14px; margin-top: 2px; }
.stat-cards .stat-card:nth-child(1) { transform: rotate(-0.6deg); }
.stat-cards .stat-card:nth-child(3) { transform: rotate(0.5deg); }

.chart-card { margin-top: var(--s6); padding: var(--s6); }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
.chart-head .note { color: var(--accent); font-size: 15px; font-weight: 700; }
.bar-chart {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--s3);
  align-items: end;
  height: 170px;
  margin-top: var(--s6);
}
.bar-col { display: flex; flex-direction: column; align-items: center; gap: var(--s2); height: 100%; justify-content: flex-end; }
.bar {
  width: 70%;
  background: var(--r1);
  border: var(--stroke) solid var(--ink);
  border-radius: 6px 3px 5px 3px;
  min-height: 6px;
  transition: height 0.4s ease;
}
.bar.best { background: var(--r6); border-color: var(--accent); border-width: var(--stroke-bold); }
.bar.none { background: var(--hairline); border-color: var(--muted-line); }
.bar-col .day { font-size: 14px; color: var(--muted); }

/* ---------- settings ---------- */

.setting-list { display: flex; flex-direction: column; gap: var(--s4); margin-top: var(--s6); }

.setting-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  width: 100%;
  text-align: start;
  padding: var(--s5) var(--s6);
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  background: var(--paper);
  box-shadow: 2px 3px 0 rgba(59, 58, 54, 0.08);
}
.setting-card h4 { font-size: 19px; }
.setting-card p { color: var(--muted); font-size: 14px; }
.setting-card svg { width: 22px; height: 22px; color: var(--muted); }
.setting-list .setting-card:nth-child(odd) { transform: rotate(-0.3deg); }
.setting-list .setting-card:nth-child(even) { transform: rotate(0.3deg); }

.toggle {
  flex: none;
  width: 58px;
  height: 34px;
  border: var(--stroke) solid var(--ink);
  border-radius: 17px 15px 18px 14px;
  background: var(--hairline);
  position: relative;
  transition: background var(--pop);
}
.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 3px;
  width: 26px;
  height: 26px;
  background: var(--paper);
  border: var(--stroke) solid var(--ink);
  border-radius: 45% 55% 48% 52%;
  transition: left var(--pop);
}
.toggle[aria-checked="true"] { background: var(--r4); }
.toggle[aria-checked="true"]::after { left: 25px; }

.lang-row { display: flex; gap: var(--s3); }
.lang-pill {
  padding: 4px 12px;
  border: var(--stroke) solid var(--muted-line);
  border-radius: var(--radius-chip);
  color: var(--muted);
  font-size: 15px;
  min-height: 34px;
  min-width: 34px;
}
.lang-pill.active { border-color: var(--ink); color: var(--ink); background: var(--highlight); font-weight: 700; }

.unlock-banner {
  display: flex;
  align-items: center;
  gap: var(--s5);
  background: var(--highlight);
  margin-top: var(--s6);
  padding: var(--s6);
}
.unlock-banner img { width: 64px; height: 64px; flex: none; }
.unlock-banner .info { flex: 1; }
.unlock-banner .info h4 { font-size: 21px; line-height: 1.2; }
.unlock-banner .info p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.unlock-banner .btn { width: auto; padding: var(--s3) var(--s5); font-size: 16px; flex: none; }

.version-line { text-align: center; color: var(--muted); font-size: 14px; margin-top: var(--s7); }

/* ---------- unlock sheet ---------- */

.sheet-veil {
  position: fixed;
  inset: 0;
  background: rgba(59, 58, 54, 0.45);
  z-index: 55;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  width: 100%;
  max-width: 520px;
  background: var(--paper);
  border: var(--stroke-bold) solid var(--ink);
  border-bottom: none;
  border-radius: 26px 10px 0 0 / 20px 26px 0 0;
  padding: var(--s7) var(--s7) calc(var(--s7) + env(safe-area-inset-bottom));
  animation: sheet-up 0.28s ease;
}
@keyframes sheet-up { from { transform: translateY(40%); } to { transform: none; } }
.sheet .grab { width: 54px; height: 5px; background: var(--muted-line); border-radius: 3px; margin: 0 auto var(--s5); }
.sheet h2 { text-align: center; font-size: 26px; }
.sheet .cast { display: flex; justify-content: center; gap: var(--s4); margin: var(--s5) 0; }
.sheet .cast img { width: 52px; height: 52px; }
.sheet ul { list-style: none; margin: var(--s5) 0 var(--s6); display: flex; flex-direction: column; gap: var(--s3); }
.sheet li { display: flex; gap: var(--s3); align-items: center; font-size: 18px; }
.sheet li::before { content: '★'; color: var(--gold); -webkit-text-stroke: 1px var(--ink); }

/* ---------- backup ---------- */

.code-card { background: var(--highlight); text-align: center; margin-top: var(--s6); padding: var(--s6); }
.code-box {
  font-family: 'Patrick Hand', monospace;
  font-size: 19px;
  letter-spacing: 1px;
  word-break: break-all;
  max-height: 96px;
  overflow-y: auto;
  margin-bottom: var(--s5);
  user-select: all;
}
.paste-area { margin-top: var(--s4); }
.paste-area textarea {
  width: 100%;
  min-height: 88px;
  font: inherit;
  font-size: 15px;
  border: var(--stroke) dashed var(--ink);
  border-radius: var(--radius-card);
  padding: var(--s4);
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}
.contains-card { margin-top: var(--s6); }
.contains-card h3 { margin-bottom: var(--s4); }
.contains-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) 0;
  font-size: 18px;
}
.contains-row .mini-quilt {
  width: 26px; height: 26px; border: var(--stroke-hair) solid var(--ink);
  border-radius: 7px 4px 8px 4px;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  overflow: hidden; flex: none;
}
.contains-row .k { flex: 1; }
.contains-row .v { color: var(--tan); font-weight: 700; }
.backup-note { color: var(--muted); font-size: 14px; margin-top: var(--s7); text-align: center; }
.backup-warn { color: var(--error); font-size: 15px; font-weight: 700; text-align: center; margin-top: var(--s2); }

/* ---------- stages ---------- */

.stage-card { padding: var(--s5) var(--s6); display: flex; flex-direction: column; gap: var(--s4); }
.stage-card-main {
  display: flex;
  align-items: center;
  gap: var(--s5);
  width: 100%;
  text-align: start;
}
.stage-card-main img { width: 56px; height: 56px; flex: none; animation: wiggle 3s ease-in-out infinite; }
.stage-card-main .pack-info { flex: 1; }
.stage-card-main .pack-info h4 { font-size: 22px; }
.stage-card-main .pack-info p { color: var(--muted); font-size: 15px; }

.stage-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--s3);
  margin-bottom: var(--s5);
}
.stage-chip {
  aspect-ratio: 1;
  position: relative;
  border-radius: var(--radius-cell);
  border: var(--stroke-hair) solid var(--muted-line);
  background: var(--paper);
  overflow: hidden;
  padding: 0;
  min-height: 44px;
  font-size: 15px;
  color: var(--muted);
}
.stage-chip .num {
  position: relative;
  z-index: 2;
  font-weight: 700;
  text-shadow: 0 0 3px rgba(255, 253, 246, 0.8);
}
.stage-chip .quilt {
  position: absolute; inset: 0;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr;
  opacity: 0.85;
}
.stage-chip.done { border: var(--stroke) solid var(--ink); color: var(--ink); }
.stage-chip.frontier {
  border: var(--stroke-bold) solid var(--accent);
  background: var(--highlight);
  color: var(--ink);
  animation: pop-in 0.35s ease;
}
.stage-chip.locked { opacity: 0.55; }
.stage-chip .stage-lock {
  position: absolute;
  right: 2px;
  bottom: 2px;
  z-index: 2;
}
.stage-chip .stage-lock svg { width: 14px; height: 14px; }

/* ---------- tutorial ---------- */

.tut-veil {
  position: fixed;
  inset: 0;
  background: rgba(59, 58, 54, 0.45);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s6);
}
.tut-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--paper);
  border: var(--stroke-bold) solid var(--ink);
  border-radius: var(--radius-panel);
  padding: var(--s7);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--s4);
  animation: pop-in 0.35s ease;
}
.tut-card h2 { font-size: 26px; }
.tut-close { position: absolute; top: var(--s2); right: var(--s2); }
.tut-char img { width: 72px; height: 72px; animation: wiggle 2.8s ease-in-out infinite; }
.tut-art { display: flex; justify-content: center; min-height: 120px; align-items: center; }
.tut-text { font-size: 18px; line-height: 1.5; min-height: 3em; }
.tut-note { color: var(--muted); }

.tut-board {
  display: grid;
  grid-template-columns: repeat(4, 34px);
  grid-template-rows: repeat(4, 34px);
  gap: 4px;
}
.tut-cell {
  border-radius: var(--radius-cell);
  border: var(--stroke-hair) solid rgba(59, 58, 54, 0.16);
  display: flex;
  align-items: center;
  justify-content: center;
}
.tut-cell svg.star { width: 62%; height: 62%; }
.tut-cell svg.star path { fill: var(--gold); stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; }
.tut-cell .mark { font-size: 22px; color: rgba(59, 58, 54, 0.55); font-weight: 700; font-family: sans-serif; }
.tut-cell.big { width: 52px; height: 52px; }

.tut-taps { display: flex; align-items: center; gap: var(--s3); }
.tut-arrow { font-size: 22px; color: var(--muted); }

.tut-tools { display: flex; gap: var(--s5); }
.tut-tools .box {
  width: 56px; height: 56px;
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  display: flex; align-items: center; justify-content: center;
  background: var(--paper);
}
.tut-tools .box svg { width: 26px; height: 26px; }
.tut-tools .box img { width: 40px; height: 40px; }
.tut-tools .box.hl { background: var(--highlight); }

.tut-stickers { display: flex; gap: var(--s3); }
.tut-stickers .sticker { width: 44px; }

.tut-dots { display: flex; justify-content: center; gap: var(--s3); }
.tut-dots i {
  width: 10px; height: 10px;
  border-radius: 50% 45% 55% 48%;
  background: var(--muted-line);
  display: inline-block;
  transition: background var(--pop), transform var(--pop);
}
.tut-dots i.on { background: var(--accent); transform: scale(1.3); }

/* ---------- ranking ---------- */

.rank-box { width: 100%; max-width: 340px; margin: var(--s5) auto 0; min-height: 0; }
.rank-optin {
  border: var(--stroke) solid var(--ink);
  border-radius: var(--radius-card);
  background: var(--paper);
  padding: var(--s5);
  display: flex;
  flex-direction: column;
  gap: var(--s4);
}
.rank-ask { font-size: 18px; font-weight: 700; }
.rank-btns { display: flex; flex-direction: column; gap: var(--s2); }
.rank-btns .btn { padding: var(--s3) var(--s5); font-size: 17px; }

input.rank-nick {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: var(--paper);
  border: var(--stroke) dashed var(--muted-line);
  border-radius: var(--radius-chip);
  padding: var(--s3) var(--s4);
  width: 100%;
  max-width: 190px;
}
input.rank-nick:focus { outline: none; border-color: var(--ink); }

.rank-result { font-size: 21px; font-weight: 700; color: var(--ink); animation: pop-in var(--pop); }

.rank-list {
  max-height: 46dvh;
  overflow-y: auto;
  margin-top: var(--s4);
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}
.rank-row {
  display: flex;
  align-items: center;
  gap: var(--s4);
  padding: var(--s3) var(--s4);
  border: var(--stroke-hair) solid var(--hairline);
  border-radius: var(--radius-chip);
  font-size: 17px;
}
.rank-row.me { background: var(--highlight); border: var(--stroke) solid var(--accent); font-weight: 700; }
.rank-row:nth-child(1) .rank-pos, .rank-row:nth-child(2) .rank-pos, .rank-row:nth-child(3) .rank-pos { color: var(--accent); }
.rank-pos { min-width: 34px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.rank-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-time { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---------- misc ---------- */

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.empty-note { text-align: center; color: var(--muted); margin: var(--s8) 0; }
