:root {
  --teal: #004a4a;
  --teal-d: #002e30;
  --hud: #0a2a6a;
  --hud-d: #051a44;
  --hud-l: #3a5ab0;
  --panel: #06204a;
  --text: #e8e8f0;
  --dim: #8a94b0;
  --gold: #ffd040;
  --red: #ff4040;
  --green: #6dff8a;
  --stone: #4a4a52;
  --stone-l: #7a7a84;
  --stone-d: #26262c;
  --font: 'Press Start 2P', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--teal-d);
  color: var(--text);
  font-family: var(--font);
  font-size: 10px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button, input, select { font-family: var(--font); font-size: 10px; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

#app {
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--teal);
  position: relative;
  padding-top: env(safe-area-inset-top);
}

/* ---------- 3D view ---------- */
#view-wrap {
  position: relative;
  flex: none;
  padding: 6px 6px 0;
  display: flex;
  justify-content: center;
}
#view {
  display: block;
  width: min(100%, 76vh);
  aspect-ratio: 2 / 1;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 3px solid #000;
  box-shadow: 0 0 0 2px var(--teal-d);
  background: #000;
  touch-action: none;
  cursor: crosshair;
}
#floor-tag {
  position: absolute;
  left: 50%;
  bottom: -2px;
  transform: translate(-50%, 50%);
  background: #000;
  color: var(--gold);
  padding: 3px 8px;
  font-size: 7px;
  white-space: nowrap;
  border: 2px solid var(--hud-l);
  z-index: 2;
  max-width: 94%;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- screen ---------- */
#screen {
  flex: 1;
  overflow-y: auto;
  padding: 18px 10px 80px;
  -webkit-overflow-scrolling: touch;
}
h2 {
  font-size: 10px;
  margin: 18px 0 8px;
  color: var(--gold);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  text-shadow: 2px 2px 0 #000;
}
h2 small { color: var(--dim); font-size: 7px; align-self: center; }
h2:first-child { margin-top: 0; }

