:root {
  --bg: #0b0912;
  --panel: rgba(18, 14, 28, 0.92);
  --line: #3a2f52;
  --gold: #f0c050;
  --gold2: #ffe9a8;
  --jade: #5cf0a0;
  --red: #e04848;
  --text: #ece6f6;
  --dim: #9a90b0;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow: hidden; overscroll-behavior: none; }
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; }
/* phones that won't turn the browser: the page turns itself while held upright */
body.rotated #app { inset: auto; top: 0; left: 0; width: 100vh; height: 100vw; width: 100dvh; height: 100dvw; transform-origin: top left; transform: rotate(90deg) translateY(-100%); }

.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto;
  background: radial-gradient(ellipse at 50% 30%, #2a1f45 0%, #120e1e 55%, #08060c 100%); }
.box { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px 20px; box-shadow: 0 20px 60px #0008, inset 0 1px #ffffff10; }
.box.wide { width: min(980px, 100%); }
h1 { margin: 0 0 6px; text-align: center; font-size: 30px; letter-spacing: 1px; color: var(--gold2); text-shadow: 0 0 18px #f0a82066; line-height: 1.1; }
h1 span { color: var(--gold); font-size: 40px; }
h2 { margin: 0 0 14px; color: var(--gold2); text-align: center; }
.sub, .hint { text-align: center; color: var(--dim); font-size: 13px; margin: 6px 0 14px; }
.hint { margin: 14px 0 0; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.tabs button { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 8px; cursor: pointer; color: var(--dim); }
.tabs button.on { border-color: var(--gold); color: var(--gold2); background: #f0c05014; }
form { display: grid; gap: 10px; }
form.row { grid-template-columns: 1fr auto; margin-top: 14px; }
input { background: #0c0a14; border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; outline: none; min-width: 0; }
input:focus { border-color: var(--gold); }
.primary { background: linear-gradient(#f6cd62, #c88a1c); color: #2a1604; border: 0; border-radius: 8px; padding: 11px 18px; font-weight: 700; cursor: pointer; }
.primary:disabled { opacity: 0.6; }
.err { color: #ff8080; min-height: 1em; margin: 4px 0 0; font-size: 13px; }

.classes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.card { text-align: left; background: #0e0b18; border: 1px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.card.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 24px #f0c05030; }
.card canvas { width: 100%; image-rendering: pixelated; border-radius: 8px; background: #16121f; aspect-ratio: 120 / 96; }
.card h3 { margin: 4px 0 0; color: var(--gold2); font-size: 16px; }
.card p { margin: 0; color: var(--dim); font-size: 12px; }
.card ul { margin: 2px 0 0; padding-left: 18px; font-size: 12px; color: #cfc6e6; }
.stats div { display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 6px; font-size: 11px; color: var(--dim); }
.stats i { height: 5px; background: #ffffff12; border-radius: 3px; overflow: hidden; }
.stats b { display: block; height: 100%; background: linear-gradient(90deg, #c88a1c, #ffe08a); }

/* ---- the game */
#game { padding: 0; background: #000; display: block; }
#view, #labels { position: absolute; inset: 0; width: 100%; height: 100%; }
#view { image-rendering: pixelated; image-rendering: crisp-edges; }
#labels { pointer-events: none; }
#hud { position: absolute; inset: 0; pointer-events: none; padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
#hud > * { pointer-events: auto; }
.me { position: absolute; top: 8px; left: 10px; width: min(260px, 34vw); background: #0d0a16cc; border: 1px solid var(--line); border-radius: 10px; padding: 6px 8px; }
.me .nm { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .nm b { color: var(--gold2); }
.me .nm span { color: var(--jade); font-size: 12px; }
.bar { position: relative; height: 12px; background: #00000080; border-radius: 6px; overflow: hidden; margin-top: 4px; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 0; transition: width 0.15s; }
.bar.hp i { background: linear-gradient(#ff7070, #c02a2a); }
.bar.exp { height: 8px; }
.bar.exp i { background: linear-gradient(#7ff0ff, #1d8aa0); }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 9px; line-height: 12px; text-shadow: 0 1px 2px #000; }
.bar.exp span { line-height: 8px; font-size: 7px; }
.small { font-size: 11px; color: var(--dim); margin-top: 3px; }
.top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; background: #0d0a16cc; border: 1px solid var(--line); border-radius: 20px; padding: 4px 14px; font-size: 13px; white-space: nowrap; }
.top b { color: var(--gold2); }
.dim { color: var(--dim); font-size: 11px; }
.menu { position: absolute; top: 8px; right: 10px; display: flex; gap: 6px; }
.menu button { width: 38px; height: 38px; border-radius: 10px; background: #0d0a16cc; border: 1px solid var(--line); cursor: pointer; font-size: 17px; }
.menu button.ready { border-color: var(--gold); box-shadow: 0 0 12px #f0c05088; animation: pulse 1.2s infinite; }
.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }

#zone { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none; opacity: 0; }
#zone div { font-size: 26px; font-weight: 800; color: var(--gold2); text-shadow: 0 0 16px #f0a820aa, 0 2px 3px #000; letter-spacing: 1px; }
#zone small { color: #e6dcff; text-shadow: 0 1px 3px #000; }
#zone.on { animation: zone 3.2s ease forwards; }
@keyframes zone { 0% { opacity: 0; transform: translate(-50%, 8px); } 12%, 75% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }
#toast { position: absolute; top: 30%; left: 50%; transform: translateX(-50%); background: #000000c0; border: 1px solid var(--gold); color: var(--gold2); padding: 6px 14px; border-radius: 20px; opacity: 0; transition: opacity 0.2s; pointer-events: none; white-space: nowrap; }
#toast.on { opacity: 1; }

.chat { position: absolute; left: 10px; bottom: 10px; width: min(340px, 40vw); }
#log { max-height: 130px; overflow-y: auto; font-size: 12px; text-shadow: 0 1px 2px #000; scrollbar-width: none; mask-image: linear-gradient(transparent, #000 25%); }
#log .line { padding: 1px 0; }
#log .line b { color: var(--gold2); }
#log .sys { color: #b8d8ff; font-style: italic; }
#chatInput { width: 100%; margin-top: 4px; padding: 6px 10px; font-size: 13px; background: #0d0a16cc; }

#joyzone { display: none; position: absolute; left: 0; bottom: 0; width: 45%; height: 62%; touch-action: none; }
#joybase { position: absolute; width: 110px; height: 110px; margin: -55px 0 0 -55px; left: 90px; top: 70%; border-radius: 50%; background: #ffffff14; border: 2px solid #ffffff30; opacity: 0.6; }
#joybase.on { opacity: 1; }
#joyknob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px; border-radius: 50%; background: radial-gradient(#fff8, #fff3); }

.skills { position: absolute; right: 12px; bottom: 12px; display: grid; grid-template-columns: repeat(5, auto); align-items: end; gap: 8px; }
.skills button { position: relative; border-radius: 50%; border: 2px solid #f0c05099; background: radial-gradient(#3a2a10, #120c04); cursor: pointer; touch-action: none; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.skills .sk { width: 66px; height: 66px; }
.skills .sk.s1 { width: 82px; height: 82px; border-color: var(--gold); }
.skills .sk::after { content: ""; position: absolute; inset: 0; background: conic-gradient(#000000b0 calc(var(--cd, 0) * 360deg), transparent 0); pointer-events: none; }
.skills .nm { font-size: 10px; font-weight: 700; text-align: center; line-height: 1.1; padding: 0 6px; color: var(--gold2); text-shadow: 0 1px 2px #000; }
.skills .cdt { position: absolute; z-index: 2; font-size: 18px; font-weight: 800; color: #fff; text-shadow: 0 0 4px #000; }
.skills kbd { position: absolute; bottom: 3px; font-size: 9px; color: var(--dim); }
.skills .item { width: 46px; height: 46px; border-color: #5cf0a088; background: radial-gradient(#10301e, #050c08); }
.skills .item .ic { font-size: 18px; }
.skills .item .qty { position: absolute; bottom: 2px; right: 8px; font-size: 10px; font-weight: 700; }
.skills button:active { transform: scale(0.94); }

#respawn { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; background: #30000040; text-shadow: 0 2px 4px #000; pointer-events: none; }
#respawn b { color: var(--gold2); margin: 0 6px; }

#panel, #fatal { position: absolute; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 5; }
.pbox { width: min(560px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.pbox header { display: flex; justify-content: space-between; align-items: center; }
.pbox h3 { margin: 0; color: var(--gold2); }
.pbox header button { background: none; border: 0; font-size: 20px; cursor: pointer; }
#fatal .pbox { text-align: center; }
.shop .bal { color: var(--gold2); }
.shop .item { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.shop .item small { display: block; color: var(--dim); }
.shop .item button { background: #2a1f10; border: 1px solid var(--gold); border-radius: 8px; padding: 6px 10px; margin-left: 4px; cursor: pointer; color: var(--gold2); }
.board { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; font-size: 13px; }
.board h4 { margin: 8px 0; color: var(--gold2); }
.board ol { margin: 0; padding-left: 20px; }
.help p { margin: 8px 0; font-size: 14px; }

/* touch screens: joystick on, keyboard hints off, chat smaller */
body.touch #joyzone { display: block; }
body.touch .skills kbd, body.touch #chatInput { display: none; }
body.touch .chat { bottom: auto; top: 96px; left: 10px; width: 34%; pointer-events: none; }
body.touch #log { max-height: 80px; font-size: 11px; }
/* short landscape screens (phones), and phones turned by the page itself */
@media (max-height: 420px) {
  .skills .sk { width: 56px; height: 56px; }
  .skills .sk.s1 { width: 70px; height: 70px; }
  .skills .item { width: 40px; height: 40px; }
  .top { font-size: 11px; gap: 8px; padding: 3px 10px; left: 10px; transform: none; top: 92px; }
  .menu button { width: 32px; height: 32px; font-size: 14px; }
  .me { padding: 4px 6px; }
  body.touch .chat { top: 122px; }
}
body.rotated .skills .sk { width: 56px; height: 56px; }
body.rotated .skills .sk.s1 { width: 70px; height: 70px; }
body.rotated .skills .item { width: 40px; height: 40px; }
body.rotated .top { font-size: 11px; gap: 8px; padding: 3px 10px; left: 10px; transform: none; top: 92px; }
body.rotated .menu button { width: 32px; height: 32px; font-size: 14px; }
body.rotated .me { padding: 4px 6px; }
body.rotated.touch .chat { top: 122px; }
@media (max-width: 760px) and (orientation: portrait) {
  .classes { grid-template-columns: 1fr; }
}
@media (max-width: 760px) { .top span:nth-child(4), .top #ping { display: none; } }

#loading { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; background: #0b0912; color: var(--gold2); }
#loading .spin { width: 38px; height: 38px; border-radius: 50%; border: 3px solid #f0c05033; border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
