:root {
  --ink: #05070b;
  --ash: #e6dfd2;
  --ember: #ff6a1f;
  --red: #ff1a2e;
  --green: #45ff78;
  --violet: #c040ff;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
  --display: 'Rubik Mono One', 'JetBrains Mono', monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--ink); color: var(--ash); font-family: var(--mono); overflow: hidden; touch-action: none; -webkit-user-select: none; user-select: none; }
canvas#c { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100svh; display: block; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--ember); outline-offset: 3px; }

/* screens shown by body[data-state] */
.screen, #hud { display: none; }
body[data-state="loading"] #loading,
body[data-state="title"] #title,
body[data-state="levelup"] #levelup,
body[data-state="paused"] #paused,
body[data-state="over"] #over,
body[data-state="error"] #error { display: flex; }
body[data-state="play"] #hud,
body[data-state="levelup"] #hud,
body[data-state="paused"] #hud,
body[data-state="over"] #hud { display: block; }

.screen {
  position: fixed; inset: 0; flex-direction: column; align-items: flex-start; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) max(6vw, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(6vw, env(safe-area-inset-left));
  gap: 18px; z-index: 5;
}
#levelup, #paused, #over, #error { background: rgba(5, 7, 11, 0.72); }
#loading { align-items: center; }
.load { font-size: 18px; color: var(--ember); }
.load span { display: inline-block; animation: blink 1s infinite; }
.load span:nth-child(2) { animation-delay: .15s; } .load span:nth-child(3) { animation-delay: .3s; } .load span:nth-child(4) { animation-delay: .45s; }
@keyframes blink { 50% { opacity: .15; } }

#title { background: linear-gradient(90deg, rgba(5,7,11,.85) 0%, rgba(5,7,11,.55) 45%, rgba(5,7,11,0) 75%); }
h1 { font-family: var(--display); font-size: clamp(48px, 10vw, 128px); line-height: .9; color: var(--ember); text-shadow: 4px 4px 0 var(--red); }
h2 { font-family: var(--display); font-size: clamp(28px, 5vw, 52px); line-height: 1; color: var(--ash); }
.lede { max-width: 34ch; font-size: clamp(15px, 1.6vw, 19px); line-height: 1.5; }
.small { font-size: 14px; opacity: .8; }
.big {
  font-family: var(--display); font-size: clamp(18px, 2.2vw, 24px); padding: 16px 28px;
  background: var(--ember); color: var(--ink); border: 3px solid var(--ash);
  box-shadow: 6px 6px 0 var(--red);
}
.big:hover { transform: translate(-2px, -2px); box-shadow: 8px 8px 0 var(--red); }
.big:active { transform: translate(3px, 3px); box-shadow: 2px 2px 0 var(--red); }
.plain { font-size: 15px; text-decoration: underline; padding: 8px 0; }
.controls.desk { display: grid; grid-template-columns: repeat(5, auto); gap: 6px 22px; margin-top: 10px; }
.controls dt { font-weight: 800; color: var(--ember); font-size: 15px; }
.controls dd { font-size: 14px; opacity: .85; }
.controls.mob { display: none; max-width: 34ch; font-size: 15px; line-height: 1.5; }
body.touch .desk { display: none !important; }
body.touch .controls.mob { display: block; }
.bigtime { font-family: var(--display); font-size: clamp(56px, 12vw, 120px); color: var(--ember); line-height: 1; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 3; }
#tierbar {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: rgba(5,7,11,.8); border: 2px solid var(--ash);
  width: min(560px, 92vw);
}
#tier-name { font-family: var(--display); font-size: 16px; color: var(--ember); min-width: 7.5em; }
#tier-segs { display: flex; gap: 3px; }
#tier-segs i { width: 14px; height: 14px; border: 2px solid var(--ash); }
#tier-segs i.on { background: var(--red); border-color: var(--red); }
.track { flex: 1; height: 6px; background: rgba(230,223,210,.2); overflow: hidden; }
#tier-fill { display: block; height: 100%; background: var(--ash); transform-origin: left; }
#timer { font-weight: 800; font-size: 18px; min-width: 3.2em; text-align: right; }
#topright { position: absolute; top: max(14px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); display: flex; gap: 14px; align-items: center; font-weight: 800; font-size: 15px; }
#pause-btn { pointer-events: auto; width: 40px; height: 40px; border: 2px solid var(--ash); background: rgba(5,7,11,.8); font-weight: 800; }
#vitals { position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); width: min(380px, 44vw); }
.hp { position: relative; height: 26px; border: 2px solid var(--ash); background: rgba(5,7,11,.8); }
#hp-fill { position: absolute; inset: 0; background: var(--ember); transform-origin: left; transition: transform .12s; }
#hp-num { position: relative; display: block; line-height: 22px; padding-left: 8px; font-size: 14px; color: var(--ink); mix-blend-mode: normal; text-shadow: 0 0 0 transparent; }
.xp { height: 8px; margin-top: 4px; background: rgba(230,223,210,.2); }
#xp-fill { display: block; height: 100%; background: #7affd8; transform-origin: left; }

