/* Hoshi Salon — design tokens and styles */

@font-face {
  font-family: "Nunito";
  src: url("../vendor/fonts/Nunito-Variable.ttf") format("truetype");
  font-weight: 200 1000;
  font-display: swap;
}
@font-face {
  font-family: "Nunito Sans";
  src: url("../vendor/fonts/NunitoSans-Variable.ttf") format("truetype");
  font-weight: 200 1000;
  font-display: swap;
}

:root {
  /* colours */
  --bg: #fff6ee;
  --bg-2: #ffeef0;
  --panel: #ffffff;
  --panel-soft: #fffaf6;
  --ink: #4a3640;
  --ink-soft: #8a7280;
  --line: #f0dfe2;
  --accent: #e05a86;          /* overridden per character */
  --accent-soft: #fde4ec;
  --gold: #e9b44c;
  --mint: #7cc8a8;
  --danger: #e2574c;
  --black-stone: #2b2730;
  --white-stone: #fbf8f2;

  /* type */
  --font-display: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, sans-serif;
  --font-body: "Nunito Sans", system-ui, -apple-system, sans-serif;
  --fs-xs: 0.78rem;
  --fs-s: 0.9rem;
  --fs-m: 1rem;
  --fs-l: 1.25rem;
  --fs-xl: 1.7rem;
  --fs-xxl: clamp(2.4rem, 8vw, 4.2rem);

  /* spacing and shape */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --r-s: 10px;
  --r-m: 16px;
  --r-l: 24px;
  --r-pill: 999px;
  --shadow-s: 0 2px 6px rgba(120, 60, 80, 0.10);
  --shadow-m: 0 8px 24px rgba(120, 60, 80, 0.14);
  --shadow-l: 0 18px 48px rgba(120, 60, 80, 0.20);

  /* motion */
  --ease: cubic-bezier(0.22, 0.8, 0.3, 1);
  --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
  --t-fast: 140ms;
  --t-screen: 260ms;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--fs-m);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 800; margin: 0; }
button { font: inherit; color: inherit; }

#app { position: relative; min-height: 100%; min-height: 100dvh; }

.boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  text-align: center;
  font-family: var(--font-display);
  color: var(--ink-soft);
}
.logo {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: var(--fs-xxl);
  color: var(--accent);
  letter-spacing: 0.01em;
}

/* ---------- board ---------- */
.board-canvas {
  display: block;
  border-radius: 14px;
  box-shadow: 0 2px 0 #c8955a, 0 6px 0 #b98549, var(--shadow-l);
  cursor: pointer;
}

/* ---------- screens & transitions ---------- */
.screen {
  position: absolute;
  inset: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  background-size: cover;
  background-position: center;
  background-color: var(--bg);
  transition: opacity var(--t-screen) var(--ease), transform var(--t-screen) var(--ease);
}
.screen.enter { opacity: 0; transform: translateY(12px) scale(0.99); }
.screen.active { opacity: 1; transform: none; }
.screen.leave { opacity: 0; transform: translateY(-8px); pointer-events: none; }
.reduce-motion .screen { transition: opacity 120ms linear; transform: none !important; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 2px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--fs-m);
  padding: 11px 20px;
  border-radius: var(--r-pill);
  box-shadow: 0 3px 0 var(--line), var(--shadow-s);
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast);
  min-height: 44px;
}
.btn:hover { background: var(--panel-soft); }
.btn:active { transform: translateY(3px) scale(0.98); box-shadow: 0 0 0 var(--line), var(--shadow-s); }
.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 0 color-mix(in srgb, var(--accent) 70%, #000 30%), var(--shadow-m);
}
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 90%, #fff 10%); }
.btn.primary:active { box-shadow: 0 0 0 transparent, var(--shadow-s); }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; box-shadow: 0 4px 0 #a8382f; }
.btn.big { font-size: var(--fs-l); padding: 14px 28px; width: 100%; }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, #fff); outline-offset: 2px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--panel);
  font-size: 1.3rem; font-weight: 800; cursor: pointer;
  box-shadow: 0 3px 0 var(--line);
  transition: transform var(--t-fast) var(--ease);
}
.icon-btn:active { transform: translateY(3px); box-shadow: none; }

/* ---------- panels ---------- */
.panel {
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  border-radius: var(--r-l);
  box-shadow: var(--shadow-l);
  border: 1px solid rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(8px);
}
.panel-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.panel-head h2 { font-size: var(--fs-xl); }
.panel section { margin-top: var(--sp-5); }
.panel h3 { font-size: var(--fs-s); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); margin-bottom: var(--sp-2); }
.small-print { font-size: var(--fs-xs); color: var(--ink-soft); margin: var(--sp-2) 0 0; }
.small-print.warn { color: var(--danger); }

/* ---------- character view ---------- */
.charview { position: relative; display: flex; flex-direction: column; align-items: center; }
.portrait-wrap { position: relative; cursor: pointer; transform-origin: 50% 100%; }
.portrait-wrap.pop { animation: pop 260ms var(--ease-bounce); }
.portrait {
  display: block; width: 100%; height: 100%; object-fit: contain; object-position: bottom;
  transform-origin: 50% 100%;
  animation: breathe 4.2s ease-in-out infinite;
  user-select: none; -webkit-user-drag: none;
  filter: drop-shadow(0 8px 18px rgba(120, 60, 80, 0.18));
}
.portrait-glow {
  position: absolute; left: 10%; right: 10%; bottom: 2%; height: 70%;
  background: radial-gradient(circle at 50% 60%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 70%);
  filter: blur(8px);
}
@keyframes breathe { 0%, 100% { transform: translateY(0) scale(1, 1); } 50% { transform: translateY(-2px) scale(1.006, 1.012); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.035); } 100% { transform: scale(1); } }
.reduce-motion .portrait, .reduce-motion .portrait-wrap.pop { animation: none; }

