* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #070b18; color: #fff;
  font-family: 'Baloo 2', 'Nunito', system-ui, 'Noto Sans', 'Noto Sans Thai', 'Noto Sans CJK SC', 'Hiragino Sans', 'PingFang SC', 'Apple SD Gothic Neo', sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
#viewport { position: fixed; inset: 0; display: grid; place-items: center; }
#stage {
  position: absolute; left: 0; top: 0; width: 1280px; height: 720px;
  transform-origin: 0 0; overflow: hidden; border-radius: 0;
}
#game { position: absolute; inset: 0; width: 1280px; height: 720px; touch-action: none; display: block; }

.overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px;
  background: radial-gradient(ellipse at center, rgba(10,14,34,.55), rgba(5,8,20,.88));
  animation: fade .25s ease;
}
.overlay.hidden { display: none; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { transform: scale(.85); opacity: 0 } to { transform: scale(1); opacity: 1 } }

.loader { text-align: center; font-size: 22px; }
.spin { width: 56px; height: 56px; margin: 0 auto 10px; border-radius: 50%; border: 6px solid #2a3560; border-top-color: #ffb020; animation: rot 1s linear infinite; }
@keyframes rot { to { transform: rotate(360deg) } }

#menu { background: linear-gradient(180deg, rgba(5,8,20,.35), rgba(5,8,20,.8)); justify-content: flex-start; padding-top: 30px; }
.menu-head { width: 1160px; display: flex; justify-content: space-between; align-items: flex-start; }
.logo { display: flex; flex-direction: column; line-height: .9; filter: drop-shadow(0 6px 0 rgba(0,0,0,.35)); }
.logo .l1 { font-size: 46px; font-weight: 800; letter-spacing: 6px; color: #ffd34d; -webkit-text-stroke: 2px #7a3a00; }
.logo .l2 { font-size: 64px; font-weight: 800; background: linear-gradient(90deg, #ff7a2f, #ffe14a 30%, #5fc8ff 55%, #58d15a 75%, #b36bff); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-stroke: 2px rgba(0,0,0,.35); }
.logo .l3 { font-size: 40px; font-weight: 800; letter-spacing: 10px; color: #fff; -webkit-text-stroke: 2px #1a2350; }
.wallet { font-size: 26px; background: rgba(20,26,56,.9); border: 2px solid rgba(255,255,255,.15); padding: 6px 18px; border-radius: 30px; }
.wallet b { color: #9ff3ff; }
.wallet.center { align-self: center; }

.chapters { display: grid; grid-template-columns: repeat(4, 272px); gap: 18px; margin-top: 8px; }
.chapter {
  position: relative; border-radius: 18px; overflow: hidden; background: #111831;
  border: 3px solid rgba(255,255,255,.14); cursor: pointer; transition: transform .15s, border-color .15s;
  animation: pop .3s ease both;
}
.chapter:hover:not(.locked) { transform: translateY(-4px); border-color: #ffd34d; }
.chapter canvas { display: block; width: 100%; height: 153px; }
.chapter .info { padding: 8px 14px 12px; }
.chapter .name { font-size: 21px; font-weight: 800; }
.chapter .meta { display: flex; justify-content: space-between; align-items: center; color: #aab4de; font-size: 15px; }
.chapter .st { color: #ffd34d; font-size: 20px; letter-spacing: 2px; }
.chapter .st .off { color: #3a4470; }
.chapter .tag { position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.6); padding: 2px 10px; border-radius: 10px; font-size: 14px; font-weight: 800; }
.chapter.locked { cursor: not-allowed; filter: grayscale(.8) brightness(.6); }
.chapter.locked::after { content: '🔒'; position: absolute; inset: 0 0 auto 0; height: 153px; display: grid; place-items: center; font-size: 48px; }
.chapter .play { position: absolute; right: 12px; top: 112px; background: linear-gradient(#34d058, #15803d); border-radius: 12px; padding: 2px 16px; font-weight: 800; font-size: 18px; box-shadow: 0 4px 0 #0b5226; }

.menu-row { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 12px; margin-top: 6px; max-width: 1180px; }
.menu-row.small { justify-content: center; margin-top: 14px; }

.btn {
  font: inherit; font-weight: 800; font-size: 20px; color: #fff; border: 0; cursor: pointer;
  padding: 10px 26px 12px; border-radius: 14px; position: relative;
  box-shadow: 0 5px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25);
  transition: transform .08s, filter .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25); }
.btn:disabled { filter: grayscale(1) brightness(.6); cursor: not-allowed; }
.btn.green { background: linear-gradient(#34d058, #15803d); }
.btn.blue { background: linear-gradient(#4f8cff, #1d4fb8); }
.btn.purple { background: linear-gradient(#b169ff, #6b21a8); }
.btn.dark { background: linear-gradient(#475569, #1e293b); }
.btn.gold { background: linear-gradient(#ffc93c, #c27c00); color: #3a2200; }
.btn.icon { padding: 10px 16px 12px; }
.btn.off { opacity: .45; }

.modal {
  background: linear-gradient(180deg, #1a2350, #0f1533); border: 3px solid rgba(255,255,255,.15);
  border-radius: 24px; padding: 26px 36px; min-width: 420px; max-width: 900px; text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: pop .25s ease both;
}
.modal.wide { width: 860px; }
/* long translations: never let a modal leave the 720px stage */
.modal { max-height: 704px; overflow-y: auto; }
.modal h2 { margin: 0 0 8px; font-size: 40px; line-height: 1.1; }
.modal .sub { margin: 0 0 10px; color: #aab4de; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.actions { display: flex; gap: 12px; justify-content: center; margin-top: 18px; }

.upgrade-list { display: grid; gap: 10px; margin-top: 14px; text-align: left; }
.upg { display: grid; grid-template-columns: 50px 1fr auto; gap: 14px; align-items: center; background: rgba(255,255,255,.05); border-radius: 14px; padding: 8px 14px; }
.upg .ic { font-size: 32px; text-align: center; }
.upg .nm { font-size: 20px; font-weight: 800; }
.upg .ds { color: #aab4de; font-size: 15px; }
.upg .pips { display: inline-flex; gap: 4px; margin-left: 8px; vertical-align: middle; }
.upg .pips i { width: 14px; height: 8px; border-radius: 4px; background: #2d3665; }
.upg .pips i.on { background: #ffd34d; }
.upg .btn { font-size: 17px; padding: 6px 16px 8px; min-width: 120px; }

.howto { text-align: left; font-size: 17px; line-height: 1.38; margin: 6px 0; padding-left: 24px; }
.howto li { margin: 4px 0; }
.elements { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 16px; text-align: left; font-size: 16px; color: #d6dcf7; margin: 10px 0; }
.dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.dot.fire { background: #ff7a2f; } .dot.ice { background: #5fc8ff; } .dot.nature { background: #58d15a; }
.dot.lightning { background: #ffe14a; } .dot.arcane { background: #b36bff; }
.keys { color: #aab4de; font-size: 15px; }
kbd { background: #2d3665; border-radius: 6px; padding: 0 7px; margin: 0 2px; font-family: inherit; font-weight: 800; color: #fff; }

.stars { font-size: 64px; letter-spacing: 8px; line-height: 1; margin: 4px 0 10px; }
.stars span { display: inline-block; color: #ffd34d; text-shadow: 0 4px 0 #8a5200; animation: pop .4s ease both; }
.stars span.off { color: #2d3665; text-shadow: none; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 10px 0; }
.stats div { background: rgba(255,255,255,.06); border-radius: 12px; padding: 6px 10px; }
.stats b { display: block; font-size: 26px; color: #ffe27a; }
.stats small { color: #aab4de; font-size: 14px; }
.dmg { display: grid; gap: 4px; margin: 8px 0; }
.dmg .row { display: grid; grid-template-columns: 90px 1fr 70px; gap: 8px; align-items: center; font-size: 14px; text-align: left; }
.dmg .bar { height: 10px; border-radius: 5px; background: rgba(255,255,255,.07); overflow: hidden; }
.dmg .bar i { display: block; height: 100%; border-radius: 5px; }
.reward { font-size: 28px; font-weight: 800; }
.reward b { color: #9ff3ff; }
.win h2 { color: #ffd34d; }
.lose h2 { color: #ff7a8a; }

#rotate { display: none; }
@media (orientation: portrait) and (max-width: 700px) and (pointer: coarse) {
  #rotate {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; padding: 10px; text-align: center;
    background: rgba(255,176,32,.95); color: #2a1a00; font-weight: 800; z-index: 10;
  }
}

/* ---------------------------------------------------------------- long-term systems */
.head-right { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.wallet-row { display: flex; gap: 10px; }
.streak { font-size: 22px; background: rgba(60,20,8,.9); border: 2px solid rgba(255,140,60,.5); padding: 6px 14px; border-radius: 30px; }
.streak b { color: #ffb36b; }
.streak.hidden, .continue.hidden, .badge.hidden { display: none; }
.continue { font-size: 20px; animation: glow 1.6s ease-in-out infinite; }
.continue small { display: block; font-size: 14px; font-weight: 700; opacity: .9; }
@keyframes glow { 50% { filter: brightness(1.18); } }

.diff-tabs { display: flex; gap: 10px; width: 1160px; }
.diff-tabs .tab { --c: #34d058; }
.tab {
  font: inherit; font-weight: 800; font-size: 18px; color: #c7cbe0; cursor: pointer;
  background: rgba(20,26,56,.85); border: 2px solid rgba(255,255,255,.14); border-radius: 12px; padding: 4px 18px;
}
.tab.on { color: #fff; border-color: var(--c, #ffd34d); box-shadow: inset 0 -3px 0 var(--c, #ffd34d); }
.tab.locked { opacity: .45; cursor: not-allowed; }
.tab small { font-weight: 700; color: #ffd34d; margin-left: 6px; }

.btn .badge {
  position: absolute; top: -8px; right: -8px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  background: #ef4444; color: #fff; font-size: 15px; line-height: 24px; box-shadow: 0 2px 0 #7f1d1d;
}

.upg-tabs { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 6px 0; }
.upg-tabs .wallet { font-size: 20px; padding: 3px 14px; margin-left: 12px; }
.upg .lv { color: #ffd34d; font-size: 16px; margin-left: 8px; }
.upg .perks { font-size: 13px; color: #6b7399; }
.upg .perks .on { color: #7dff9a; }
.upg .dot { width: 30px; height: 30px; margin: 0 auto; display: block; }
.upgrade-list .prog { height: 8px; border-radius: 4px; background: #2d3665; overflow: hidden; margin-top: 4px; }
.upgrade-list .prog i { display: block; height: 100%; background: #ffd34d; }

.bless-title { margin: 0; font-size: 46px; color: #ffd34d; text-shadow: 0 4px 0 rgba(0,0,0,.4); }
.bless-sub { margin: -8px 0 4px; color: #c7cbe0; font-size: 17px; }
.bless-cards { display: flex; gap: 22px; }
.bless-card {
  font: inherit; color: #fff; cursor: pointer; width: 260px; min-height: 290px; padding: 18px 18px 34px;
  border-radius: 20px; border: 3px solid var(--c); text-align: center; position: relative;
  background: linear-gradient(180deg, rgba(30,38,80,.97), rgba(12,16,38,.97));
  box-shadow: 0 0 30px color-mix(in srgb, var(--c) 45%, transparent), 0 10px 0 rgba(0,0,0,.35);
  transition: transform .12s; animation: pop .3s ease both;
}
.bless-card:hover { transform: translateY(-8px) scale(1.03); }
.bless-card .ic { font-size: 70px; line-height: 1.2; }
.bless-card .nm { font-size: 24px; font-weight: 800; margin: 4px 0; }
.bless-card .ds { font-size: 17px; color: #d6dcf7; line-height: 1.35; }
.bless-card .rar { position: absolute; top: 10px; left: 12px; font-size: 13px; font-weight: 800; color: var(--c); }
.bless-card .stk { position: absolute; top: 10px; right: 12px; font-size: 13px; color: #aab4de; }
.bless-card .key { position: absolute; bottom: 10px; left: 0; right: 0; font-size: 13px; color: #6b7399; }

.result-extra { font-size: 16px; color: #d6dcf7; display: grid; gap: 4px; margin-top: 6px; }
.result-extra .q { color: #7dff9a; }
.result-extra .goal { color: #ffd34d; }
.save-note { font-size: 14px; max-width: 320px; margin: 12px auto 0; }

.toast {
  position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 20;
  background: linear-gradient(#ffc93c, #c27c00); color: #3a2200; font-weight: 800; font-size: 20px;
  padding: 10px 24px; border-radius: 16px; box-shadow: 0 6px 0 rgba(0,0,0,.35); animation: pop .3s ease both;
  pointer-events: none;
}
.toast.hidden { display: none; }
@media (prefers-reduced-motion: reduce) {
  .continue, .overlay, .modal, .bless-card, .chapter, .toast { animation: none !important; }
}

/* ---------------------------------------------------------------- language picker */
.lang-pick {
  display: inline-flex; align-items: center; gap: 6px; font-size: 20px; cursor: pointer;
  background: linear-gradient(#475569, #1e293b); border-radius: 14px; padding: 6px 10px 8px 14px;
  box-shadow: 0 5px 0 rgba(0,0,0,.35), inset 0 2px 0 rgba(255,255,255,.25);
}
.lang-select {
  font: inherit; font-size: 17px; font-weight: 800; color: #fff; background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.2); border-radius: 10px; padding: 3px 8px; cursor: pointer; max-width: 190px;
}
.lang-select option { color: #111; background: #fff; }

/* phones: invisible hit-area padding around buttons (the 1280×720 stage is scaled down on small screens) */
@media (pointer: coarse) {
  .btn::after { content: ''; position: absolute; inset: -7px -5px; }
}