.xp { margin-bottom: 4px; }
.xp .bar, .bar {
  height: 10px;
  background: #000;
  border: 2px solid var(--hud-l);
  position: relative;
}
.bar i { display: block; height: 100%; background: linear-gradient(#ffe070, #e0a020); }
.xp .meta { display: flex; justify-content: space-between; font-size: 7px; color: var(--dim); margin-top: 4px; }

.task {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--stone);
  border: 3px solid;
  border-color: var(--stone-l) var(--stone-d) var(--stone-d) var(--stone-l);
  padding: 8px;
  margin-bottom: 6px;
}
.task.done { opacity: 0.55; background: #34343a; }
.task.off { opacity: 0.4; }
.fire {
  flex: none;
  width: 44px;
  height: 44px;
  background: #1a0808;
  border: 3px solid;
  border-color: #c04040 #600 #600 #c04040;
  color: var(--red);
  font-size: 18px;
  line-height: 1;
  display: grid;
  place-items: center;
}
.fire:active { transform: translateY(2px); }
.fire[disabled] { border-color: #444 #222 #222 #444; color: #555; background: #222; cursor: default; }
.task.done .fire { color: var(--green); border-color: #3a8a4a #144 #144 #3a8a4a; background: #082010; }
.task .body { flex: 1; min-width: 0; cursor: pointer; }
.task .title {
  font-size: 10px;
  color: #fff;
  word-break: break-word;
  text-shadow: 1px 1px 0 #000;
}
.task.done .title { text-decoration: line-through; }
.task .meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 7px;
  color: #cfd2dc;
  margin-top: 6px;
}
.tag { padding: 2px 4px; background: #000; }
.tag.easy { color: #b8c070; }
.tag.med { color: #ff7070; }
.tag.hard { color: #80a8ff; }
.tag.boss { color: #e090ff; }
.pts { color: var(--gold); }
.fire-streak { color: #ffa040; }
.prog { width: 100%; height: 4px; background: #000; margin-top: 6px; }
.prog i { display: block; height: 100%; background: var(--red); }
.undo {
  flex: none;
  background: none;
  border: 2px solid #777;
  color: #ccc;
  width: 30px;
  height: 30px;
  font-size: 12px;
}
.empty {
  text-align: center;
  color: var(--dim);
  padding: 24px 10px;
  font-size: 8px;
  line-height: 2;
}

/* ---------- buttons/forms ---------- */
.btn {
  background: var(--hud);
  border: 3px solid;
  border-color: var(--hud-l) var(--hud-d) var(--hud-d) var(--hud-l);
  padding: 10px 12px;
  color: #fff;
  text-shadow: 1px 1px 0 #000;
}
.btn:active { border-color: var(--hud-d) var(--hud-l) var(--hud-l) var(--hud-d); }
.btn.red { background: #7a1010; border-color: #c04040 #3a0000 #3a0000 #c04040; }
.btn.gold { background: #8a6a10; border-color: #e0c050 #4a3000 #4a3000 #e0c050; }
.btn.green { background: #146a2a; border-color: #4ac06a #043010 #043010 #4ac06a; }
.btn[disabled] { opacity: 0.4; cursor: default; }
.btn.block { width: 100%; }

input[type=text], input[type=number] {
  width: 100%;
  background: #000;
  border: 2px solid var(--hud-l);
  color: #fff;
  padding: 10px;
  font-size: 11px;
  outline: none;
  border-radius: 0;
}
input:focus { border-color: var(--gold); }
label.f { display: block; font-size: 8px; color: var(--gold); margin: 14px 0 6px; }
textarea {
  width: 100%;
  background: #000;
  border: 2px solid var(--hud-l);
  color: #fff;
  padding: 10px;
  font-size: 9px;
  line-height: 1.7;
  font-family: var(--font);
  outline: none;
  border-radius: 0;
  resize: vertical;
}
textarea:focus { border-color: var(--gold); }
/* mission details under the title */
.task .notes { font-size: 7px; color: #c4c8d2; line-height: 1.8; margin-top: 4px; white-space: pre-wrap; word-break: break-word; }
.off-note { display: block; width: 100%; text-align: center; font-size: 7px; color: var(--dim); margin: 2px 0 6px; }
.off-note:hover { color: #fff; }

.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button {
  flex: 1 1 auto;
  background: #000;
  border: 2px solid #444;
  padding: 8px 6px;
  font-size: 8px;
  color: var(--dim);
  min-width: 52px;
}
.seg button.on { border-color: var(--gold); color: #fff; background: #2a2000; }
.seg.days button { min-width: 0; flex: 1; padding: 8px 0; }

/* ---------- FAB / tabs / HUD ---------- */
#fab {
  position: absolute;
  right: 14px;
  bottom: calc(118px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  font-size: 26px;
  background: #7a1010;
  color: #fff;
  border: 4px solid;
  border-color: #e05050 #3a0000 #3a0000 #e05050;
  box-shadow: 3px 3px 0 #000;
  z-index: 5;
  line-height: 1;
}
#fab:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 #000; }

#tabs {
  display: flex;
  flex: none;
  background: #000;
  gap: 2px;
  padding: 2px;
}
#tabs button {
  flex: 1;
  background: var(--stone-d);
  border: 2px solid #3a3a42;
  color: var(--dim);
  padding: 8px 2px;
  font-size: 7px;
}
#tabs button.on { color: var(--gold); background: var(--stone); border-color: var(--stone-l); }

#hud {
  flex: none;
  display: flex;
  gap: 3px;
  background: var(--hud);
  border-top: 3px solid var(--hud-l);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
#hud .panel {
  flex: 1 1 0;
  min-width: 0;
  background: var(--panel);
  border: 2px solid;
  border-color: var(--hud-d) var(--hud-l) var(--hud-l) var(--hud-d);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 1px;
  gap: 4px;
}
#hud .lbl { font-size: 6px; color: #b8c4e8; letter-spacing: 0; }
#hud b { font-size: 11px; color: #fff; text-shadow: 2px 2px 0 #000; white-space: nowrap; }
#hud b.gold { color: var(--gold); }
#hud .face { flex: 0 0 auto; padding: 2px; background: #000; }
#face { height: 64px; width: auto; aspect-ratio: 32 / 38; image-rendering: pixelated; display: block; }
#hud .wide { display: none; }
#hud .mute { flex: 0 0 26px; color: var(--gold); font-size: 12px; padding: 0; }
#hud .mute.off { color: #555; text-decoration: line-through; }

@media (min-width: 560px) {
  body { font-size: 11px; }
  #hud .wide { display: flex; flex-basis: 0; flex-grow: 1.4; }
  #hud .lbl { font-size: 7px; }
  #hud b { font-size: 13px; }
  #face { height: 76px; }
  #floor-tag { font-size: 8px; }
}

/* ---------- modal + overlay ---------- */
#modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#modal .box {
  background: var(--hud-d);
  border: 4px solid var(--hud-l);
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 560px) { #modal { align-items: center; } }
#modal h3 { margin: 0 0 6px; color: var(--gold); font-size: 12px; }
.row { display: flex; gap: 8px; margin-top: 18px; }
.row .btn { flex: 1; }
.hint { font-size: 7px; color: var(--dim); margin-top: 6px; line-height: 1.8; }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  overflow-y: auto;
}
#overlay .logo {
  font-size: clamp(20px, 7vw, 40px);
  line-height: 1.3;
  color: #e02020;
  text-shadow: 3px 3px 0 #6a0000, 6px 6px 0 #000;
  margin: 0 0 6px;
}
#overlay .logo span { color: var(--gold); text-shadow: 3px 3px 0 #6a4a00, 6px 6px 0 #000; }
#overlay .sub { color: #8ab0ff; font-size: 9px; margin-bottom: 26px; }
#overlay .brief { max-width: 440px; text-align: left; font-size: 8px; line-height: 2.1; color: #ccd; margin: 0 auto 18px; }
#overlay .brief b { color: var(--gold); font-weight: normal; }
#overlay form { width: 100%; max-width: 360px; }
#overlay .check { display: flex; gap: 10px; align-items: center; font-size: 8px; margin: 14px 0 20px; text-align: left; }
#overlay .check input { width: 18px; height: 18px; accent-color: #e02020; }
.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse-slow { 50% { opacity: 0.55; } }

.tally { width: 100%; max-width: 380px; font-size: 11px; }
.tally h1 { color: var(--gold); font-size: 18px; margin: 0 0 24px; text-shadow: 3px 3px 0 #000; line-height: 1.4; }
.tally .line { display: flex; justify-content: space-between; margin: 12px 0; }
.tally .line b { color: #fff; font-weight: normal; }
.tally .bj { margin: 0 auto 18px; width: 128px; height: 152px; image-rendering: pixelated; display: block; border: 3px solid var(--hud-l); }

/* ---------- stats ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { background: var(--panel); border: 2px solid var(--hud-l); padding: 8px; }
.stat span { display: block; font-size: 7px; color: var(--dim); }
.stat b { font-size: 13px; color: #fff; font-weight: normal; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 90px; background: #000; padding: 6px; border: 2px solid var(--hud-l); }
.chart div { flex: 1; background: var(--red); min-height: 2px; position: relative; }
.chart div.today { background: var(--gold); }
.chart-days { display: flex; gap: 3px; padding: 2px 8px; font-size: 6px; color: var(--dim); }
.chart-days span { flex: 1; text-align: center; }

.reward {
  display: flex; align-items: center; gap: 10px;
  background: var(--stone); border: 3px solid;
  border-color: var(--stone-l) var(--stone-d) var(--stone-d) var(--stone-l);
  padding: 8px; margin-bottom: 6px;
}
.reward .body { flex: 1; min-width: 0; cursor: pointer; }
.reward .title { color: #fff; word-break: break-word; text-shadow: 1px 1px 0 #000; }
.reward .cost { color: var(--gold); font-size: 8px; margin-top: 4px; }
.loot { font-size: 8px; color: var(--dim); padding: 4px 0; border-bottom: 1px dashed #335; display: flex; justify-content: space-between; gap: 8px; }
.opt { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px dashed #2a5a5a; gap: 10px; }
.opt input[type=range] { width: 50%; accent-color: var(--gold); }
.toggle { min-width: 64px; }

/* ---------- streak shield ---------- */
#hud .panel { position: relative; }
#hud .panel.shielded::after {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 8px;
  height: 9px;
  background: linear-gradient(90deg, #8ac4ff 50%, #3a7ae0 50%);
  border: 1px solid #fff;
  border-radius: 1px 1px 50% 50%;
  box-shadow: 0 0 4px #6ab0ff;
}
.shield-icon {
  display: inline-block;
  width: 10px;
  height: 11px;
  vertical-align: -1px;
  background: linear-gradient(90deg, #8ac4ff 50%, #3a7ae0 50%);
  border: 1px solid #fff;
  border-radius: 1px 1px 50% 50%;
}
.reward.shield-card { background: #26304a; border-color: #5a7ac0 #121a30 #121a30 #5a7ac0; }

/* ---------- overdue: a slow red pulse ---------- */
.task.overdue {
  animation: overdue-pulse 2.6s ease-in-out infinite;
  border-color: #c04040 #4a1010 #4a1010 #c04040;
}
@keyframes overdue-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 50, 50, 0); background: var(--stone); }
  50% { box-shadow: 0 0 14px 2px rgba(255, 50, 50, 0.55); background: #5a3a3e; }
}
.task.overdue .fire { animation: overdue-fire 2.6s ease-in-out infinite; }
@keyframes overdue-fire { 50% { background: #4a0c0c; color: #ff8080; } }
.tag.overdue-tag { color: #fff; background: #b01818; }
@media (prefers-reduced-motion: reduce) {
  .task.overdue, .task.overdue .fire { animation: none; box-shadow: 0 0 10px 1px rgba(255, 50, 50, 0.45); }
}

/* ---------- when & where ---------- */
.plan { color: #9ad0ff; }
.plan-row { display: flex; gap: 6px; }
.plan-row input[type=time] { flex: 0 0 auto; width: 9.5em; }
.plan-row input[type=text] { flex: 1; min-width: 0; }
input[type=time] {
  background: #000;
  border: 2px solid var(--hud-l);
  color: #fff;
  padding: 9px 6px;
  font-family: var(--font);
  font-size: 10px;
  border-radius: 0;
  color-scheme: dark;
}

/* ---------- crew ---------- */
.crew-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 2px solid var(--hud-l);
  padding: 8px;
  margin-bottom: 6px;
}
.crew-row.me { border-color: var(--gold); background: #1e2a10; }
.crew-row .rank { font-size: 14px; color: var(--gold); width: 22px; text-align: center; flex: none; }
.crew-row .who { flex: 1; min-width: 0; }
.crew-row .nm { color: #fff; font-size: 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crew-row .nm small { color: var(--gold); font-size: 7px; }
.crew-row .bar { height: 6px; margin: 5px 0 4px; border-width: 1px; }
.crew-row .bar i { background: linear-gradient(#7dff9a, #2a9a4a); }
.crew-row .sub { font-size: 6px; color: var(--dim); }
.crew-row .nums { flex: none; text-align: right; display: flex; flex-direction: column; gap: 2px; }
.crew-row .nums b { font-size: 12px; color: var(--gold); font-weight: normal; }
.crew-row .nums small { font-size: 6px; color: var(--dim); }
.crew-row .nums span { font-size: 6px; color: #ffa040; }
.crew-code {
  font-size: 20px;
  letter-spacing: 3px;
  text-align: center;
  color: var(--gold);
  background: #000;
  border: 2px dashed var(--gold);
  padding: 12px;
  text-shadow: 2px 2px 0 #6a4a00;
}
#tabs button { font-size: 6px; }
@media (min-width: 400px) { #tabs button { font-size: 7px; } }

/* edit / undo buttons on each mission row */
.row-btns { display: flex; flex-direction: column; gap: 4px; flex: none; }
.undo.edit { color: var(--gold); border-color: #8a7a40; display: grid; place-items: center; }
.undo.edit:hover, .undo.edit:focus-visible { background: #2a2400; }

/* ---------- hero builder ---------- */
#hud .face { cursor: pointer; }
#hud .face:hover { outline: 2px solid var(--gold); }
.hero-preview { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 8px 0 0; }
.hero-preview canvas { width: 64px; height: 76px; image-rendering: pixelated; background: #000; border: 2px solid var(--hud-l); }
.hero-preview canvas.big { width: 96px; height: 114px; border-color: var(--gold); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 34px; height: 34px; border: 3px solid #000; outline: 2px solid #444; padding: 0; }
.swatch.on { outline: 3px solid var(--gold); }

/* ---------- cutscenes ---------- */
.cutscene { width: 100%; max-width: 560px; text-align: center; cursor: pointer; }
.cutscene canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  border: 3px solid var(--hud-l);
  display: block;
  margin: 0 auto 16px;
}
.cs-title { font-size: clamp(16px, 5vw, 24px); color: var(--gold); text-shadow: 3px 3px 0 #000; margin-bottom: 8px; }
.cutscene.dusk .cs-title { color: #ffb060; }
.cs-sub { font-size: 7px; color: #8ab0ff; line-height: 2; margin-bottom: 18px; }
.cs-quote {
  margin: 0 auto;
  max-width: 480px;
  min-height: 6.4em;
  font-size: 10px;
  line-height: 2.1;
  color: #fff;
  text-align: left;
}
.cs-caret { display: inline-block; width: 7px; height: 10px; background: var(--gold); margin-left: 3px; animation: blink 0.8s steps(2) infinite; vertical-align: -1px; }
.cs-author { font-size: 8px; color: var(--gold); text-align: right; max-width: 480px; margin: 8px auto 20px; min-height: 1em; }
.cs-btn { min-width: 220px; }
.cs-skip { margin-top: 10px; }

/* final boss */
.tag.boss-tag { color: #fff; background: #6a1a8a; box-shadow: 0 0 6px #c040ff; }

/* section color = guard uniform color */
.freq-chip { display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px; border: 2px solid #000; box-shadow: 1px 1px 0 #000; }
.freq-chip.daily { background: #d04646; }
.freq-chip.weekly { background: #4a76d0; }
.freq-chip.monthly { background: #4aa04a; }
.freq-chip.yearly { background: #8048b0; }
.freq-chip.once { background: #e8903c; }

/* health panel: flashes green when you heal, red when you're hit */
#h-today.low { color: #ff5050; }
#hud .panel.heal { animation: hp-heal 0.6s ease-out; }
#hud .panel.hurt { animation: hp-hurt 0.6s ease-out; }
@keyframes hp-heal { 0% { background: #1e6a2a; } 100% { background: var(--panel); } }
@keyframes hp-hurt { 0% { background: #8a1010; } 100% { background: var(--panel); } }

/* ---------- accounts ---------- */
#overlay .auth { width: 100%; max-width: 380px; text-align: left; }
#overlay .auth h3 { color: var(--gold); font-size: 11px; margin: 0 0 8px; text-align: center; line-height: 1.8; }
#overlay .auth .hint { text-align: center; }
#overlay .auth .btn.block { margin-top: 18px; }
#overlay .auth input { margin-bottom: 2px; }
.dim { color: var(--dim); }
input[type=email], input[type=password] {
  width: 100%; background: #000; border: 2px solid var(--hud-l); color: #fff;
  padding: 10px; font-size: 11px; outline: none; border-radius: 0; font-family: var(--font);
}
input[type=email]:focus, input[type=password]:focus { border-color: var(--gold); }
.auth-links { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.linkbtn { background: none; border: none; color: #8ab0ff; font-size: 7px; padding: 6px 0; text-decoration: underline; cursor: pointer; }
.linkbtn:hover { color: #fff; }
.auth-msg { font-size: 8px; min-height: 2em; margin-top: 12px; color: var(--red); text-align: center; line-height: 1.8; max-width: 380px; }

.plan-note {
  background: #2a2008; border: 2px solid var(--gold); padding: 10px; margin-bottom: 12px;
  font-size: 7px; line-height: 2; color: #e8d8a0; display: flex; flex-direction: column; gap: 8px;
}
.plan-note b { color: var(--gold); font-weight: normal; }
.plan-note.free { background: #2a1010; border-color: #c04040; }
.task.locked { opacity: 0.45; filter: grayscale(0.7); }
.tag.locked-tag { color: #fff; background: #444; }
/* dailies waiting for the next wing: tap the name to call the guard in */
.tag.summon-tag { color: #000; background: var(--gold); animation: pulse-slow 2.4s ease-in-out infinite; }
.tag.wing-tag { color: #7dff9a; }
.task .body[data-summon] { cursor: pointer; }
.task .body[data-summon]:active { opacity: 0.7; }
