:root {
  --bg: #14161a;
  --panel: #1d2026;
  --line: #363b45;
  --fg: #dfe3ea;
  --dim: #8a93a3;
  --accent: #ffd23f;
  --good: #38d67a;
  --bad: #ff5a5a;
  --warn: #ffa64d;
  --size: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}
[hidden] { display: none !important; }
.dim { color: var(--dim); }
.grow { flex: 1; min-width: 0; }
.note { color: var(--warn); min-height: 1.4em; }

button, input {
  font: inherit;
  color: var(--fg);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
}
button { cursor: pointer; touch-action: manipulation; }
button:disabled { opacity: .45; }
button.primary { background: #2f6f4a; border-color: #3c8a5c; }
button.danger { background: #7a2b2b; border-color: #a33a3a; }
button.small { padding: 6px 10px; font-size: 14px; }
input { width: 100%; }
input:focus { outline: 2px solid #4d7cff; outline-offset: -1px; }

/* ---------------------------------------------------------------- sign in */

#login {
  max-width: 360px;
  margin: 0 auto;
  padding: max(48px, env(safe-area-inset-top)) 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#login h1 { font-size: 22px; margin: 0; }
#login p { margin: 0; }

/* ------------------------------------------------------------------ game */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

#bar, #botRow, #cmdRow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--panel);
}
#bar { border-bottom: 1px solid var(--line); font-size: 14px; }
#mud { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.on { background: var(--good); }
.dot.half { background: var(--warn); }

#vitals {
  display: flex;
  gap: 10px;
  padding: 6px 10px;
  background: var(--panel);
  font-size: 12px;
}
.vit { flex: 1; display: flex; align-items: center; gap: 5px; min-width: 0; }
.vlbl { color: var(--dim); }
.vbar { flex: 1; height: 7px; background: #2a2e36; border-radius: 4px; overflow: hidden; min-width: 18px; }
.vbar i { display: block; height: 100%; width: 0; background: var(--good); }
.vit[data-v="sp"] .vbar i { background: #4d9dff; }
.vit[data-v="ep"] .vbar i { background: var(--accent); }
.vit.low .vbar i { background: var(--bad); }
.vnum { font-variant-numeric: tabular-nums; white-space: nowrap; }

#botRow { border-bottom: 1px solid var(--line); font-size: 14px; }
#botSaid { overflow: hidden; }
#botState { white-space: nowrap; }
#botState.on { color: var(--good); }
#botState.paused { color: var(--warn); }
#botPlan { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ tabs */

#tabs {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
#tabs button {
  flex: 1;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--dim);
  padding: 9px 6px;
  font-size: 14px;
  border-bottom: 2px solid transparent;
}
#tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
#badge {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #000;
  font-size: 12px;
  font-weight: 700;
}
.tab { flex: 1; min-height: 0; display: flex; flex-direction: column; }

#pushBanner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #2b2f38;
  border-bottom: 1px solid var(--accent);
  font-size: 14px;
}

/* ------------------------------------------------------------ bot status */