.bubble {
  position: relative;
  background: var(--panel);
  border-radius: var(--r-m);
  padding: 10px 16px 12px;
  box-shadow: var(--shadow-m);
  border: 2px solid color-mix(in srgb, var(--accent) 25%, #fff);
  min-height: 3.2em;
  font-weight: 600;
  opacity: 0;
  transform: translateY(6px) scale(0.97);
  transition: opacity 180ms var(--ease), transform 220ms var(--ease-bounce);
  pointer-events: none;
}
.bubble.show { opacity: 1; transform: none; }
.bubble-name {
  position: absolute; top: -12px; left: 14px;
  background: var(--accent); color: #fff;
  font-family: var(--font-display); font-weight: 800; font-size: var(--fs-xs);
  padding: 2px 10px; border-radius: var(--r-pill);
}
.bubble-text { display: block; padding-top: 2px; }

.charview.stage { width: min(100%, 460px); }
.charview.stage .portrait-wrap { width: 100%; aspect-ratio: 400 / 480; }
.charview.stage .bubble { position: absolute; left: 50%; top: 4%; width: min(92%, 340px); translate: -50% 0; }
.charview.stage .bubble::after {
  content: ""; position: absolute; left: 50%; bottom: -10px; width: 18px; height: 18px;
  background: var(--panel); border-right: 2px solid color-mix(in srgb, var(--accent) 25%, #fff); border-bottom: 2px solid color-mix(in srgb, var(--accent) 25%, #fff);
  transform: translateX(-50%) rotate(45deg);
}

/* ---------- title ---------- */
.title-screen {
  display: grid; grid-template-rows: auto 1fr auto; justify-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px 28px; cursor: pointer; outline: none;
}
.title-logo { text-align: center; position: relative; margin-top: 2vh; }
.title-logo .logo { text-shadow: 0 4px 0 #fff, 0 8px 24px rgba(224, 90, 134, 0.35); }
.logo-star { position: absolute; top: -10px; right: -26px; color: var(--gold); font-size: 2rem; animation: twinkle 2.4s ease-in-out infinite; }
.logo-tag { margin: 4px 0 0; font-family: var(--font-display); font-weight: 700; color: var(--ink-soft); }
@keyframes twinkle { 0%, 100% { transform: scale(1) rotate(0); opacity: 1; } 50% { transform: scale(1.25) rotate(20deg); opacity: 0.7; } }
.title-stage { display: flex; align-items: flex-end; justify-content: center; width: 100%; min-height: 0; }
.title-stage .charview.stage { width: min(80vw, 52vh, 440px); }
.tap-start {
  border: none; background: var(--panel); color: var(--accent);
  font-family: var(--font-display); font-weight: 900; font-size: var(--fs-l);
  padding: 12px 34px; border-radius: var(--r-pill); box-shadow: var(--shadow-m);
  animation: breathe-btn 1.8s ease-in-out infinite; cursor: pointer;
}
@keyframes breathe-btn { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.05); opacity: 0.85; } }

/* ---------- home ---------- */
.home {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "stage menu";
  padding: 16px clamp(16px, 4vw, 48px) 0;
  gap: 8px 24px;
}
.topbar { grid-area: top; display: flex; justify-content: space-between; align-items: center; gap: 8px; min-width: 0; }
.brand {
  font-family: var(--font-display); font-weight: 900; font-size: var(--fs-l); color: var(--accent);
  background: var(--panel); padding: 6px 16px; border-radius: var(--r-pill); box-shadow: var(--shadow-s);
}
.brand-star { color: var(--gold); margin-right: 6px; }
.stat-chip { background: var(--panel); padding: 6px 14px; border-radius: var(--r-pill); font-weight: 800; font-family: var(--font-display); box-shadow: var(--shadow-s); }
.home-stage { grid-area: stage; display: flex; align-items: flex-end; justify-content: center; min-height: 0; }
.home-stage .charview.stage { width: min(100%, 64vh, 520px); }
.home-menu { grid-area: menu; display: flex; flex-direction: column; justify-content: center; gap: 12px; padding-bottom: 24px; }
.menu-btn {
  display: flex; align-items: center; gap: 12px;
  border: 2px solid rgba(255, 255, 255, 0.9); background: color-mix(in srgb, var(--panel) 92%, transparent);
  padding: 14px 18px; border-radius: var(--r-m);
  font-family: var(--font-display); font-weight: 800; font-size: var(--fs-l);
  box-shadow: 0 4px 0 var(--line), var(--shadow-m); cursor: pointer; text-align: left;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.menu-btn:hover { transform: translateX(-3px); }
.menu-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--line), var(--shadow-s); }
.menu-btn.primary { background: var(--accent); color: #fff; font-size: 1.5rem; padding: 18px 22px; box-shadow: 0 5px 0 color-mix(in srgb, var(--accent) 70%, #000 30%), var(--shadow-l); }
.menu-icon { width: 1.6em; text-align: center; }
.menu-label { flex: 1; }
.menu-btn.soon { color: var(--ink-soft); }
.soon-tag { font-size: var(--fs-xs); background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: var(--r-pill); }

/* ---------- setup & settings ---------- */
.setup, .settings-screen { display: flex; justify-content: center; align-items: flex-start; padding: 24px 16px; }
.setup-panel, .settings-panel { width: min(100%, 560px); padding: 20px 24px 24px; margin: auto 0; }
.opp-list { display: grid; grid-template-columns: 1fr; gap: 10px; }
.opp-card {
  display: flex; align-items: center; gap: 12px; text-align: left;
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--r-m); padding: 8px 12px; font: inherit;
}
.opp-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.opp-card img { width: 64px; height: 76px; object-fit: cover; object-position: top; border-radius: 12px; background: #fff; }
.opp-info { display: flex; flex-direction: column; }
.opp-info strong { font-family: var(--font-display); font-size: var(--fs-l); }
.opp-info span { font-size: var(--fs-s); font-weight: 700; color: var(--accent); }
.opp-info em { font-size: var(--fs-s); color: var(--ink-soft); }
.opp-card.locked { opacity: 0.6; border-style: dashed; }
.silhouette { width: 64px; height: 64px; border-radius: 12px; background: var(--line); display: grid; place-content: center; font-family: var(--font-display); font-size: 1.8rem; color: #fff; }
.segmented { display: flex; gap: 6px; background: var(--panel-soft); padding: 5px; border-radius: var(--r-m); border: 1px solid var(--line); }
.seg {
  flex: 1; border: none; background: transparent; padding: 8px 6px; border-radius: 12px;
  font-family: var(--font-display); font-weight: 800; cursor: pointer; display: flex; flex-direction: column; align-items: center;
  transition: background var(--t-fast), color var(--t-fast);
}
.seg small { font-family: var(--font-body); font-weight: 600; font-size: 0.72rem; color: var(--ink-soft); }
.seg[aria-checked="true"] { background: var(--panel); color: var(--accent); box-shadow: var(--shadow-s); }
.seg:disabled { opacity: 0.45; cursor: default; }
.setup-panel .btn.big { margin-top: var(--sp-5); }

.toggles { display: flex; flex-direction: column; gap: 4px; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 8px 2px; cursor: pointer; position: relative; }
.toggle-text { flex: 1; font-weight: 700; display: flex; flex-direction: column; }
.toggle-text small { font-weight: 500; color: var(--ink-soft); font-size: var(--fs-xs); }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { width: 48px; height: 28px; border-radius: 14px; background: var(--line); position: relative; flex: none; transition: background var(--t-fast); }
.toggle-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-s); transition: transform 200ms var(--ease-bounce); }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid color-mix(in srgb, var(--accent) 60%, #fff); outline-offset: 2px; }

.slider { display: grid; grid-template-columns: 5.5em 1fr 3em; align-items: center; gap: 10px; padding: 6px 0; font-weight: 700; }
.slider input { accent-color: var(--accent); width: 100%; }
.slider output { text-align: right; color: var(--ink-soft); font-size: var(--fs-s); }
.save-stats { margin: 4px 0; font-weight: 600; }
.row-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }

/* ---------- match ---------- */
.screen-match { overflow: hidden; }
.match {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(250px, 330px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "char board" "hud board";
  gap: 16px 24px;
  padding: 16px 24px;
  background:
    radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 45%),
    radial-gradient(circle at 90% 90%, #e8f3ff, transparent 40%),
    var(--bg);
}
.char-area { grid-area: char; min-height: 0; display: flex; }
.board-area { grid-area: board; min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.hud-area { grid-area: hud; display: flex; flex-direction: column; gap: 10px; }
.board-wrap { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.board-wrap.shake { animation: shake 280ms ease; }
@keyframes shake { 20% { transform: translateX(-5px); } 40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(2px); } }

.charview.side { width: 100%; height: 100%; justify-content: flex-end; gap: 14px; }
.charview.side .portrait-wrap { flex: 1; min-height: 120px; width: 100%; display: flex; justify-content: center; }
.charview.side .portrait { width: auto; max-width: 100%; }
.charview.side .bubble { width: 100%; }

.players { display: flex; align-items: center; gap: 8px; }
.vs { font-family: var(--font-display); font-weight: 900; color: var(--ink-soft); font-size: var(--fs-s); }
.player-chip {
  flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0;
  background: var(--panel); border-radius: var(--r-m); padding: 8px 10px; box-shadow: var(--shadow-s);
  border: 2px solid transparent; transition: border-color var(--t-fast), transform var(--t-fast);
}
.player-chip.turn { border-color: var(--accent); transform: translateY(-2px); box-shadow: var(--shadow-m); }
.chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.chip-text strong { font-family: var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip-text small { color: var(--ink-soft); font-size: 0.72rem; white-space: nowrap; }
.stone-dot { display: inline-block; width: 22px; height: 22px; border-radius: 50%; flex: none; vertical-align: -5px; }
.stone-dot[data-color="1"] { background: radial-gradient(circle at 35% 30%, #6a6470, #17141a 70%); }
.stone-dot[data-color="2"] { background: radial-gradient(circle at 35% 30%, #fff, #d9d1c4 80%); box-shadow: inset 0 0 0 1px rgba(140,125,110,0.4); }
.status { font-family: var(--font-display); font-weight: 800; text-align: center; color: var(--ink); min-height: 1.5em; }
.status.thinking::after { content: "…"; display: inline-block; animation: dots 1.2s steps(4) infinite; width: 1.2em; text-align: left; overflow: hidden; vertical-align: bottom; }
@keyframes dots { 0% { width: 0; } 100% { width: 1.2em; } }
.actions { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.act {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 2px solid var(--line); background: var(--panel); border-radius: 14px; padding: 8px 2px;
  font-family: var(--font-display); font-weight: 800; font-size: var(--fs-xs); cursor: pointer;
  box-shadow: 0 3px 0 var(--line); min-height: 52px;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast);
}
.act:active:not(:disabled) { transform: translateY(3px); box-shadow: none; }
.act:disabled { opacity: 0.4; cursor: default; }
.act-icon { font-size: 1.15rem; line-height: 1; }
.score-panel { background: var(--panel); border-radius: var(--r-m); padding: 12px; box-shadow: var(--shadow-m); }
.score-line { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center; font-weight: 700; }
.score-result { width: 100%; text-align: center; font-family: var(--font-display); font-size: var(--fs-l); color: var(--accent); }
.score-help { font-size: var(--fs-xs); color: var(--ink-soft); text-align: center; margin: 6px 0 10px; }
.score-actions { display: flex; gap: 8px; justify-content: center; }
.score-actions .btn { flex: 1; padding: 10px 8px; }

/* ---------- results ---------- */
.results {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 480px);
  align-items: center; gap: 16px clamp(16px, 4vw, 56px); padding: 24px clamp(16px, 4vw, 48px);
}
.results-stage { display: flex; justify-content: center; align-items: flex-end; align-self: end; }
.results-stage .charview.stage { width: min(100%, 70vh, 500px); }
.results-panel { padding: 22px 24px; }
.banner {
  font-family: var(--font-display); font-weight: 900; font-size: clamp(2rem, 6vw, 3rem); text-align: center;
  animation: banner-in 600ms var(--ease-bounce) both;
}
.banner.win { color: var(--accent); text-shadow: 0 3px 0 #fff, 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent); }
.banner.lose { color: var(--ink); }
@keyframes banner-in { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }
.result-reason { text-align: center; font-weight: 700; margin: 4px 0 14px; }
.result-code { color: var(--ink-soft); font-weight: 600; }
.score-table { width: 100%; border-collapse: collapse; font-size: var(--fs-s); }
.score-table th, .score-table td { padding: 7px 8px; text-align: right; border-bottom: 1px solid var(--line); }
.score-table th:first-child { text-align: left; font-weight: 600; color: var(--ink-soft); }
.score-table thead th { font-family: var(--font-display); color: var(--ink); white-space: nowrap; }
.score-table tr.total th, .score-table tr.total td { font-weight: 900; font-family: var(--font-display); font-size: var(--fs-m); border-bottom: none; color: var(--ink); }
.results-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.results-actions .btn { flex: 1 1 auto; }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 6px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 0.6; } }
.reduce-motion .confetti { display: none; }

/* ---------- toasts & dialogs ---------- */
#toasts {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none;
  width: min(92vw, 440px);
}
.toast {
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: var(--r-m);
  font-weight: 700; box-shadow: var(--shadow-l); text-align: center;
  opacity: 0; transform: translateY(10px); transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}
.toast.warn { background: #fff; color: var(--ink); border-left: 5px solid var(--danger); }
.toast.show { opacity: 1; transform: none; }
.overlay {
  position: fixed; inset: 0; z-index: 40; background: rgba(74, 54, 64, 0.32); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 16px; opacity: 0; transition: opacity 200ms var(--ease);
}
.overlay.show { opacity: 1; }
.dialog {
  background: var(--panel); border-radius: var(--r-l); padding: 22px; width: min(100%, 460px);
  max-height: calc(100dvh - 32px); overflow-y: auto; box-shadow: var(--shadow-l);
  transform: scale(0.95); transition: transform 220ms var(--ease-bounce);
}
.overlay.show .dialog { transform: none; }
.dialog-title { font-size: var(--fs-xl); margin-bottom: 6px; }
.dialog-text { color: var(--ink-soft); margin: 0 0 8px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.match-menu section:first-of-type { margin-top: 10px; }
.match-menu section { margin-top: 16px; }
.match-menu h3 { font-size: var(--fs-s); text-transform: uppercase; letter-spacing: 0.08em; color: var(--ink-soft); }

/* ---------- portrait / narrow layouts ---------- */
@media (orientation: portrait), (max-width: 760px) {
  .home {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas: "top" "stage" "menu";
    padding: 12px 16px 0;
  }
  .home-stage .charview.stage { width: min(100%, 46dvh, 440px); }
  .home-menu { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
  .home-menu .menu-btn { font-size: var(--fs-m); padding: 12px 10px; gap: 6px; min-width: 0; }
  .home-menu .menu-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .home-menu .soon-tag { font-size: 0.66rem; padding: 2px 6px; }
  .home-menu .menu-btn.primary { grid-column: 1 / -1; justify-content: center; font-size: var(--fs-xl); }
  .home-menu .menu-btn.primary .menu-label { flex: none; }
  .home-menu .menu-btn:hover { transform: none; }

  .screen-match { overflow-y: auto; }
  .match {
    height: auto; min-height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas: "char" "board" "hud";
    gap: 10px; padding: 10px 16px max(16px, env(safe-area-inset-bottom));
    align-content: start;
  }
  .board-area { width: 100%; }
  .board-wrap { width: 100%; height: auto; aspect-ratio: 1; max-width: 640px; }
  .charview.side { flex-direction: row; align-items: flex-end; height: auto; gap: 10px; }
  .charview.side .portrait-wrap { flex: none; width: 92px; height: 110px; min-height: 0; }
  .charview.side .bubble { flex: 1; margin-bottom: 6px; min-height: 4.2em; }
  .charview.side .portrait-glow { display: none; }

  .results { grid-template-columns: 1fr; align-items: start; padding: 16px; }
  .results-stage { align-self: center; }
  .results-stage .charview.stage { width: min(100%, 36dvh, 340px); }
}
@media (max-width: 420px) {
  .home-menu .soon-tag { display: none; }
  .home-menu .menu-btn.soon { opacity: 0.75; }
}
@media (max-width: 400px) {
  .act-label { font-size: 0.68rem; }
  .setup-panel, .settings-panel { padding: 16px; }
}
/* short landscape screens (phones on their side) */
@media (orientation: landscape) and (max-height: 520px) {
  .match { grid-template-columns: minmax(220px, 300px) minmax(0, 1fr); padding: 8px 16px; gap: 8px 16px; }
  .charview.side .portrait-wrap { min-height: 60px; }
  .act { min-height: 44px; padding: 4px 2px; }
}
/* tablets held upright: a bigger portrait above the board */
@media (orientation: portrait) and (min-width: 600px) {
  .charview.side .portrait-wrap { width: 150px; height: 180px; }
  .charview.side .bubble { font-size: var(--fs-l); }
  .match { padding-left: 24px; padding-right: 24px; }
  .board-wrap { margin: 0 auto; max-width: min(640px, calc(100dvh - 420px)); }
}

/* ---------- Milestone 2: rooms, ranks, review ---------- */
.room-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.room-card {
  display: grid; grid-template-columns: 44px 1fr; grid-template-rows: auto auto; column-gap: 10px; align-items: center; text-align: left;
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--r-m); padding: 8px 10px; font: inherit; cursor: pointer;
}
.room-card img { grid-row: 1 / 3; width: 44px; height: 44px; }
.room-card strong { font-family: var(--font-display); font-size: var(--fs-m); line-height: 1.15; }
.room-card small { font-size: 0.72rem; color: var(--ink-soft); line-height: 1.25; }
.room-card.selected { border-color: var(--room); background: color-mix(in srgb, var(--room) 12%, #fff); }
.room-card.locked { opacity: 0.6; filter: grayscale(0.6); }
.badge { display: inline-block; margin-left: 6px; font-size: 0.68rem; font-family: var(--font-body); font-weight: 800; padding: 1px 8px; border-radius: var(--r-pill); background: var(--accent); color: #fff; vertical-align: 2px; }
.badge.won { background: var(--mint); }
.start-ranks { display: grid; gap: 8px; margin-top: 10px; }
.start-rank { display: flex; flex-direction: column; text-align: left; gap: 2px; padding: 10px 14px; border-radius: var(--r-m); border: 2px solid var(--line); background: var(--panel); font: inherit; cursor: pointer; }
.start-rank:hover { border-color: var(--accent); }
.start-rank strong { font-family: var(--font-display); }
.start-rank span { font-size: var(--fs-s); color: var(--ink-soft); }

.match { background:
    linear-gradient(color-mix(in srgb, var(--bg) 80%, transparent), color-mix(in srgb, var(--bg) 88%, transparent)),
    var(--room-bg, none) center / cover,
    var(--bg); }
.match-tags { display: flex; flex-wrap: wrap; gap: 4px; justify-content: center; }
.tag { font-size: 0.7rem; font-weight: 800; padding: 2px 8px; border-radius: var(--r-pill); background: var(--panel); box-shadow: var(--shadow-s); color: var(--ink-soft); }
.tag.ranked { background: var(--accent); color: #fff; }

.menu-btn.continue { background: var(--accent); color: #fff; font-size: 1.4rem; box-shadow: 0 5px 0 color-mix(in srgb, var(--accent) 70%, #000 30%), var(--shadow-l); }
.menu-btn.continue small { font-family: var(--font-body); font-size: var(--fs-s); font-weight: 700; opacity: 0.9; }
.stat-chip small { font-weight: 700; color: var(--ink-soft); }
@media (orientation: portrait), (max-width: 760px) {
  .home-menu .menu-btn.continue { grid-column: 1 / -1; justify-content: center; font-size: var(--fs-xl); }
  .home-menu .menu-btn.continue .menu-label { flex: none; }
  .room-list { grid-template-columns: 1fr; }
}

.rank-block { background: var(--panel-soft); border: 1px solid var(--line); border-radius: var(--r-m); padding: 10px 14px; margin: 6px 0 12px; }
.rank-block.up { border-color: var(--gold); background: #fff8e6; animation: banner-in 600ms var(--ease-bounce) both; }
.rank-head { display: flex; justify-content: space-between; align-items: baseline; font-family: var(--font-display); }
.rank-head span { font-weight: 800; color: var(--accent); }
.rank-bar { height: 10px; border-radius: 5px; background: var(--line); margin: 6px 0 4px; overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--gold)); border-radius: 5px; transition: width 800ms var(--ease); }
.rank-block small { color: var(--ink-soft); font-size: var(--fs-xs); }
.unlock-banner { display: flex; align-items: center; gap: 12px; background: linear-gradient(90deg, var(--accent-soft), #fff8e6); border-radius: var(--r-m); padding: 8px 12px; margin-bottom: 12px; animation: banner-in 700ms var(--ease-bounce) both; }
.unlock-banner img { width: 56px; height: 67px; object-fit: cover; object-position: top; border-radius: 10px; background: #fff; }
.unlock-banner div { display: flex; flex-direction: column; }
.unlock-banner strong { font-family: var(--font-display); font-size: var(--fs-l); }
.unlock-banner span { font-size: var(--fs-s); color: var(--ink-soft); }

.review { display: flex; justify-content: center; padding: 20px 16px; }
.review-panel { width: min(100%, 820px); padding: 18px 22px 24px; margin: auto 0; }
.review-sub { margin-left: auto; color: var(--ink-soft); font-weight: 700; font-size: var(--fs-s); }
.review-top .charview.side { flex-direction: row; align-items: flex-end; gap: 10px; height: auto; }
.review-top .charview.side .portrait-wrap { flex: none; width: 90px; height: 108px; min-height: 0; }
.review-top .charview.side .bubble { flex: 1; margin-bottom: 6px; }
.review-top .portrait-glow { display: none; }
.graph-box { margin-top: 12px; }
.wr-graph { width: 100%; height: auto; display: block; }
.review-progress { font-weight: 800; font-family: var(--font-display); margin: 8px 0; }
.moments { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.moment { display: flex; flex-direction: column; text-align: left; gap: 2px; background: var(--panel); border: 2px solid var(--line); border-radius: var(--r-m); padding: 8px 10px; font: inherit; cursor: pointer; }
.moment.selected { border-color: var(--accent); background: var(--accent-soft); }
.moment strong { font-family: var(--font-display); }
.moment span { color: var(--danger); font-weight: 800; font-size: var(--fs-s); }
.moment em { color: var(--ink-soft); font-size: var(--fs-xs); }
.review-main { display: grid; grid-template-columns: minmax(0, 360px) 1fr; gap: 16px; align-items: center; margin-top: 12px; }
.review-board { width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.review-caption { font-weight: 600; }
@media (max-width: 640px) {
  .moments { grid-template-columns: 1fr; }
  .review-main { grid-template-columns: 1fr; }
}
.room-opened { background: #fff8e6; border: 1px solid var(--gold); border-radius: var(--r-m); padding: 8px 12px; margin-bottom: 12px; font-weight: 800; font-family: var(--font-display); text-align: center; animation: banner-in 700ms var(--ease-bounce) both; }

/* ---------- Milestone 3: rewards ---------- */
.reward-block { background: var(--panel-soft); border: 1px solid var(--line); border-radius: var(--r-m); padding: 10px 14px; margin: 0 0 12px; display: grid; gap: 6px; }
.reward-row { display: flex; align-items: center; gap: 8px; }
.reward-row small { margin-left: auto; color: var(--ink-soft); font-weight: 700; }
.petal-icon { width: 22px; height: 22px; }
.hearts { display: inline-flex; gap: 2px; }
.heart { width: 16px; height: 16px; display: inline-block; background: var(--line); clip-path: path('M8 15 C1 10 1 3 5 2 C6.5 2 7.5 3 8 4 C8.5 3 9.5 2 11 2 C15 3 15 10 8 15 Z'); }
.heart.on { background: #ff7a9c; }
.bond-bar i { background: linear-gradient(90deg, #ff9ab6, #ff6f91); }
.achv { font-size: var(--fs-s); background: #fff8e6; border-radius: 10px; padding: 4px 10px; }
.bond-up { position: relative; text-align: center; background: linear-gradient(135deg, #ffe3ec, #fff3f7); border: 2px solid #ff9ab6; border-radius: var(--r-m); padding: 12px; margin: 0 0 12px; overflow: hidden; animation: banner-in 700ms var(--ease-bounce) both; }
.bond-up strong { font-family: var(--font-display); font-size: var(--fs-l); color: #d94f73; }
.bond-up ul { margin: 6px 0 0; padding: 0; list-style: none; font-weight: 700; font-size: var(--fs-s); }
.bond-up-hearts i { position: absolute; bottom: -20px; width: 14px; height: 14px; background: #ff7a9c; clip-path: path('M7 13 C1 9 1 3 4.5 2 C6 2 6.6 3 7 3.6 C7.4 3 8 2 9.5 2 C13 3 13 9 7 13 Z'); animation: float-up 2.6s ease-out infinite; }
.bond-up-hearts i:nth-child(1) { left: 8%; animation-delay: 0s; } .bond-up-hearts i:nth-child(2) { left: 22%; animation-delay: .4s; }
.bond-up-hearts i:nth-child(3) { left: 38%; animation-delay: .9s; } .bond-up-hearts i:nth-child(4) { left: 52%; animation-delay: .2s; }
.bond-up-hearts i:nth-child(5) { left: 66%; animation-delay: 1.1s; } .bond-up-hearts i:nth-child(6) { left: 80%; animation-delay: .6s; } .bond-up-hearts i:nth-child(7) { left: 92%; animation-delay: 1.4s; }
@keyframes float-up { 0% { transform: translateY(0) scale(.6); opacity: 0; } 20% { opacity: .9; } 100% { transform: translateY(-120px) scale(1.1); opacity: 0; } }
.reduce-motion .bond-up-hearts { display: none; }

/* ---------- Milestone 3: cosmetics ---------- */
.chip-title { font-style: normal; font-weight: 700; font-size: 0.72rem; color: var(--accent); font-family: var(--font-body); }
.player-chip[data-frame="frame-sakura"] { border-color: #ffb7c9; box-shadow: 0 0 0 3px #ffe3ec, var(--shadow-s); background: linear-gradient(135deg, #fff, #fff3f7); }
.player-chip[data-frame="frame-moon"] { border-color: #8f9ad8; box-shadow: 0 0 0 3px #e3e6ff, var(--shadow-s); background: linear-gradient(135deg, #fff, #f1f2ff); }
.player-chip[data-frame="frame-kohaku"] { border-color: #e05a86; box-shadow: 0 0 0 3px #ffd36b, var(--shadow-s); }
.player-chip[data-frame="frame-suzu"] { border-color: #22a39a; box-shadow: 0 0 0 3px #ff8fab, var(--shadow-s); }
.player-chip[data-frame="frame-celeste"] { border-color: #3f9e7a; box-shadow: 0 0 0 3px #e9d48a, var(--shadow-s); }
.player-chip[data-frame="frame-kai"] { border-color: #6f86b8; box-shadow: 0 0 0 3px #cfd6e6, var(--shadow-s); }
.confetti.sakura i { width: 12px; height: 9px; border-radius: 80% 0 80% 0; background: #ffb7c9 !important; }
.confetti.moon i { width: 10px; height: 10px; background: #fff3c4 !important; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }

/* ---------- Milestone 3: characters ---------- */
.characters-screen, .wardrobe-screen, .shop-screen, .tasks-screen { display: flex; justify-content: center; align-items: flex-start; padding: 20px 16px; }
.chars-panel { width: min(100%, 760px); padding: 18px 22px 24px; margin: auto 0; }
.char-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.char-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; background: var(--panel); border: 2px solid var(--line); border-radius: var(--r-m); padding: 10px 6px 12px; font: inherit; cursor: pointer; transition: transform var(--t-fast) var(--ease); }
.char-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.char-card img { width: 100%; aspect-ratio: 5 / 6; object-fit: cover; object-position: top; border-radius: 12px; background: linear-gradient(var(--accent-soft), #fff); }
.char-card strong { font-family: var(--font-display); font-size: var(--fs-l); }
.char-card small { font-size: 0.72rem; color: var(--ink-soft); text-align: center; }
.char-card.locked img { background: none; filter: brightness(0) opacity(0.3); }
.char-card .badge { position: absolute; top: 8px; right: 8px; }
.profile { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 460px); gap: 16px 32px; width: min(100%, 1060px); align-items: end; margin: auto 0; }
.profile-stage { display: flex; justify-content: center; }
.profile-stage .charview.stage { width: min(100%, 64vh, 460px); }
.profile-panel { padding: 18px 20px 22px; align-self: center; max-height: calc(100dvh - 40px); overflow-y: auto; }
.tabs { margin-bottom: 12px; }
.bio { margin-top: 0; }
.facts { display: grid; grid-template-columns: 7.5em 1fr; gap: 4px 12px; font-size: var(--fs-s); margin: 0 0 14px; }
.facts dt { font-weight: 800; color: var(--ink-soft); }
.facts dd { margin: 0; }
.bond-head { display: flex; align-items: center; gap: 10px; }
.bond-head small { margin-left: auto; color: var(--ink-soft); font-weight: 700; }
.reward-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 4px; font-size: var(--fs-s); }
.reward-list li { display: flex; gap: 8px; padding: 6px 10px; border-radius: 10px; background: var(--panel-soft); color: var(--ink-soft); }
.reward-list li.got { background: #ffe8ef; color: var(--ink); font-weight: 700; }
.reward-list .lv { min-width: 2.6em; font-weight: 900; color: #d94f73; }
.gift-row { display: flex; flex-wrap: wrap; gap: 8px; }
.gift { display: flex; flex-direction: column; align-items: center; padding: 6px 10px; border-radius: 12px; border: 2px solid var(--line); background: var(--panel); cursor: pointer; font: inherit; }
.gift-icon { font-size: 1.6rem; line-height: 1.2; }
.linkish { background: none; border: none; color: var(--accent); font-weight: 800; cursor: pointer; padding: 0; text-decoration: underline; }
.line-gallery { display: grid; gap: 10px; }
.line-group h4 { margin: 0 0 4px; font-family: var(--font-display); font-size: var(--fs-s); color: var(--ink-soft); }
.line { display: block; width: 100%; text-align: left; font: inherit; font-size: var(--fs-s); background: var(--panel-soft); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; margin-bottom: 4px; cursor: pointer; }
.line.locked { color: var(--ink-soft); cursor: default; }
.outfit-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.outfit-card { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px; border-radius: var(--r-m); border: 2px solid var(--line); background: var(--panel); font: inherit; cursor: pointer; }
.outfit-card img { width: 100%; aspect-ratio: 5 / 6; object-fit: cover; object-position: top; border-radius: 10px; background: linear-gradient(var(--accent-soft), #fff); }
.outfit-card.selected { border-color: var(--accent); background: var(--accent-soft); }
.outfit-card.locked img { filter: grayscale(0.8) opacity(0.6); }
.outfit-card small { font-size: 0.72rem; color: var(--ink-soft); }
@media (orientation: portrait), (max-width: 760px) {
  .char-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile { grid-template-columns: minmax(0, 1fr); }
  .profile-stage .charview.stage { width: min(100%, 34dvh, 300px); }
  .profile-panel { max-height: none; }
}

/* ---------- Milestone 3: wardrobe & shop ---------- */
.wardrobe-panel { width: min(100%, 980px); padding: 18px 22px 24px; margin: auto 0; }
.shop-panel { width: min(100%, 760px); padding: 18px 22px 24px; margin: auto 0; }
.petal-balance { margin-left: auto; display: inline-flex; align-items: center; gap: 4px; background: #fff0f5; padding: 4px 12px; border-radius: var(--r-pill); font-family: var(--font-display); font-weight: 900; }
.petals-chip { display: inline-flex; align-items: center; gap: 4px; }
.topbar { flex-wrap: wrap; }
.topbar .stat-chip + .stat-chip { margin-left: -8px; }
.wardrobe-grid { display: grid; grid-template-columns: minmax(0, 380px) 1fr; gap: 20px; align-items: start; }
.wardrobe-preview { display: grid; gap: 10px; position: sticky; top: 0; }
.wardrobe-board { width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.preview-chip { max-width: 320px; }
.slots { display: grid; gap: 4px; }
.slot h3 { margin-bottom: 6px; }
.slots .slot { margin-top: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.choice { border: 2px solid var(--line); background: var(--panel); border-radius: var(--r-pill); padding: 6px 14px; font: inherit; font-weight: 700; font-size: var(--fs-s); cursor: pointer; }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.choice.more { border-style: dashed; color: var(--ink-soft); }
.kit { margin-top: 14px; }
.kit-items, .gift-shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.shop-item { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-items: center; column-gap: 8px; background: var(--panel); border: 2px solid var(--line); border-radius: var(--r-m); padding: 8px 10px; }
.shop-item strong { font-family: var(--font-display); }
.shop-item small { grid-column: 1; color: var(--ink-soft); font-size: 0.72rem; }
.shop-item .buy, .shop-item .owned-tag { grid-column: 2; grid-row: 1 / 3; }
.gift-shop .shop-item { grid-template-columns: auto 1fr auto; }
.gift-shop .gift-icon { grid-row: 1 / 3; }
.gift-shop .shop-item small { grid-column: 2; }
.gift-shop .shop-item .buy { grid-column: 3; }
.shop-item.owned { opacity: 0.7; }
.owned-tag { color: var(--mint); font-weight: 900; font-size: var(--fs-s); }
.btn.buy { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; min-height: 36px; font-size: var(--fs-s); }
.price { display: inline-flex; align-items: center; gap: 3px; }
.price .petal-icon { width: 18px; height: 18px; }
.shop-outfits { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
@media (orientation: portrait), (max-width: 760px) {
  .wardrobe-grid { grid-template-columns: 1fr; }
  .wardrobe-preview { position: static; }
}

/* ---------- Milestone 3: emotes ---------- */
.char-area { position: relative; }
.emote-box { position: absolute; top: 4%; right: 4%; z-index: 3; pointer-events: none; }
.emote-pop { width: 92px; height: 92px; filter: drop-shadow(0 6px 12px rgba(120, 60, 80, 0.25)); animation: emote-in 420ms var(--ease-bounce) both; }
.emote-pop.out, .player-emote.out { animation: emote-out 300ms ease forwards; }
@keyframes emote-in { from { transform: scale(0.3) rotate(-15deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes emote-out { to { transform: scale(0.6); opacity: 0; } }
.player-emote-box { position: absolute; left: 54px; top: 4px; z-index: 3; pointer-events: none; }
.player-emote { display: flex; flex-direction: column; align-items: center; background: #fff; border-radius: 18px; padding: 6px 12px; box-shadow: var(--shadow-m); animation: emote-in 380ms var(--ease-bounce) both; }
.player-emote span { font-size: 2rem; line-height: 1.1; }
.player-emote small { font-weight: 800; font-size: 0.72rem; color: var(--ink-soft); }
.emote-btn { position: absolute; left: 6px; top: 6px; z-index: 4; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: var(--panel); font-size: 1.2rem; cursor: pointer; box-shadow: var(--shadow-s); }
.emote-picker { position: absolute; left: 6px; top: 52px; z-index: 5; display: grid; grid-template-columns: repeat(3, 44px); gap: 4px; background: var(--panel); border-radius: var(--r-m); padding: 6px; box-shadow: var(--shadow-l); }
.emote-picker button { width: 44px; height: 44px; border: none; background: var(--panel-soft); border-radius: 12px; font-size: 1.4rem; cursor: pointer; }
.emote-picker button:hover { background: var(--accent-soft); }
@media (orientation: portrait), (max-width: 760px) {
  .emote-pop { width: 64px; height: 64px; }
  .emote-box { top: -6px; right: 2px; }
  .emote-btn { left: auto; right: 4px; bottom: auto; top: -6px; width: 34px; height: 34px; font-size: 1rem; }
  .emote-picker { left: auto; right: 4px; bottom: auto; top: 32px; }
  .player-emote-box { left: 96px; top: -8px; }
}
.reduce-motion .emote-pop, .reduce-motion .player-emote { animation: none; }

/* ---------- Milestone 3: tasks ---------- */
.task-list, .achv-list { display: grid; gap: 8px; }
.task { display: flex; align-items: center; gap: 12px; background: var(--panel); border: 2px solid var(--line); border-radius: var(--r-m); padding: 10px 12px; }
.task.done { border-color: var(--gold); background: #fffaf0; }
.task.claimed { opacity: 0.6; }
.task-text { flex: 1; display: grid; gap: 2px; }
.task-text small { color: var(--ink-soft); font-size: 0.72rem; }
.achv-item { display: grid; grid-template-columns: 2em 1fr auto; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-m); padding: 8px 12px; opacity: 0.65; }
.achv-item.got { opacity: 1; border-color: var(--gold); background: #fffaf0; }
.achv-item small { display: block; color: var(--ink-soft); font-size: 0.75rem; }
.achv-icon { font-size: 1.3rem; text-align: center; }
.achv-reward { display: inline-flex; align-items: center; gap: 2px; font-weight: 800; font-size: var(--fs-s); }
.achv-reward em { font-weight: 700; color: var(--accent); font-style: normal; }
.achv-reward .petal-icon { width: 16px; height: 16px; }
.menu-btn { position: relative; }
.dot { position: absolute; top: -6px; right: -6px; min-width: 22px; height: 22px; border-radius: 11px; background: var(--danger); color: #fff; font-size: 0.75rem; display: grid; place-content: center; padding: 0 6px; font-family: var(--font-body); font-weight: 900; }
@media (max-width: 520px) { .achv-item { grid-template-columns: 2em 1fr; } .achv-reward { grid-column: 2; } }

/* ---------- Milestone 3: clock ---------- */
.chip-clock { margin-left: auto; font-family: var(--font-display); font-weight: 900; font-variant-numeric: tabular-nums; background: var(--panel-soft); border-radius: 8px; padding: 2px 6px; font-size: var(--fs-s); }
.chip-clock.low { background: var(--danger); color: #fff; animation: breathe-btn 1s ease-in-out infinite; }
.board-wrap { position: relative; }
.countdown { position: absolute; top: 8%; right: 8%; font-family: var(--font-display); font-weight: 900; font-size: clamp(3rem, 10vw, 6rem); color: var(--accent); text-shadow: 0 4px 0 #fff, 0 8px 24px rgba(0,0,0,0.2); pointer-events: none; animation: count-pop 900ms ease-out forwards; }
@keyframes count-pop { 0% { transform: scale(1.6); opacity: 0; } 20% { transform: scale(1); opacity: 1; } 100% { transform: scale(0.9); opacity: 0; } }
.reduce-motion .countdown { animation: none; }

/* ---------- Milestone 4: stories ---------- */
.story-list { display: grid; gap: 8px; }
.story-card { display: flex; align-items: center; gap: 12px; text-align: left; background: var(--panel); border: 2px solid var(--line); border-radius: var(--r-m); padding: 10px 12px; font: inherit; cursor: pointer; }
.story-card strong { font-family: var(--font-display); display: block; }
.story-card small { color: var(--accent); font-weight: 800; font-size: 0.75rem; }
.story-card.read small { color: var(--ink-soft); }
.story-card.locked { opacity: 0.6; }
.story-card.locked small { color: var(--ink-soft); }
.story-num { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-content: center; font-family: var(--font-display); font-weight: 900; flex: none; }
.vn { display: grid; grid-template-rows: auto 1fr auto; justify-items: center; padding: 16px; cursor: pointer; user-select: none; }
.vn-title { justify-self: start; background: color-mix(in srgb, var(--panel) 90%, transparent); border-radius: var(--r-m); padding: 6px 14px; box-shadow: var(--shadow-s); display: flex; flex-direction: column; }
.vn-title small { color: var(--accent); font-weight: 800; font-size: 0.72rem; }
.vn-title strong { font-family: var(--font-display); }
.vn-stage { display: flex; align-items: flex-end; justify-content: center; min-height: 0; width: 100%; }
.vn-stage .charview.stage { width: min(90vw, 56dvh, 460px); }
.vn-box { position: relative; width: min(100%, 860px); min-height: 8.5em; background: color-mix(in srgb, var(--panel) 95%, transparent); border: 3px solid color-mix(in srgb, var(--accent) 35%, #fff); border-radius: var(--r-l); padding: 22px 26px 18px; box-shadow: var(--shadow-l); margin-top: -40px; z-index: 2; }
.vn-name { position: absolute; top: -16px; left: 22px; background: var(--accent); color: #fff; font-family: var(--font-display); font-weight: 900; padding: 4px 16px; border-radius: var(--r-pill); }
.vn-text { font-size: var(--fs-l); line-height: 1.5; font-weight: 600; }
.vn-text.narration { font-style: italic; color: var(--ink-soft); }
.vn-more { position: absolute; right: 18px; bottom: 8px; color: var(--accent); animation: breathe-btn 1.2s ease-in-out infinite; }
.vn-controls { position: absolute; top: 16px; right: 16px; display: flex; gap: 6px; }
.vn-btn { border: 2px solid var(--line); background: var(--panel); border-radius: var(--r-pill); padding: 6px 14px; font: inherit; font-weight: 800; cursor: pointer; box-shadow: var(--shadow-s); }
.vn-btn[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: transparent; }
@media (max-width: 600px) { .vn-text { font-size: var(--fs-m); } .vn-box { padding: 20px 16px 16px; } }

/* ---------- Milestone 4: lessons & practice ---------- */
.lesson-head { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 800; flex-wrap: wrap; }
.lesson-panel { padding: 12px 14px; }
.lesson-say { margin: 0 0 8px; font-weight: 700; }
.lesson-task strong { display: block; margin-bottom: 6px; font-family: var(--font-display); }
.practice-filters { display: grid; gap: 6px; }
.rank-select { font: inherit; font-weight: 700; padding: 8px 10px; border-radius: var(--r-m); border: 2px solid var(--line); background: var(--panel); }
.practice-meta { font-size: var(--fs-s); color: var(--ink-soft); font-weight: 700; text-align: center; }
.practice .segmented .seg, .practice .seg { font-size: 0.78rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lesson-panel:not(:has(.lesson-task > *)) { display: none; }
.mode-block { border-color: var(--accent); }
.segmented { flex-wrap: wrap; }
.board-canvas:focus { outline: none; }
.board-canvas:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; }

/* ---------- Milestone 4: loading & credits ---------- */
.boot.loading { gap: 10px; background: radial-gradient(circle at 50% 40%, #ffe6ee, var(--bg) 70%); }
.boot .tip { max-width: 34ch; margin: 0 auto; font-family: var(--font-body); font-weight: 600; color: var(--ink-soft); }
.loader { position: relative; width: 64px; height: 64px; margin: 0 auto; animation: spin 1.6s linear infinite; }
.loader i { position: absolute; width: 28px; height: 28px; border-radius: 50%; top: 18px; }
.loader i:first-child { left: 0; background: radial-gradient(circle at 35% 30%, #6a6470, #17141a 70%); }
.loader i:last-child { right: 0; background: radial-gradient(circle at 35% 30%, #fff, #d9d1c4 80%); box-shadow: inset 0 0 0 1px rgba(140,125,110,0.4); }
@keyframes spin { to { transform: rotate(360deg); } }
.credits-body h2 { font-size: var(--fs-l); margin: 14px 0 6px; }
.credits-body h3 { font-size: var(--fs-m); margin: 12px 0 4px; }
.credits-body p, .credits-body li { font-size: var(--fs-s); }
.table-wrap { overflow-x: auto; }
.credits-table { font-size: 0.78rem; }
.credits-table td, .credits-table th { text-align: left !important; vertical-align: top; }
.credits-body a { color: var(--accent); word-break: break-all; }