.slot { position: relative; overflow: hidden; }
.slot::after { content: ''; position: absolute; inset: 0; background: rgba(5,7,11,.72); transform-origin: bottom; transform: scaleY(var(--cd, 0)); }
#skills { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; gap: 8px; }
#skills .slot { width: 112px; padding: 10px 10px 8px; border: 2px solid var(--ash); background: rgba(5,7,11,.8); display: flex; flex-direction: column; gap: 2px; }
#skills .slot b { font-size: 15px; }
#skills .slot small { font-size: 13px; opacity: .75; }
.slot.sky.ready { border-color: var(--red) !important; }
.slot.oc.ready { border-color: var(--green) !important; }

#toast { position: fixed; left: 0; right: 0; top: 30%; text-align: center; font-family: var(--display); font-size: clamp(40px, 9vw, 96px); color: var(--ash); opacity: 0; pointer-events: none; z-index: 4; text-shadow: 4px 4px 0 var(--red); }
#toast.go { animation: toast 2.2s ease-out; }
@keyframes toast { 0% { opacity: 0; transform: scale(1.3); } 12% { opacity: 1; transform: scale(1); } 70% { opacity: 1; } 100% { opacity: 0; } }
body.oc #tier-name { color: var(--green); }

/* level up cards: hard-edged panels, number key in the corner */
#levelup { align-items: center; }
#cards { display: grid; grid-template-columns: repeat(3, minmax(0, 260px)); gap: 16px; }
.card { position: relative; text-align: left; padding: 22px 18px 20px; min-height: 170px; background: var(--ink); border: 3px solid var(--ash); display: flex; flex-direction: column; gap: 10px; }
.card:hover, .card:focus-visible { border-color: var(--ember); transform: translateY(-4px); }
.card strong { font-family: var(--display); font-size: 18px; color: var(--ember); line-height: 1.15; }
.card .txt { font-size: 15px; line-height: 1.45; }
.card .key { position: absolute; top: 0; right: 0; background: var(--ash); color: var(--ink); font-weight: 800; padding: 2px 9px; }

/* touch controls */
#stick-zone, #pad { display: none; }
body.touch #stick-zone { display: block; position: absolute; left: 0; bottom: 0; width: 50%; height: 60%; pointer-events: auto; }
#stick-base { position: absolute; left: 0; top: 0; width: 120px; height: 120px; border: 3px solid rgba(230,223,210,.5); display: none; }
#stick-base.on { display: block; }
#stick-knob { position: absolute; left: 35px; top: 35px; width: 44px; height: 44px; background: var(--ember); }
body.touch #pad {
  display: grid; position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  grid-template-columns: 74px 104px; grid-template-rows: 64px 64px 64px; gap: 10px; pointer-events: auto;
}
#pad .slot { border: 3px solid var(--ash); background: rgba(5,7,11,.75); font-weight: 800; font-size: 15px; }
#btn-skyfall { grid-column: 1; grid-row: 1; }
#btn-overclock { grid-column: 2; grid-row: 1; }
#btn-dash { grid-column: 1; grid-row: 2 / 4; }
#btn-attack { grid-column: 2; grid-row: 2 / 4; background: rgba(255,106,31,.85) !important; color: var(--ink); font-family: var(--display); font-size: 18px; }
body.touch #vitals { bottom: auto; top: calc(max(14px, env(safe-area-inset-top)) + 58px); width: 46vw; }
body.touch #topright { top: calc(max(14px, env(safe-area-inset-top)) + 58px); }

@media (max-width: 720px) {
  #cards { grid-template-columns: 1fr; width: 100%; gap: 10px; }
  .card { min-height: 0; padding: 16px; }
  #tier-segs { display: none; }
  #tier-name { min-width: 0; font-size: 14px; }
  #title { background: rgba(5,7,11,.6); }
}
.noscript { position: fixed; inset: 0; display: grid; place-items: center; font-size: 18px; }
