:root {
  --ink: #4a2a5a;
  --paper: #fff8ee;
  --accent: #ff8a5a;
  --good: #5ac86a;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  font-family: ui-rounded, 'SF Pro Rounded', 'Nunito', 'Varela Round', system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2a1a30;
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

canvas#cv, #touch {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
canvas#cv { display: block; }

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

/* ---------- Joystick ---------- */
#joy {
  position: fixed;
  left: 0;
  top: 0;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  border: 3px solid rgba(255, 255, 255, 0.5);
  display: none;
  pointer-events: none;
  z-index: 5;
}
#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 3px 0 rgba(74, 42, 90, 0.3);
}

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: calc(8px + var(--safe-t));
  left: calc(8px + var(--safe-l));
  right: calc(8px + var(--safe-r));
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
  z-index: 10;
}
.card {
  background: rgba(255, 248, 238, 0.94);
  border-radius: 16px;
  box-shadow: 0 3px 0 rgba(74, 42, 90, 0.25);
}
.stat {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 8px;
  min-width: 170px;
  flex: 0 1 240px;
}
.lv {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  background: var(--accent);
  color: #fff;
  border-radius: 12px;
  padding: 5px 7px;
  min-width: 38px;
}
.lv b { font-size: 18px; }
.bars { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.bar {
  position: relative;
  height: 16px;
  border-radius: 8px;
  background: #e8d8e0;
  overflow: hidden;
}
.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  border-radius: 8px;
  transition: width 0.2s;
}
.bar.hp i { background: linear-gradient(#8af09a, #4ac85a); }
.bar.hp.low i { background: linear-gradient(#ff9a9a, #ff5a6a); animation: pulse 0.6s infinite alternate; }
.bar.xp { height: 7px; }
.bar.xp i { background: linear-gradient(#ffe07a, #ffb03a); }
.bar span {
  position: absolute;
  inset: 0;
  font-size: 11px;
  font-weight: 800;
  line-height: 16px;
  text-align: center;
  color: var(--ink);
}
@keyframes pulse { to { opacity: 0.6; } }
.zone {
  padding: 8px 12px;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: auto;
}
.round {
  pointer-events: auto;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--paper);
  font-size: 26px;
  box-shadow: 0 4px 0 rgba(74, 42, 90, 0.3);
  flex: none;
}
.round:active, .round.down { transform: translateY(3px); box-shadow: 0 1px 0 rgba(74, 42, 90, 0.3); }
@media (max-width: 440px) {
  #hud { flex-wrap: wrap; }
  .zone { order: 3; flex-basis: auto; font-size: 12px; padding: 5px 10px; margin-left: 0; }
  .stat { flex: 1 1 auto; }
}

/* ---------- Zone banner ---------- */
#banner {
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -50%) scale(0.8);
  text-align: center;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 12;
  text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(74, 42, 90, 0.6);
  transition: opacity 0.4s, transform 0.4s;
  white-space: nowrap;
}
#banner b { display: block; font-size: 34px; font-weight: 900; }
#banner small { font-size: 15px; font-weight: 800; }
#banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* ---------- Controls ---------- */
.ctl { position: fixed; inset: 0; pointer-events: none; z-index: 8; }
.ctl button { pointer-events: auto; }
.act {
  position: absolute;
  right: calc(22px + var(--safe-r));
  bottom: calc(30px + var(--safe-b));
  min-width: 96px;
  height: 96px;
  border-radius: 48px;
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 6px 0 #c85a3a;
  animation: bob 1s infinite ease-in-out;
}
.act:active, .act.down { transform: translateY(5px); box-shadow: 0 1px 0 #c85a3a; animation: none; }
@keyframes bob { 50% { transform: translateY(-3px); } }

.btn {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 248, 238, 0.92);
  box-shadow: 0 5px 0 rgba(74, 42, 90, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  line-height: 1;
}
.btn:active, .btn.down { transform: translateY(4px); box-shadow: 0 1px 0 rgba(74, 42, 90, 0.35); }
.btn small { font-size: 10px; font-weight: 800; margin-top: 2px; }
.btn .cd {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(rgba(74, 42, 90, 0.55) calc(var(--p, 0) * 360deg), transparent 0);
  pointer-events: none;
}
.btn.lg {
  width: 92px; height: 92px; font-size: 40px;
  right: calc(18px + var(--safe-r)); bottom: calc(24px + var(--safe-b));
  background: #ff9a6a;
  box-shadow: 0 6px 0 #c85a3a;
}
.btn.lg:active, .btn.lg.down { box-shadow: 0 1px 0 #c85a3a; }
.btn.md { width: 64px; height: 64px; font-size: 24px; }
#btn-skill { right: calc(34px + var(--safe-r)); bottom: calc(130px + var(--safe-b)); background: #c8b0ff; }
#btn-dodge { right: calc(122px + var(--safe-r)); bottom: calc(18px + var(--safe-b)); background: #b0e8ff; }
.btn.sm { width: 52px; height: 52px; font-size: 22px; right: calc(118px + var(--safe-r)); bottom: calc(100px + var(--safe-b)); overflow: visible; }
.badge {
  position: absolute;
  right: -4px;
  top: -4px;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  line-height: 22px;
  text-align: center;
}
.pill {
  position: absolute;
  right: calc(10px + var(--safe-r));
  top: calc(70px + var(--safe-t));
  padding: 8px 14px;
  border-radius: 20px;
  background: rgba(255, 248, 238, 0.85);
  font-weight: 800;
  font-size: 14px;
  box-shadow: 0 3px 0 rgba(74, 42, 90, 0.3);
}
.pill:active, .pill.down { transform: translateY(2px); box-shadow: none; }
@media (max-width: 440px) {
  .pill { top: calc(100px + var(--safe-t)); }
}

/* ---------- Modal / sheets ---------- */
#modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(42, 26, 48, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(12px + var(--safe-t)) calc(12px + var(--safe-r)) calc(12px + var(--safe-b)) calc(12px + var(--safe-l));
  touch-action: pan-y;
  animation: fade 0.18s;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  background: var(--paper);
  border-radius: 24px;
  width: min(560px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 0 rgba(74, 42, 90, 0.35);
  animation: pop 0.22s cubic-bezier(0.3, 1.5, 0.5, 1);
  overflow: hidden;
}
@keyframes pop { from { transform: scale(0.85); } }
.sheet header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 0;
}
.sheet h2 { margin: 0; font-size: 22px; font-weight: 900; flex: 1; }
.x {
  width: 40px; height: 40px; border-radius: 50%;
  background: #f0e0e8; font-size: 20px; font-weight: 900; flex: none;
}
.tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs button {
  flex: 1 0 auto;
  padding: 8px 10px;
  border-radius: 14px;
  background: #f0e4ea;
  font-weight: 800;
  font-size: 14px;
}
.tabs button.on { background: var(--accent); color: #fff; }
.sheet header, .statline, .tabs { flex: none; }
.body {
  min-height: 0;
  padding: 0 12px 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  flex: 1;
}
.statline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
  margin: 0 12px 4px;
}
.statline span { background: #fff; border-radius: 10px; padding: 4px 8px; }
h3 { margin: 14px 0 6px; font-size: 15px; font-weight: 900; opacity: 0.75; }
.note {
  background: #fff1c8;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  margin: 4px 0 8px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.mat {
  background: #fff;
  border-radius: 14px;
  padding: 8px;
  text-align: center;
}
.mat .ico { font-size: 26px; }
.mat b { display: block; font-size: 18px; }
.mat small { display: block; font-size: 10px; font-weight: 700; opacity: 0.6; line-height: 1.2; }
.mat.empty { opacity: 0.4; }
.row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 16px;
  padding: 10px;
  margin-bottom: 8px;
}
.row.on { outline: 3px solid var(--good); }
.row .ico { font-size: 30px; width: 40px; text-align: center; flex: none; }
.row .info { flex: 1; min-width: 0; }
.row .name { font-weight: 900; font-size: 15px; }
.row .desc { font-size: 12px; font-weight: 700; opacity: 0.65; }
.row .stats { font-size: 12px; font-weight: 800; color: #c85a3a; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chip {
  font-size: 12px;
  font-weight: 800;
  background: #e8f8e8;
  border-radius: 10px;
  padding: 2px 7px;
  white-space: nowrap;
}
.chip.miss { background: #ffe0e4; color: #c83a4a; }
.go {
  flex: none;
  padding: 10px 14px;
  border-radius: 14px;
  background: var(--good);
  color: #fff;
  font-weight: 900;
  font-size: 14px;
  box-shadow: 0 3px 0 #3a9a4a;
}
.go:disabled { background: #d8ccd4; box-shadow: none; color: #fff; cursor: default; }
.go.alt { background: var(--accent); box-shadow: 0 3px 0 #c85a3a; }
.go:not(:disabled):active { transform: translateY(2px); box-shadow: none; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.slot { background: #fff; border-radius: 14px; padding: 8px; text-align: center; font-size: 12px; font-weight: 800; }
.slot .ico { font-size: 28px; display: block; }

/* Result & message dialogs */
.result { padding: 18px 16px 16px; text-align: center; }
.result .big { font-size: 34px; font-weight: 900; margin: 0 0 4px; }
.result .sub { font-weight: 800; font-size: 16px; margin-bottom: 10px; }
.result .lvup {
  display: inline-block;
  background: linear-gradient(#ffe07a, #ffb03a);
  color: var(--ink);
  font-weight: 900;
  border-radius: 14px;
  padding: 6px 14px;
  margin: 4px 0 10px;
  animation: pop 0.4s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.result .chips { justify-content: center; margin: 6px 0 14px; }
.result .chip { font-size: 15px; padding: 5px 10px; background: #fff; }
.result p { font-weight: 700; font-size: 15px; line-height: 1.4; }
.result .go { padding: 12px 28px; font-size: 17px; }
.result .btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  left: 50%;
  top: calc(84px + var(--safe-t));
  transform: translateX(-50%) translateY(-10px);
  background: rgba(74, 42, 90, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 16px;
  font-weight: 800;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 30;
  max-width: calc(100% - 24px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 440px) { #toast { top: calc(120px + var(--safe-t)); } }

/* ---------- Title ---------- */
#title {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  background: radial-gradient(circle at 50% 35%, rgba(255, 248, 220, 0.25), rgba(42, 26, 48, 0.45));
  padding: 20px;
  text-align: center;
}
.logo h1 {
  margin: 0;
  font-size: clamp(48px, 14vw, 84px);
  line-height: 0.9;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 5px 0 #4a8a3a, 0 10px 0 var(--ink), 0 0 30px rgba(0, 0, 0, 0.3);
  letter-spacing: 1px;
}
.logo p { margin: 16px 0 0; color: #fff; font-weight: 800; text-shadow: 0 2px 0 var(--ink); }
.sprout { font-size: 54px; animation: bob 1.4s infinite ease-in-out; }
.title-btns { display: flex; flex-direction: column; gap: 12px; width: min(280px, 80vw); }
.big-btn {
  padding: 16px;
  border-radius: 20px;
  background: var(--accent);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  box-shadow: 0 6px 0 #c85a3a;
}
.big-btn.alt { background: var(--paper); color: var(--ink); box-shadow: 0 6px 0 rgba(74, 42, 90, 0.4); }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #c85a3a; }
.hint { color: #fff; font-size: 13px; font-weight: 700; opacity: 0.9; text-shadow: 0 1px 0 var(--ink); line-height: 1.5; }
#modal:not([hidden]) ~ #toast { top: calc(10px + var(--safe-t)); }
img.icon { width: 44px; height: 44px; object-fit: contain; display: inline-block; vertical-align: middle; filter: drop-shadow(0 2px 0 rgba(74, 42, 90, 0.18)); }
img.icon.sm { width: 20px; height: 20px; vertical-align: -5px; filter: none; }
.result .chip img.icon.sm { width: 26px; height: 26px; vertical-align: -7px; }
.mat .ico { height: 42px; display: flex; align-items: center; justify-content: center; }
.slot .ico img.icon { width: 48px; height: 48px; }

/* ================= Story & menu redesign ================= */
.quest-pill {
  position: fixed;
  left: calc(8px + var(--safe-l));
  top: calc(80px + var(--safe-t));
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(380px, calc(100% - 16px));
  padding: 7px 12px 7px 9px;
  border-radius: 16px;
  background: rgba(74, 42, 90, 0.9);
  color: #fff;
  text-align: left;
  box-shadow: 0 3px 0 rgba(42, 20, 50, 0.35);
}
.quest-pill .qi { font-size: 20px; }
.quest-pill .qt { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.quest-pill .qt b { font-size: 13px; }
.quest-pill .qt small { font-size: 11px; font-weight: 700; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quest-pill .qc { background: var(--accent); border-radius: 10px; padding: 2px 8px; font-weight: 900; font-size: 13px; flex: none; }
.quest-pill.bump { animation: pop 0.35s cubic-bezier(0.3, 1.8, 0.5, 1); }
@media (max-width: 440px) {
  .zone { display: none; }
  .quest-pill { top: calc(76px + var(--safe-t)); }
  #toast { top: calc(132px + var(--safe-t)); }
  .pill { top: calc(76px + var(--safe-t)); }
}

.sheet.menu { height: 100%; max-height: 860px; }
@media (max-width: 600px) {
  #modal { padding: calc(6px + var(--safe-t)) 6px 0; align-items: flex-end; }
  .sheet { border-radius: 24px 24px 0 0; max-height: 100%; }
  .sheet:not(.menu) { border-radius: 24px; margin-bottom: calc(12px + var(--safe-b)); }
  .sheet.menu .tabbar { padding-bottom: calc(10px + var(--safe-b)); }
}
.mhead { display: flex; gap: 10px; align-items: center; padding: 12px 12px 6px; }
.portrait {
  width: 58px; height: 58px; border-radius: 18px; flex: none;
  background: linear-gradient(#ffffff, #f3e6ee);
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  box-shadow: inset 0 -3px 0 rgba(74, 42, 90, 0.12);
}
.portrait img.icon { width: 54px; height: 54px; }
.who { flex: 1; min-width: 0; }
.who .name { font-weight: 900; font-size: 19px; }
.lvl { background: var(--accent); color: #fff; border-radius: 10px; padding: 1px 8px; font-size: 13px; margin-left: 4px; vertical-align: 2px; }
.mini { position: relative; height: 14px; border-radius: 7px; background: #eadbe4; overflow: hidden; margin-top: 4px; }
.mini i { position: absolute; inset: 0 auto 0 0; border-radius: 7px; }
.mini.hp i { background: linear-gradient(#8af09a, #4ac85a); }
.mini.xp { height: 6px; }
.mini.xp i { background: linear-gradient(#ffe07a, #ffb03a); }
.mini span { position: absolute; inset: 0; font-size: 10px; font-weight: 800; text-align: center; line-height: 14px; }
.statrow { display: flex; gap: 6px; padding: 2px 12px 8px; flex-wrap: wrap; flex: none; }
.statrow span { background: #fff; border-radius: 12px; padding: 5px 10px; font-size: 13px; font-weight: 700; }
.sheet.menu .body { padding: 4px 12px 16px; background: #fbf1e8; border-radius: 18px 18px 0 0; }
.tabbar {
  flex: none; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  padding: 6px 8px 10px; background: #fff; border-top: 2px solid #f0e4ea;
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; min-height: 54px;
  border-radius: 16px; background: transparent; font-size: 11px; font-weight: 800; color: #8a7a90;
}
.tabbar button span { font-size: 23px; line-height: 1; transition: transform 0.15s; }
.tabbar button.on { background: #ffe6da; color: var(--ink); }
.tabbar button.on span { transform: translateY(-2px) scale(1.12); }
.seg { display: flex; background: #f0e4ea; border-radius: 14px; padding: 4px; gap: 4px; margin: 8px 0 10px; }
.seg button { flex: 1; padding: 9px 4px; border-radius: 11px; background: transparent; font-weight: 800; font-size: 13px; }
.seg button.on { background: #fff; box-shadow: 0 2px 0 rgba(74, 42, 90, 0.15); }
.mcard { background: #fff; border-radius: 18px; padding: 12px; margin-bottom: 10px; box-shadow: 0 2px 0 rgba(74, 42, 90, 0.08); }
.mcard.row { display: flex; align-items: center; gap: 10px; }
.mcard .ico, .rcp .ico { width: 56px; flex: none; text-align: center; font-size: 30px; }
.mcard .name { font-weight: 900; font-size: 15px; }
.mcard .desc { font-size: 12px; font-weight: 700; opacity: 0.7; margin-top: 2px; }
.mcard .stats { font-size: 12px; font-weight: 800; color: #c85a3a; }
.mcard .info { flex: 1; min-width: 0; }
.rcp { display: flex; align-items: center; gap: 10px; }
.rcp.locked { opacity: 0.62; }
.rcp.owned { background: #f4fff4; }
img.icon.lg { width: 56px; height: 56px; }
img.icon.xl { width: 72px; height: 72px; }
img.icon.xxl { width: 116px; height: 116px; }
.stars { font-size: 11px; color: #d8901a; font-weight: 900; margin-left: 4px; white-space: nowrap; }
.tag { font-size: 12px; font-weight: 900; padding: 7px 10px; border-radius: 12px; background: #e8f8e8; white-space: nowrap; flex: none; }
.tag.lock { background: #f0e4ea; }
.chips .chip, .qrew .chip { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; padding: 3px 8px 3px 4px; border-radius: 12px; }
.chip.ok { background: #e8f8e8; }
.chip b { font-weight: 900; }
.go.sm { padding: 8px 14px; flex: none; }
.go.wide, .wide { width: 100%; margin-top: 10px; padding: 13px; font-size: 15px; }
.go.ghost { background: #fff; color: #3a9a4a; box-shadow: inset 0 0 0 2px var(--good); }
.sub { font-weight: 700; font-size: 13px; opacity: 0.7; margin: 0 0 8px; }
h3 small { font-size: 11px; opacity: 0.7; font-weight: 700; }

.qcard { background: linear-gradient(160deg, #fff7e0, #ffe8f0); border-radius: 22px; padding: 14px; margin: 8px 0 6px; box-shadow: 0 3px 0 rgba(74, 42, 90, 0.12); }
.qtop { display: flex; gap: 12px; align-items: center; }
.qart { width: 78px; height: 78px; border-radius: 20px; background: #fff; display: flex; align-items: center; justify-content: center; flex: none; font-size: 40px; }
.qchap { font-size: 12px; font-weight: 900; color: #c85a3a; text-transform: uppercase; letter-spacing: 0.5px; }
.qtitle { font-size: 22px; font-weight: 900; line-height: 1.1; }
.qtext { font-size: 14px; font-weight: 600; line-height: 1.45; margin: 10px 0; opacity: 0.85; }
.qgoal { display: flex; justify-content: space-between; font-weight: 800; font-size: 14px; }
.pbar { height: 12px; border-radius: 6px; background: #fff; overflow: hidden; margin-top: 6px; }
.pbar i { display: block; height: 100%; background: linear-gradient(90deg, #ffb03a, #ff7a5a); border-radius: 6px; }
.qrew { margin-top: 10px; font-size: 13px; font-weight: 800; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.zrow { display: flex; align-items: center; gap: 10px; background: #fff; border-radius: 16px; padding: 10px; margin-bottom: 8px; }
.zrow.locked { background: #f6eef2; }
.zrow .info { flex: 1; min-width: 0; }
.zrow .name { font-weight: 900; }
.zrow .desc { font-size: 12px; font-weight: 700; opacity: 0.75; }
.zart { width: 50px; height: 50px; flex: none; display: flex; align-items: center; justify-content: center; }
.zart img.icon { width: 50px; height: 50px; }
.emo { font-size: 30px; }
.chapters { list-style: none; padding: 0; margin: 0 0 8px; }
.chapters li { display: flex; gap: 8px; align-items: center; padding: 9px 10px; border-radius: 12px; font-weight: 800; font-size: 14px; }
.chapters li.now { background: #ffe6da; }
.chapters li.done { opacity: 0.6; }
.chapters li.later { opacity: 0.45; }
.chapters .mk { width: 22px; text-align: center; }
.chapters .ch { font-size: 11px; color: #c85a3a; width: 78px; flex: none; }
.slot small { display: block; opacity: 0.6; font-size: 10px; }
.slot span { display: block; }
.ggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.gcard {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 8px 10px;
  border-radius: 18px; background: #fff; text-align: center; box-shadow: 0 2px 0 rgba(74, 42, 90, 0.08);
}
.gcard.on { outline: 3px solid var(--good); background: #f4fff4; }
.gcard .name { font-weight: 900; font-size: 14px; }
.gcard .stats { font-size: 12px; font-weight: 800; color: #c85a3a; }
.gcard:disabled { cursor: default; color: inherit; }
.gcard:not(:disabled):active { transform: scale(0.97); }
.badge-on { position: absolute; top: 6px; right: 6px; background: var(--good); color: #fff; font-size: 10px; font-weight: 900; padding: 2px 6px; border-radius: 8px; }
.mat span { display: block; font-size: 12px; font-weight: 800; }
.bcard .btop { display: flex; gap: 12px; align-items: center; }
.bcard .ico { width: 66px; }
.pips i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #eadbe4; margin-left: 3px; vertical-align: 1px; }
.pips i.on { background: var(--accent); }
.bcard .next { margin-top: 10px; border-top: 2px dashed #f0e4ea; padding-top: 10px; }
.flash { animation: flash 0.7s 3; }
@keyframes flash { 50% { box-shadow: 0 0 0 4px #ffb03a; } }

.speaker { display: flex; flex-direction: column; align-items: center; gap: 2px; font-weight: 900; }
.speaker.small { flex-direction: row; justify-content: center; gap: 6px; margin-top: 8px; }
.bubble {
  position: relative; background: #fff; border-radius: 18px; padding: 12px 14px; margin: 10px 4px;
  font-weight: 700; line-height: 1.45; text-align: left; box-shadow: 0 2px 0 rgba(74, 42, 90, 0.1);
}
.bubble::before { content: ''; position: absolute; top: -8px; left: 50%; margin-left: -8px; border: 8px solid transparent; border-top: 0; border-bottom-color: #fff; }
.result .hint { font-weight: 800; font-size: 14px; margin-bottom: 14px; color: #c85a3a; }
.big-art { margin: 0 auto 6px; width: auto; height: auto; background: none; }
.lvcmp { display: inline-block; font-weight: 900; padding: 6px 12px; border-radius: 12px; margin-bottom: 14px; }
.lvcmp.good { background: #e8f8e8; }
.lvcmp.bad { background: #ffe0e4; color: #c83a4a; }
.sheet.celebrate { background: radial-gradient(circle at 50% 0%, #fff3c0, var(--paper) 65%); }
.confetti { font-size: 22px; letter-spacing: 4px; animation: confetti 1s ease-out; overflow: hidden; white-space: nowrap; margin-bottom: 6px; }
@keyframes confetti { from { transform: translateY(-24px) scale(0.6); opacity: 0; } }
/* Short (landscape phone) screens: compact header and tab bar so the content gets the room. */
@media (max-height: 520px) {
  #modal { padding-top: calc(4px + var(--safe-t)); }
  .sheet.menu { max-height: 100%; width: min(720px, 100%); }
  .mhead { padding: 6px 10px 2px; }
  .portrait { width: 40px; height: 40px; border-radius: 12px; }
  .portrait img.icon { width: 38px; height: 38px; }
  .who .name { font-size: 15px; }
  .statrow { display: none; }
  .tabbar { padding: 4px 8px calc(4px + var(--safe-b)); }
  .tabbar button { min-height: 40px; flex-direction: row; justify-content: center; gap: 6px; font-size: 12px; }
  .tabbar button span { font-size: 18px; }
  .qcard .qart { width: 56px; height: 56px; }
  .qcard img.icon.xl { width: 52px; height: 52px; }
}

/* ================= Onboarding ================= */
.dock {
  position: fixed; left: calc(14px + var(--safe-l)); bottom: calc(22px + var(--safe-b)); z-index: 8;
  display: flex; gap: 10px; pointer-events: none; transition: opacity 0.4s;
}
.dock-btn {
  position: relative; pointer-events: auto; width: 66px; height: 66px; border-radius: 22px;
  background: var(--paper); box-shadow: 0 5px 0 rgba(74, 42, 90, 0.3);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; line-height: 1;
  animation: pop 0.35s cubic-bezier(0.3, 1.8, 0.5, 1);
}
.dock-btn span { font-size: 30px; }
.dock-btn small { font-size: 11px; font-weight: 900; }
.dock-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(74, 42, 90, 0.3); }
.dot { position: absolute; top: 2px; right: 2px; width: 14px; height: 14px; border-radius: 50%; background: #ff4a5a; border: 2px solid #fff; display: none; }
.dock-btn.has-dot .dot { display: block; animation: pulse 0.7s infinite alternate; }
.tabbar button { position: relative; }
.tabbar .dot.on { display: block; top: 4px; right: 18%; }
@media (max-width: 440px) { #hud { flex-wrap: nowrap; } .stat { min-width: 0; } }

.unlock-card {
  position: fixed; left: 50%; top: calc(140px + var(--safe-t)); z-index: 32;
  width: min(360px, calc(100% - 24px)); display: flex; gap: 12px; align-items: center;
  padding: 12px 14px; border-radius: 20px; background: var(--paper); color: var(--ink);
  box-shadow: 0 6px 0 rgba(74, 42, 90, 0.3), 0 0 0 3px #ffd35a;
  transform: translate(-50%, -30px) scale(0.9); opacity: 0; transition: transform 0.35s cubic-bezier(0.3, 1.6, 0.5, 1), opacity 0.25s;
  pointer-events: none;
}
.unlock-card.show { transform: translate(-50%, 0) scale(1); opacity: 1; }
.unlock-card .u-ico { font-size: 38px; flex: none; animation: bob 1s infinite ease-in-out; }
.unlock-card .u-new { font-size: 11px; font-weight: 900; color: #c85a3a; text-transform: uppercase; letter-spacing: 0.5px; }
.unlock-card b { font-size: 17px; font-weight: 900; }
.unlock-card p { margin: 2px 0 0; font-size: 13px; font-weight: 700; line-height: 1.35; opacity: 0.85; }

.coach {
  position: fixed; z-index: 15; max-width: 230px; padding: 10px 14px; border-radius: 16px;
  background: #fff; color: var(--ink); font-weight: 900; font-size: 15px; line-height: 1.3;
  box-shadow: 0 4px 0 rgba(74, 42, 90, 0.3), 0 0 0 3px #ffd35a; pointer-events: none;
  animation: bob 1s infinite ease-in-out;
}
.coach.center { transform: translateX(-50%); }
.coach.above::after { content: ''; position: absolute; bottom: -9px; right: 34px; border: 9px solid transparent; border-bottom: 0; border-top-color: #fff; }
.coached { animation: coachpulse 0.9s infinite !important; }
@keyframes coachpulse { 50% { box-shadow: 0 0 0 10px rgba(255, 211, 90, 0.7), 0 5px 0 rgba(74, 42, 90, 0.35); } }

.drag-hint {
  position: fixed; left: 50%; bottom: calc(28% + var(--safe-b)); transform: translateX(-50%); z-index: 7;
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
  color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(74, 42, 90, 0.5); font-size: 16px;
}
.drag-hint .hand { font-size: 46px; animation: drag 1.6s infinite ease-in-out; }
@keyframes drag {
  0% { transform: translate(-40px, 0) scale(1); opacity: 0; }
  15% { opacity: 1; transform: translate(-40px, 0) scale(0.9); }
  70% { transform: translate(40px, -10px) scale(0.9); opacity: 1; }
  100% { transform: translate(40px, -10px) scale(1); opacity: 0; }
}

/* ================= Cutscenes ================= */
body::before, body::after {
  content: ''; position: fixed; left: 0; right: 0; height: 0; background: #1a1020; z-index: 19;
  transition: height 0.5s ease; pointer-events: none;
}
body::before { top: 0; }
body::after { bottom: 0; }
body.cinema::before, body.cinema::after { height: 9vh; }
body.cinema #hud, body.cinema #quest-pill, body.cinema .ctl, body.cinema #drag-hint, body.cinema #dock { opacity: 0; pointer-events: none; }
#hud, #quest-pill, .ctl { transition: opacity 0.4s; }
#modal.cine { background: transparent; align-items: flex-end; padding-bottom: calc(10vh + var(--safe-b)); }
.sheet.caption { width: min(520px, 100%); border-radius: 22px; background: rgba(255, 248, 238, 0.97); margin-bottom: 0; }
.sheet.caption .result { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.sheet.caption .speaker.small { justify-content: flex-start; margin: 0; }
.caption-text { font-weight: 700; font-size: 16px; line-height: 1.45; }
.caption-text.narrator { font-style: italic; text-align: center; padding: 6px 4px; }
.sheet.caption .btns { justify-content: flex-end; }
.sheet.caption .go { padding: 8px 18px; font-size: 16px; }

/* Menu dismissal lives at the bottom-left, exactly where the Bag button opened it. */
.tabbar .tab-close {
  min-width: 62px; margin-right: 4px; background: var(--ink); color: #fff; border-radius: 18px;
  box-shadow: 0 3px 0 rgba(42, 20, 50, 0.4);
}
.tabbar .tab-close span { font-size: 20px; font-weight: 900; }
.tabbar .tab-close:active { transform: translateY(3px); box-shadow: none; }
.grab { flex: none; width: 44px; height: 5px; border-radius: 3px; background: #e2d2dc; margin: 8px auto 0; }
.sheet.menu .mhead, .sheet.menu .grab { touch-action: none; }
.sheet.menu { transition: transform 0.15s; }

/* ================= Keyboard hints (desktop) ================= */
.key, .kbd-only { display: none; }
body.kbd .kbd-only { display: revert; }
body.kbd .touch-only { display: none; }
kbd, .key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 800; font-size: 11px; line-height: 1;
  color: var(--ink); background: #fff; border-radius: 6px; padding: 3px 5px; min-width: 18px; text-align: center;
  box-shadow: inset 0 -2px 0 rgba(74, 42, 90, 0.25), 0 0 0 1px rgba(74, 42, 90, 0.25);
}
body.kbd .key { display: inline-block; }
/* Round battle/dock buttons: the cap sits on the top-left rim. */
body.kbd .btn .key, body.kbd .dock-btn .key, body.kbd .act .key {
  position: absolute; top: -8px; left: -8px; font-size: 15px; padding: 5px 8px; border-radius: 8px; z-index: 2;
}
.btn, .dock-btn, .act { overflow: visible; }
.btn .cd { overflow: hidden; }
body.kbd .btn.lg .key { top: -2px; left: -2px; font-size: 16px; }
/* Inline caps on text buttons. */
body.kbd .go .key, body.kbd .pill .key, body.kbd .big-btn .key { margin-left: 8px; vertical-align: 1px; background: rgba(255, 255, 255, 0.9); }
body.kbd .big-btn .key { font-size: 13px; vertical-align: 3px; }
body.kbd .tabbar .key { position: absolute; top: 3px; left: 6px; font-size: 9px; padding: 2px 4px; opacity: 0.75; }
body.kbd .tabbar .tab-close .key { position: static; margin-top: 2px; opacity: 1; }
.drag-hint .keys { display: none; flex-direction: column; align-items: center; gap: 4px; }
body.kbd .drag-hint .keys { display: flex; }
.drag-hint .keys kbd { font-size: 18px; padding: 6px 10px; margin: 0 2px; animation: keytap 1.6s infinite; }
.drag-hint .keys span kbd:nth-child(2) { animation-delay: 0.4s; }
.drag-hint .keys span kbd:nth-child(3) { animation-delay: 0.8s; }
.drag-hint .keys span kbd:nth-child(1) { animation-delay: 1.2s; }
@keyframes keytap { 0%, 30%, 100% { transform: none; } 15% { transform: translateY(3px); box-shadow: inset 0 -1px 0 rgba(74, 42, 90, 0.25); } }
.u-key { margin-top: 6px !important; font-weight: 800 !important; }
