:root {
  --teal: #2f9e7f;
  --teal-d: #1f7a61;
  --ink: #1f2d3a;
  --muted: #6a7a88;
  --gold: #ffc83d;
  --red: #ff5a4f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #79b867;
  font-family: Nunito, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  touch-action: none; overscroll-behavior: none;
}
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: none; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 0 calc(10px + env(safe-area-inset-left));
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start;
  pointer-events: none;
}
.stats { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.chip {
  display: flex; align-items: center; gap: 7px;
  background: rgba(255,255,255,.95); border-radius: 999px;
  padding: 4px 12px 4px 5px; font-weight: 900; font-size: 17px;
  box-shadow: 0 3px 0 rgba(0,0,0,.14);
}
.coin {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 35%, #fff4b8 0 16%, #ffcf45 20% 58%, #e3a000 62%);
  box-shadow: inset 0 0 0 2px #cf8d00;
}
.lvl {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: var(--teal); color: #fff; font-size: 13px;
  display: grid; place-items: center;
}
.xpbar { width: 72px; height: 9px; border-radius: 5px; background: #dde6ea; overflow: hidden; }
.xpbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #6fe0b6, var(--teal)); transition: width .3s; }
.bump { animation: bump .28s; }
@keyframes bump { 50% { transform: scale(1.16); } }

#quest {
  justify-self: center; width: 100%; max-width: 440px;
  background: rgba(255,255,255,.96); border-radius: 16px;
  padding: 8px 12px 8px 10px; box-shadow: 0 4px 0 rgba(0,0,0,.14);
  display: flex; gap: 10px; align-items: center;
  transition: transform .2s;
}
#quest.done { animation: qdone .6s; }
@keyframes qdone { 30% { transform: scale(1.06); background: #d8ffe9; } }
.q-ico { font-size: 22px; }
.q-body { flex: 1; min-width: 0; }
.q-text { font-weight: 800; font-size: 14px; line-height: 1.2; }
.q-bar { height: 7px; background: #e3ebee; border-radius: 4px; margin-top: 5px; overflow: hidden; }
.q-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffd65c, #ffaa2b); transition: width .3s; }
.q-count { font-weight: 900; font-size: 14px; color: var(--muted); white-space: nowrap; }

.btns { display: flex; gap: 8px; pointer-events: auto; }
.rbtn {
  width: 46px; height: 46px; border-radius: 50%; border: none; cursor: pointer;
  background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.16);
  font-size: 22px; position: relative; font-family: inherit; color: var(--ink);
}
.rbtn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.16); }
.badge {
  position: absolute; top: -5px; right: -5px; min-width: 21px; height: 21px; padding: 0 5px;
  background: var(--red); color: #fff; font-size: 12px; font-weight: 900;
  border-radius: 11px; display: grid; place-items: center; border: 2px solid #fff;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { transform: scale(1.18); } }
.hidden { display: none !important; }

#chapTag {
  grid-column: 1 / -1; justify-self: start;
  font-weight: 800; font-size: 12px; color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.45);
}

@media (max-width: 680px) {
  #hud { grid-template-columns: 1fr auto; }
  #quest { grid-column: 1 / -1; grid-row: 2; max-width: none; }
  #chapTag { grid-row: 3; font-size: 13px; }
  .chip { font-size: 19px; }
  .q-text { font-size: 15.5px; }
  .q-count { font-size: 15px; }
  .rbtn { width: 50px; height: 50px; font-size: 24px; }
}