#statusTab { overflow-y: auto; padding: 10px 10px max(16px, env(safe-area-inset-bottom)); gap: 10px; }
.st-line { font-size: 15px; }
.st-line.paused { color: var(--warn); }
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 0;
}
.tile b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile span { color: var(--dim); font-size: 12px; }
.tile.hot { border-color: var(--accent); }
.tile.hot b { color: var(--accent); }
.tile.low b { color: var(--bad); }
.tile .tbar { display: block; height: 5px; margin-top: 5px; background: #2a2e36; border-radius: 3px; overflow: hidden; }
.tile .tbar i { display: block; height: 100%; width: 0; background: var(--good); }
.tile.sp .tbar i { background: #4d9dff; }
.tile.ep .tbar i { background: var(--accent); }
.tile.low .tbar i { background: var(--bad); }
.st-rates { font-size: 13px; }
.fight {
  background: var(--panel);
  border: 1px solid var(--bad);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 16px;
}
.fight.idle { border-color: var(--line); }
.fight b { font-size: 18px; }
.fight-row { display: flex; align-items: center; gap: 10px; margin-top: 4px; font-size: 13px; }
.fight-row .fbar { flex: 1; height: 7px; background: #2a2e36; border-radius: 4px; overflow: hidden; }
.fight-row .fbar i { display: block; height: 100%; width: 0; background: var(--warn); }
.fight-row .fbar i.low { background: var(--bad); }
.st-item .where { color: var(--dim); }
.st-item .xp { margin-left: auto; color: var(--good); font-variant-numeric: tabular-nums; white-space: nowrap; }
.st-now { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 14px; }
.st-now .lab { color: var(--dim); }
.st-now .old { color: var(--dim); }
.st-visit { font-size: 13px; }
.st-sec { margin-top: 6px; }
.st-sec h3 { font-size: 14px; margin: 8px 0 4px; }
.st-item { display: flex; gap: 8px; font-size: 14px; padding: 3px 0; border-top: 1px solid #23262d; }
.st-item time { color: var(--dim); flex: none; font-variant-numeric: tabular-nums; }
.st-item .end { font-weight: 600; }
.st-item .end.clear { color: var(--good); }
.st-item .end.died, .st-item .end.strong { color: var(--bad); }
.st-item .end.now { color: var(--accent); }
.st-kills { font-size: 14px; line-height: 1.5; }
.st-item.tap { cursor: pointer; }
.st-item.tap:active { background: #23262d; }
.st-item .act { margin-left: auto; padding-left: 8px; color: var(--accent); flex: none; white-space: nowrap; }

#out {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  padding: 4px 8px 8px;
  font: var(--size)/1.3 ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
#lines .ln, #prompt { white-space: pre; min-height: 1.3em; }
#out.wrap #lines .ln, #out.wrap #prompt { white-space: pre-wrap; overflow-wrap: anywhere; }
.ln .note { color: var(--dim); }
.k-echo { color: #7fb4ff; }
.k-local, .k-hint { color: var(--dim); }
.k-warn, .k-err { color: var(--warn); }
.k-good { color: var(--good); }
#prompt { color: var(--fg); }

#newer {
  position: fixed;
  right: 12px;
  bottom: calc(108px + env(safe-area-inset-bottom));
  z-index: 5;
  box-shadow: 0 2px 10px #0008;
}

#cmdRow { padding-bottom: max(6px, env(safe-area-inset-bottom)); }
#cmd { font-family: ui-monospace, Consolas, Menlo, monospace; font-size: 16px; padding: 9px 10px; }
#histBtn { flex: none; padding: 8px 13px; font-size: 16px; }
#histBtn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }

/* One row, scrolled sideways when there are more than fit: a second row
 * would come out of the game's lines on a phone held upright. */
#quick {
  display: flex;
  gap: 6px;
  padding: 6px 10px 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  touch-action: pan-x;
}
#quick::-webkit-scrollbar { display: none; }
.chip, .hcmd {
  font: 14px ui-monospace, "Cascadia Mono", Consolas, Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.chip { flex: none; max-width: 42vw; padding: 7px 12px; border-radius: 16px; }
.chip.edit { color: var(--dim); font-family: inherit; }
.chip.held, .hcmd.held { background: #24375a; border-color: #4d7cff; }

#histBox {
  flex: none;
  max-height: 45%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-top: 1px solid var(--accent);
}
.hhead { font-size: 12px; padding: 6px 10px 2px; }
#histList { overflow-y: auto; padding: 0 10px 4px; }
#histNone { margin: 4px 10px 8px; font-size: 14px; }
.hrow { display: flex; gap: 6px; align-items: center; padding: 3px 0; }
.hcmd { flex: 1; min-width: 0; text-align: left; padding: 8px 10px; }
.hstar { flex: none; padding: 8px 11px; color: var(--dim); }
.hstar.on { color: var(--accent); }

.qrow { display: flex; gap: 6px; align-items: center; margin: 6px 0; }
/* 16px: an iPhone zooms the page into any field smaller than that. */
.qrow input { padding: 8px; font-size: 16px; }
.qrow .qlabel { flex: 0 0 27%; min-width: 0; }
.qrow .qcmd { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, Menlo, monospace; }
.qrow button { flex: none; padding: 8px 10px; }

/* ----------------------------------------------------------- what happened */

#toast {
  position: fixed;
  left: 10px;
  right: 10px;
  top: calc(8px + env(safe-area-inset-top));
  z-index: 20;
  background: #2b2f38;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 4px 18px #000a;
}
#toast b { display: block; }
#toast .hint { display: block; color: var(--dim); font-size: 13px; margin-top: 4px; }

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: #000a;
  display: flex;
  align-items: flex-end;
}
.sheet-box {
  width: 100%;
  max-height: 88%;
  overflow-y: auto;
  background: var(--bg);
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  padding: 12px 14px max(16px, env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-box section { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.sheet-box p { margin: 6px 0; font-size: 14px; }
.lbl { font-weight: 600; margin-bottom: 6px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chk { display: flex; align-items: center; gap: 6px; }
.chk input { width: auto; }
#alerts { margin: 0; padding-left: 22px; font-size: 14px; }
#alerts li { margin: 4px 0; }
#alerts .when { color: var(--dim); font-size: 12px; }
#alerts .reply { margin-left: 8px; vertical-align: baseline; }

@media (min-width: 700px) {
  #login { padding-top: 80px; }
  .sheet-box { max-width: 560px; margin: 0 auto; border: 1px solid var(--line); }
  .sheet { justify-content: center; }
}
