* { box-sizing: border-box; }
:root {
  --paper: #f4e8cc; --paper2: #ead8b0; --ink: #3d2c1e; --ink2: #6b5238; --gold: #c8902a; --red: #a8402e;
  --sage: #5f8a44; --blue: #4a6a8a; --plum: #7a4a8a;
  --parch: url(assets/parchment.webp);
}
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #2a2018; color: var(--ink);
  font-family: 'Baloo 2', 'Nunito', system-ui, 'Noto Sans', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#viewport { position: fixed; inset: 0; }
#stage { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; transform-origin: 0 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 1280px; height: 720px; touch-action: none; display: block; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* parchment surfaces */
.paper, #hud, #panel, .modal, #tut, .title-card, #bossbar {
  background-color: var(--paper);
  background-image: var(--parch), linear-gradient(180deg, #f7eed8, #ecdcb6);
  background-size: 256px 256px, 100% 100%;
}

/* ---------------------------------------------------------------- HUD */
#hud {
  position: absolute; left: 8px; right: 8px; top: 6px; height: 54px; display: flex; align-items: center; gap: 12px;
  padding: 0 10px; border: 2px solid var(--ink2); border-radius: 14px;
  box-shadow: 0 3px 0 rgba(61,44,30,.35), inset 0 0 18px rgba(140,100,50,.25);
}
.res { display: flex; align-items: baseline; gap: 6px; min-width: 150px; }
.res b { font-size: 26px; font-weight: 800; line-height: 1; }
.res.gold b { color: #8a5a10; }
.res.gems b { color: var(--plum); }
.res small { font-size: 15px; color: var(--ink2); font-weight: 700; }
.ico { display: inline-block; width: 30px; height: 30px; background-size: contain; background-repeat: no-repeat; background-position: center; align-self: center; flex: none; }
.ico-gold { background-image: url(assets/icon_gold.webp); }
.ico-gem { background-image: url(assets/icon_gem.webp); }
body.noart .ico-gold { background-image: radial-gradient(circle, #ffd35a 55%, #8a5a10 58%, transparent 64%); }
body.noart .ico-gem { background-image: radial-gradient(circle, #b080e0 50%, #5a2a7a 53%, transparent 60%); }
.wavebox { flex: 1; text-align: center; min-width: 0; }
.wave-title { font-size: 22px; font-weight: 800; line-height: 1.1; white-space: nowrap; }
.wave-title small { font-size: 15px; color: var(--ink2); font-weight: 700; }
.wave-title .boss { color: var(--red); }
.bar { height: 10px; border-radius: 6px; background: rgba(61,44,30,.18); border: 1.5px solid rgba(61,44,30,.5); overflow: hidden; margin: 2px auto 0; max-width: 360px; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #7aa050, #a8c870); transition: width .2s linear; }
.hud-btns { display: flex; gap: 6px; }
.hbtn {
  position: relative; height: 42px; min-width: 46px; padding: 0 10px; border-radius: 12px; cursor: pointer; font-size: 22px; font-weight: 800;
  background: #fbf3df; border: 2px solid var(--ink2); box-shadow: 0 3px 0 rgba(61,44,30,.4);
}
.hbtn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(61,44,30,.4); }
.hbtn.crown { display: flex; align-items: center; gap: 6px; font-size: 17px; color: var(--plum); }
.hbtn.crown .c-ico { font-size: 22px; }
.hbtn.crown.ready { background: linear-gradient(#f3dcff, #d9b8f0); animation: glow 1.4s ease-in-out infinite; }
.badge {
  position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px;
  background: var(--red); color: #fff; font-size: 14px; line-height: 22px; border: 2px solid #fff3d8;
}
@keyframes glow { 50% { filter: brightness(1.12); transform: scale(1.04); } }

#bossbar {
  position: absolute; left: 400px; right: 400px; top: 66px; padding: 4px 14px 8px; border: 2px solid var(--red);
  border-radius: 12px; text-align: center; box-shadow: 0 3px 0 rgba(61,44,30,.3);
}
.bb-name { font-weight: 800; font-size: 18px; color: var(--red); line-height: 1.2; }
.bb-name small { color: var(--ink2); font-size: 14px; }
#bossbar .bar { max-width: none; height: 12px; }
#bossbar .bar i { background: linear-gradient(90deg, #b03a2a, #e06a40); }

/* ---------------------------------------------------------------- hero skills */
#skills { position: absolute; left: 12px; top: 70px; display: flex; gap: 8px; }
.skill {
  position: relative; width: 62px; height: 62px; border-radius: 50%; cursor: pointer; padding: 0; overflow: hidden;
  border: 3px solid var(--ink2); background: #fbf3df center / 120% auto no-repeat; box-shadow: 0 3px 0 rgba(61,44,30,.45);
}
.skill .cd {
  position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(rgba(40,28,18,.65) calc(var(--p, 0) * 1turn), transparent 0);
}
.skill .k { position: absolute; left: 4px; bottom: 0; font-size: 13px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000; }
.skill .em { position: absolute; right: 2px; top: 0; font-size: 17px; }
.skill.ready { border-color: #e0b040; box-shadow: 0 0 0 3px rgba(255,220,120,.6), 0 3px 0 rgba(61,44,30,.45); animation: glow 1.6s ease-in-out infinite; }
.skill .t { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff; text-shadow: 0 1px 3px #000; }

/* ---------------------------------------------------------------- shop panel */
#panel {
  position: absolute; left: 0; right: 0; top: 520px; bottom: 0; padding: 6px 10px 8px;
  border-top: 3px solid var(--ink2); box-shadow: 0 -4px 14px rgba(40,26,14,.35);
}
.tabs { display: flex; align-items: center; gap: 6px; height: 36px; }
.tab {
  cursor: pointer; font-size: 18px; font-weight: 800; padding: 2px 14px; border-radius: 10px 10px 0 0; position: relative;
  background: rgba(61,44,30,.08); border: 2px solid rgba(61,44,30,.3); border-bottom: 0; color: var(--ink2);
}
.tab.on { background: #fff7e4; color: var(--ink); border-color: var(--ink2); }
.tab .dot { position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%; background: var(--red); border: 2px solid #fff3d8; }
.stats { flex: 1; text-align: right; font-size: 15px; color: var(--ink2); font-weight: 700; white-space: nowrap; overflow: hidden; }
.stats b { color: var(--ink); }
.buymode { display: flex; border: 2px solid var(--ink2); border-radius: 10px; overflow: hidden; }
.buymode button { cursor: pointer; border: 0; background: #fbf3df; font-weight: 800; font-size: 16px; padding: 2px 12px; }
.buymode button + button { border-left: 2px solid var(--ink2); }
.buymode button.on { background: var(--ink2); color: #fff3d8; }

.cards { display: flex; gap: 8px; height: 150px; margin-top: 4px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.card {
  flex: 0 0 132px; display: flex; flex-direction: column; border-radius: 12px; padding: 6px 7px; position: relative;
  background: rgba(255,250,236,.75); border: 2px solid rgba(61,44,30,.45); text-align: center;
}
.card { cursor: pointer; }
.card.locked { opacity: .55; }
/* phones: grow the hit area of small HUD buttons without changing their look */
@media (pointer: coarse) {
  .hbtn, .tab, .buymode button { position: relative; }
  .hbtn::after, .tab::after { content: ''; position: absolute; inset: -6px -4px; }
}
.card .top { display: flex; align-items: center; gap: 5px; }
.card .pic { width: 40px; height: 40px; flex: none; border-radius: 8px; font-size: 28px; line-height: 40px; background: center / contain no-repeat; }
.card .nm { font-size: 15px; font-weight: 800; line-height: 1.05; text-align: left; }
.card .lv { font-size: 13px; color: var(--ink2); font-weight: 700; text-align: left; }
.card .val { font-size: 14px; font-weight: 700; color: var(--ink); margin: 3px 0 2px; line-height: 1.15; min-height: 32px; }
.card .val em { font-style: normal; color: var(--sage); }
.card .buy {
  margin-top: auto; cursor: pointer; border-radius: 10px; border: 2px solid #5a3f14; padding: 1px 4px 2px;
  font-weight: 800; font-size: 16px; background: linear-gradient(#f2c860, #d49a2a); color: #3a2200; box-shadow: 0 3px 0 #7a5214;
  display: flex; align-items: center; justify-content: center; gap: 3px; white-space: nowrap;
}
.card .buy small { font-size: 12px; font-weight: 800; opacity: .8; }
.card .buy .ico { width: 18px; height: 18px; }
.card .buy:active { transform: translateY(2px); box-shadow: 0 1px 0 #7a5214; }
.card .buy.no { background: #d9ccb0; border-color: #9a8a6a; color: #7a6a50; box-shadow: 0 3px 0 #9a8a6a; }
.card .buy.max { background: #cfe0c0; border-color: var(--sage); color: #2e4a20; box-shadow: none; }
.card.can { border-color: #b08020; box-shadow: 0 0 0 2px rgba(240,190,80,.45); }

/* ---------------------------------------------------------------- tutorial + toast */
#tut {
  position: absolute; z-index: 15; max-width: 380px; padding: 10px 14px 10px; border: 2.5px solid var(--ink); border-radius: 14px;
  font-size: 18px; font-weight: 700; line-height: 1.3; box-shadow: 0 6px 18px rgba(40,26,14,.4); animation: pop .3s ease both;
}
#tut-skip { float: right; margin: 6px 0 0 10px; cursor: pointer; border: 0; background: none; color: var(--ink2); font-size: 14px; text-decoration: underline; }
.tut-arrow { position: absolute; width: 0; height: 0; border: 12px solid transparent; }
.tut-arrow.down { border-top-color: var(--ink); bottom: -24px; left: var(--ax, 40px); }
.tut-arrow.up { border-bottom-color: var(--ink); top: -24px; left: var(--ax, 40px); }
.toast {
  position: absolute; top: 72px; left: 50%; transform: translateX(-50%); z-index: 30; pointer-events: none;
  background: #fff3d8; border: 2.5px solid var(--ink); color: var(--ink); font-weight: 800; font-size: 20px;
  padding: 8px 22px; border-radius: 14px; box-shadow: 0 5px 0 rgba(61,44,30,.35); animation: pop .3s ease both; white-space: nowrap;
}

/* ---------------------------------------------------------------- overlays */
.overlay {
  position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(40,28,18,.35), rgba(30,20,12,.72)); animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.9); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.loader { text-align: center; font-size: 22px; color: #f4e8cc; }
.spin { width: 54px; height: 54px; margin: 0 auto 10px; border-radius: 50%; border: 6px solid rgba(244,232,204,.3); border-top-color: #e0b040; animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg) } }

.modal {
  border: 3px solid var(--ink); border-radius: 22px; padding: 20px 30px; min-width: 440px; max-width: 1000px; max-height: 690px;
  text-align: center; box-shadow: 0 24px 60px rgba(20,12,6,.6), inset 0 0 30px rgba(140,100,50,.25); animation: pop .25s ease both;
  overflow-y: auto;
}
.modal.wide { width: 960px; }
.modal h2 { margin: 0 0 6px; font-size: 36px; line-height: 1.1; }
.modal .sub { margin: 0 0 8px; color: var(--ink2); font-size: 17px; }
.modal .goal { color: var(--sage); font-weight: 800; font-size: 18px; margin: 4px 0; }
.stack { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 14px; }
.keys { font-size: 14px !important; margin-top: 10px !important; }
kbd { background: #fbf3df; border: 1.5px solid var(--ink2); border-radius: 5px; padding: 0 6px; margin: 0 1px; font-family: inherit; font-weight: 800; }

.btn {
  cursor: pointer; font-weight: 800; font-size: 20px; color: #fff8e6; border: 2.5px solid var(--ink); border-radius: 14px; padding: 7px 22px 9px;
  box-shadow: 0 4px 0 rgba(40,26,14,.55); text-shadow: 0 1px 0 rgba(0,0,0,.35); transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(40,26,14,.55); }
.btn:disabled { filter: grayscale(.9) brightness(.8); cursor: not-allowed; }
.btn.green { background: linear-gradient(#7fae55, #4f7c32); }
.btn.blue { background: linear-gradient(#6f93b8, #43678c); }
.btn.purple { background: linear-gradient(#a57bc4, #6e4590); }
.btn.dark { background: linear-gradient(#8a7358, #5a4632); }
.btn.red { background: linear-gradient(#c46a52, #8e3a28); }
.btn.big { font-size: 30px; padding: 10px 44px 13px; }
.btn.small { font-size: 16px; padding: 4px 14px 6px; }
.btn.off { opacity: .5; text-decoration: line-through; }
textarea { width: 100%; height: 70px; font: 13px/1.3 monospace; border: 2px solid var(--ink2); border-radius: 10px; background: #fffaf0; color: var(--ink); resize: none; user-select: text; -webkit-user-select: text; }

/* title */
#title { background: radial-gradient(ellipse at center, rgba(40,28,18,.15), rgba(30,20,12,.55)); }
.title-card { padding: 26px 50px 20px; border: 3px solid var(--ink); border-radius: 26px; text-align: center; box-shadow: 0 24px 60px rgba(20,12,6,.55); animation: pop .4s ease both; }
.logo { display: flex; flex-direction: column; line-height: .95; }
.logo .l1 { font-size: 38px; font-weight: 800; letter-spacing: 10px; color: var(--gold); text-transform: uppercase; }
.logo .l2 { font-size: 72px; font-weight: 800; color: var(--red); -webkit-text-stroke: 2px var(--ink); text-shadow: 0 5px 0 rgba(61,44,30,.25); }
.logo .l3 { font-size: 22px; font-weight: 700; color: var(--ink2); letter-spacing: 3px; margin-top: 6px; }
.tagline { font-size: 19px; color: var(--ink2); max-width: 520px; margin: 12px auto 18px; }
.hint { font-size: 15px; color: var(--ink2); margin: 12px 0 0; }

.big-reward { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 8px 0; }
.big-reward b { font-size: 54px; color: #8a5a10; }
.big-reward .ico { width: 54px; height: 54px; }

/* legacy tree */
.prestige-box { display: flex; align-items: center; gap: 16px; text-align: left; background: rgba(122,74,138,.1); border: 2px solid rgba(122,74,138,.5); border-radius: 14px; padding: 10px 14px; }
.prestige-box > div { flex: 1; }
.pb-line { font-size: 16px; line-height: 1.35; }
.pb-line b { color: var(--plum); }
#pb-info { margin-top: 4px; font-size: 18px; font-weight: 800; }
.tree-head { display: flex; justify-content: space-between; align-items: center; margin: 10px 2px 6px; font-weight: 800; font-size: 18px; }
.tree-head span { display: flex; align-items: center; gap: 6px; }
.tree-head .ico { width: 24px; height: 24px; }
.tree-head small { color: var(--ink2); font-size: 14px; }
.tree { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; text-align: left; }
.branch h3 { margin: 0 0 6px; font-size: 18px; text-align: center; color: var(--ink2); border-bottom: 2px dashed rgba(61,44,30,.35); }
.node { display: grid; grid-template-columns: 38px 1fr auto; gap: 8px; align-items: center; padding: 6px 8px; margin-bottom: 6px; border-radius: 12px; border: 2px solid rgba(61,44,30,.35); background: rgba(255,250,236,.7); position: relative; }
.node.child { margin-left: 16px; }
.node.child::before { content: ''; position: absolute; left: -12px; top: 50%; width: 10px; border-top: 2px solid rgba(61,44,30,.4); }
.node.lock { opacity: .45; }
.node .ic { font-size: 26px; text-align: center; }
.node .nm { font-weight: 800; font-size: 15px; line-height: 1.1; }
.node .nm span { color: var(--plum); font-size: 13px; }
.node .ds { font-size: 13px; color: var(--ink2); line-height: 1.15; }
.node .btn { font-size: 15px; padding: 2px 8px 4px; min-width: 70px; border-radius: 10px; }

/* achievements & quests */
.ach-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: left; }
.ach { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 10px; border: 2px solid rgba(61,44,30,.3); background: rgba(255,250,236,.6); font-size: 14px; line-height: 1.15; }
.ach.on { border-color: var(--gold); background: #fff4d0; }
.ach .ai { font-size: 22px; }
.ach small { color: var(--ink2); }
.list { display: grid; gap: 8px; text-align: left; margin-top: 8px; }
.quest { display: grid; grid-template-columns: 40px 1fr auto; gap: 12px; align-items: center; padding: 8px 12px; border-radius: 12px; border: 2px solid rgba(61,44,30,.35); background: rgba(255,250,236,.7); }
.quest .qi { font-size: 28px; text-align: center; }
.quest .qn { font-weight: 800; font-size: 18px; }
.quest .prog { height: 8px; border-radius: 4px; background: rgba(61,44,30,.18); overflow: hidden; margin-top: 3px; }
.quest .prog i { display: block; height: 100%; background: var(--sage); }
.howto { text-align: left; font-size: 18px; line-height: 1.45; margin: 6px 0; padding-left: 24px; }

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 760px) and (pointer: coarse) {
  #rotate {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; padding: 10px; text-align: center; z-index: 50;
    background: #e0b040; color: #2a1a00; font-weight: 800;
  }
}
@media (prefers-reduced-motion: reduce) {
  .overlay, .modal, .toast, .skill.ready, .hbtn.crown.ready, #tut { animation: none !important; }
}

/* ---------------------------------------------------------------- i18n */
.lang-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-weight: 800; }
.lang-row select { flex: 1; max-width: 60%; font: inherit; font-weight: 700; padding: 6px 10px; border-radius: 10px; border: 2px solid var(--ink2); background: #fffaf0; color: var(--ink); }
/* long labels (de/ru/fr…) wrap instead of overflowing; CJK/Thai line-break anywhere */
.card .nm, .card .val, .tab, .btn, .hbtn, .node .nm, .ach, .quest .qn { overflow-wrap: break-word; hyphens: auto; }
body[data-lang="de"] .card .nm, body[data-lang="ru"] .card .nm, body[data-lang="fr"] .card .nm,
body[data-lang="es"] .card .nm, body[data-lang="pt"] .card .nm, body[data-lang="id"] .card .nm, body[data-lang="tr"] .card .nm { font-size: 13px; letter-spacing: -0.01em; }
body[data-lang="de"] .card .val, body[data-lang="ru"] .card .val, body[data-lang="fr"] .card .val { font-size: 12.5px; }
.card .top > div:last-child { min-width: 0; }
body[data-lang="ja"], body[data-lang="zh"], body[data-lang="ko"], body[data-lang="th"] { line-break: anywhere; }