/* ---------- Toasts ---------- */
#toasts {
  position: fixed; left: 0; right: 0; top: 34%; z-index: 8;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.toast {
  background: rgba(31,45,58,.92); color: #fff; font-weight: 800; font-size: 16px;
  padding: 10px 18px; border-radius: 14px; box-shadow: 0 6px 18px rgba(0,0,0,.25);
  animation: tin .3s ease-out; transition: opacity .4s, transform .4s; text-align: center; max-width: 90vw;
}
.toast.gold { background: linear-gradient(180deg, #ffd65c, #f5a623); color: #3b2500; }
.toast.green { background: linear-gradient(180deg, #4fd1a1, #2f9e7f); }
.toast.out { opacity: 0; transform: translateY(-14px); }
@keyframes tin { from { transform: scale(.7); opacity: 0; } }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(16,28,36,.55); display: flex; align-items: center; justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  pointer-events: auto;
}
.modal-box {
  background: #fff; border-radius: 22px; width: 100%; max-width: 520px; max-height: 100%;
  overflow: auto; padding: 20px; box-shadow: 0 12px 0 rgba(0,0,0,.18);
  animation: pop .25s ease-out; touch-action: pan-y;
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.modal.dialog { align-items: flex-end; background: rgba(16,28,36,.35); }
.modal-box.dialog { max-width: 640px; padding: 14px; cursor: pointer; }
.dlg { display: flex; gap: 14px; align-items: center; }
.portrait { width: 110px; height: 110px; border-radius: 18px; flex: none; background: #e9f4f1; }
.dlg-body { flex: 1; min-width: 0; }
.dlg-name { font-weight: 900; font-size: 16px; margin-bottom: 4px; }
.dlg-text { font-weight: 700; font-size: 16px; line-height: 1.35; min-height: 2.7em; }
.dlg-hint { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: right; font-weight: 800; }
@media (max-width: 480px) {
  .portrait { width: 78px; height: 78px; }
  .dlg-text { font-size: 15px; }
}

h2 { margin: 0 0 4px; font-size: 22px; font-weight: 900; }
.sub { color: var(--muted); font-weight: 700; margin: 0 0 14px; }
.btn {
  display: block; width: 100%; border: none; border-radius: 14px; cursor: pointer;
  background: var(--teal); color: #fff; font-family: inherit; font-weight: 900; font-size: 17px;
  padding: 13px; box-shadow: 0 4px 0 var(--teal-d); margin-top: 10px;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--teal-d); }
.btn.gray { background: #e7edf0; color: var(--ink); box-shadow: 0 4px 0 #c5d0d6; }
.btn.red { background: #f0625a; box-shadow: 0 4px 0 #c2433c; }
.btn:disabled { opacity: .45; cursor: default; }

.head-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.x { border: none; background: #eef2f4; width: 38px; height: 38px; border-radius: 50%; font-size: 18px; cursor: pointer; font-family: inherit; }
.tabs { display: flex; gap: 6px; margin: 12px 0; }
.tab { flex: 1; border: none; border-radius: 12px; padding: 9px; font-weight: 900; font-family: inherit; font-size: 15px; background: #eef2f4; color: var(--muted); cursor: pointer; }
.tab.on { background: var(--teal); color: #fff; }
.sp-line { font-weight: 800; background: #fff6da; border-radius: 12px; padding: 8px 12px; }
.skill { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid #eef2f4; }
.skill:last-child { border-bottom: none; }
.skill .ic { font-size: 28px; width: 40px; text-align: center; }
.skill .info { flex: 1; min-width: 0; }
.skill .nm { font-weight: 900; }
.skill .ds { font-size: 13px; color: var(--muted); font-weight: 700; }
.pips { display: flex; gap: 3px; margin-top: 5px; flex-wrap: wrap; }
.pips i { width: 12px; height: 7px; border-radius: 3px; background: #e1e8eb; }
.pips i.on { background: var(--teal); }
.plus {
  border: none; background: var(--gold); color: #3b2500; font-weight: 900; font-size: 20px;
  width: 46px; height: 46px; border-radius: 14px; cursor: pointer; box-shadow: 0 3px 0 #d39a16; font-family: inherit;
}
.plus:disabled { background: #e7edf0; color: #a6b2ba; box-shadow: 0 3px 0 #c5d0d6; cursor: default; }
.skins { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.skin { border: 3px solid #eef2f4; border-radius: 16px; padding: 8px; text-align: center; cursor: pointer; background: #fafcfc; }
.skin.on { border-color: var(--teal); background: #eaf8f3; }
.skin.locked { opacity: .5; cursor: default; }
.skin canvas { width: 100%; max-width: 120px; aspect-ratio: 1; }
.skin .nm { font-weight: 900; font-size: 14px; }
.skin .rq { font-size: 12px; color: var(--muted); font-weight: 700; }
.help { padding-left: 20px; font-weight: 700; line-height: 1.45; }
.help li { margin-bottom: 6px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.stat-grid div { background: #f2f7f6; border-radius: 12px; padding: 10px; font-weight: 800; }
.stat-grid b { display: block; font-size: 22px; color: var(--teal); }
.big-emoji { font-size: 54px; text-align: center; }
.center { text-align: center; }
