:root {
  --bg: #0d1714;
  --panel: #15231e;
  --panel2: #1b2c26;
  --line: #2a4037;
  --text: #f3f4ed;
  --muted: #9aaca4;
  --gold: #efc264;
  --green: #65d29a;
  --red: #ff766c;
  --amber: #ffbe5c;
  --blue: #77b9ff;
  --safeT: env(safe-area-inset-top, 0px);
  --safeB: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; width: 100%; min-height: 100%;
  background: var(--bg); color: var(--text);
  font-family: Inter, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body { overscroll-behavior: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

/* ---------------------------------------------------------------- shell */

.boot { height: 100vh; display: grid; place-content: center; text-align: center; gap: 8px; }
.boot .crest { font-size: 52px; color: var(--gold); }
.boot b { font-size: 20px; }
.boot small, .muted { color: var(--muted); }

.shell {
  min-height: 100%;
  padding: calc(12px + var(--safeT)) 12px calc(92px + var(--safeB));
  max-width: 520px; margin: auto;
}

.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
/* Tapping the crest opens the rules again. The walkthrough explains them once;
   this is where a player who has been away for a fortnight goes. */
.brand {
  display: flex; align-items: center; gap: 9px; min-width: 0;
  border: 0; background: none; color: inherit; padding: 0; text-align: left;
}
.brand i {
  width: 34px; height: 34px; border-radius: 12px; flex: none;
  background: linear-gradient(145deg, #315e49, #172a21);
  display: grid; place-items: center; color: var(--gold); font-style: normal;
}
.brand b { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand small { display: block; color: var(--muted); font-size: 11px; }

.orders {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; font-weight: 800; color: var(--gold); background: var(--panel); flex: none;
}
.orders .dim { color: var(--muted); font-weight: 500; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  padding: 6px 8px calc(6px + var(--safeB));
  background: #0c1512ee; border-top: 1px solid var(--line); backdrop-filter: blur(16px);
}
.tabbar { max-width: 520px; margin: auto; display: grid; grid-template-columns: repeat(5, 1fr); }
.tab {
  border: 0; background: transparent; color: var(--muted);
  display: grid; gap: 2px; place-items: center; padding: 7px 2px; font-size: 9px;
}
.tab i { font-style: normal; font-size: 20px; }
.tab.active { color: var(--gold); }
/* Held shut while the walkthrough is running, so the only live control on
   screen is the one the current step is pointing at. */
.tab.locked { opacity: .22; pointer-events: none; }

/* ---------------------------------------------------------------- hero */

.hero {
  position: relative; min-height: 168px; overflow: hidden;
  border: 1px solid var(--line); border-radius: 22px; padding: 18px;
  background:
    radial-gradient(circle at 83% 25%, var(--raceGlow, rgba(101,210,154,.18)), transparent 45%),
    linear-gradient(145deg, #1c3028, #122019);
}
.hero .copy { position: relative; z-index: 1; max-width: 60%; }
.hero h1 { font-size: 23px; margin: 3px 0; }
.hero p { margin: 0; color: var(--muted); font-size: 12px; }
.hero .tag {
  display: inline-block; padding: 4px 8px; border-radius: 99px;
  background: #0005; color: var(--gold); font-size: 10px; font-weight: 800;
}
.heroArt {
  position: absolute; right: -6px; bottom: -6px;
  width: 158px; height: 158px; pointer-events: none;
  filter: drop-shadow(0 10px 14px #0007);
}

/* A sticker slot holds a PNG poster and, once it is ready, a canvas on top.
   The poster is what makes the portrait appear instantly and what remains if
   the animation never loads. */
.stickerSlot { position: relative; display: block; }
.stickerSlot img, .stickerSlot canvas {
  width: 100%; height: 100%; object-fit: contain; display: block;
}
.stickerSlot canvas {
  position: absolute; inset: 0; opacity: 0; transition: opacity .18s;
}
.stickerSlot.live canvas { opacity: 1; }
.stickerSlot.live .poster { opacity: 0; }
.poster { transition: opacity .18s; }

.linkish {
  margin-top: 8px; padding: 0; border: 0; background: none;
  color: var(--blue); font-size: 11px; text-decoration: underline;
}

/* ---------------------------------------------------------------- resources */

.resources { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin: 10px 0; }
.resource {
  padding: 9px 7px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); min-width: 0;
}
.resource small {
  display: block; color: var(--muted); font-size: 9px;
  text-transform: uppercase; letter-spacing: .06em;
}
.resource b {
  display: block; margin-top: 3px; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.resource em {
  display: block; margin-top: 2px; font-style: normal;
  font-size: 10px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.resource.bad { border-color: #6d2f2b; background: #1e1615; }
.resource.bad em { color: var(--red); }
.resource.warn em { color: var(--amber); }

/* ---------------------------------------------------------------- cards */

.sectionHead { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 20px 2px 9px; }
.sectionHead h2 { font-size: 15px; margin: 0; }
.sectionHead small { color: var(--muted); font-size: 11px; }

.card {
  border: 1px solid var(--line); border-radius: 17px; background: var(--panel);
  padding: 14px; margin-bottom: 9px; color: var(--text); text-align: left; width: 100%;
}
.card.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0; border: 0; background: none; margin: 0; }
.card h3 { font-size: 14px; margin: 0 0 4px; }
.card p { font-size: 12px; color: var(--muted); line-height: 1.45; margin: 0 0 4px; }
.card .right { text-align: right; flex: none; }
.card .right b { font-size: 16px; }
.card .right em { display: block; font-style: normal; font-size: 10px; color: var(--muted); }
.card.action { display: block; }
.card.dim { opacity: .55; }
.card.hint p { color: var(--muted); }

.metric { font-weight: 800; color: var(--gold); white-space: nowrap; }
.metric.short { color: var(--red); }

.bar { height: 6px; background: #09110e; border-radius: 99px; overflow: hidden; margin: 10px 0; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; }

.statline {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12px;
}
.statline:last-child { border-bottom: 0; }
.statline span { color: var(--muted); }
.statline b { text-align: right; }
.statline b.short { color: var(--red); }
.statline.total { border-top: 1px solid var(--line); border-bottom: 0; margin-top: 2px; }
.statline.total b { color: var(--gold); font-size: 14px; }
.statline.effect b { color: var(--green); font-weight: 600; }

.statCard { display: block; }
.tapHint { display: block; margin-top: 10px; font-size: 11px; color: var(--blue); }

.warnCard { border-color: #6b5220; background: #1d1a12; }
.warnText { color: var(--amber); font-size: 12px; line-height: 1.45; margin: 0 0 6px; }
.hintText { color: var(--muted); font-size: 11.5px; line-height: 1.5; margin: 10px 0 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.empty { text-align: center; padding: 26px 14px; color: var(--muted); }

.news em { display: block; font-style: normal; font-size: 10px; color: var(--muted); margin-top: 5px; }
.news.win { border-left: 3px solid var(--green); }
.news.loss { border-left: 3px solid var(--red); }

/* ---------------------------------------------------------------- advice */

.advice.bad { border-left: 3px solid var(--red); }
.adviceTop { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.adviceTop h3 { flex: 1; }
.adviceActions { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }

.btn { border: 0; border-radius: 12px; padding: 11px 14px; background: var(--green); color: #092016; font-weight: 800; }
.btn.secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--red); color: #270806; }
.btn.danger.holding { background: #b8433a; color: #fff; }
.btn.small { padding: 8px 12px; font-size: 12px; border-radius: 10px; }
.btn.big { padding: 15px; font-size: 15px; margin-top: 18px; }
.btn:disabled { opacity: .42; }
.wide { width: 100%; }

.goalPick {
  border: 1px solid var(--line); background: var(--panel); color: var(--gold);
  border-radius: 999px; padding: 6px 11px; font-size: 11px; font-weight: 700;
}

/* ---------------------------------------------------------------- world */

.avatar { width: 46px; height: 46px; object-fit: contain; border-radius: 13px; background: #0d1714; flex: none; }
.rank { display: flex; align-items: center; gap: 10px; }
.rank .grow, .card.row .grow { flex: 1; min-width: 0; }
.badge { font-size: 9px; border: 1px solid var(--line); padding: 4px 7px; border-radius: 99px; color: var(--muted); flex: none; }
.badge.bad { color: var(--red); border-color: #6d2f2b; }

.target .card.row { align-items: flex-start; }
.noIntel { display: block; font-style: normal; font-size: 11px; color: var(--amber); margin-top: 3px; }
.freshIntel { display: block; font-style: normal; font-size: 11px; color: var(--green); margin-top: 3px; }
.staleIntel { display: block; font-style: normal; font-size: 11px; color: var(--muted); margin-top: 3px; }

.report.good { border-left: 3px solid var(--green); }
.report.bad { border-left: 3px solid var(--red); }
.reportHead { text-align: center; padding-bottom: 6px; }
.reportHead h2 { margin: 6px 0 4px; }
.reportHead.good h2 { color: var(--green); }
.reportHead.bad h2 { color: var(--red); }
.reportArt { width: 132px; height: 132px; margin: 0 auto; }
.reportArt img, .reportArt svg { width: 100%; height: 100%; object-fit: contain; }

/* ---------------------------------------------------------------- war */

.warCard { border-color: var(--red); background: #1d1512; }
.warTag { color: var(--red); }
.goodText { color: var(--green); font-size: 12px; margin: 0 0 12px; }

.warBars { display: grid; gap: 8px; margin: 12px 0 6px; }
.warBar {
  display: grid; grid-template-columns: 84px 1fr 54px; align-items: center; gap: 8px;
  font-size: 11px; color: var(--muted);
}
.warBar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.warBar i {
  display: block; height: 10px; border-radius: 99px; background: var(--green);
  min-width: 3px; box-shadow: inset 0 0 0 1px #0003;
}
.warBar.them i { background: var(--red); }
.warBar b { text-align: right; color: var(--text); }

.relation.hostile { border-left: 3px solid var(--red); }
.relation.unfriendly { border-left: 3px solid var(--amber); }
.relation.war { border-left: 3px solid var(--red); background: #1d1512; }
.relation.recovery { border-left: 3px solid var(--blue); }
.bar.tension i { background: linear-gradient(90deg, var(--amber), var(--red)); }

.badge.gold { color: var(--gold); border-color: var(--gold); }

/* An AI-held seat is labelled, never merely hinted at. A player should be able
   to tell at a glance who is a person, without hunting for a coloured dot. */
.aiTag {
  display: inline-block; padding: 1px 5px; border-radius: 5px;
  background: #6b4a12; color: var(--gold);
  font-size: 9px; font-weight: 800; letter-spacing: .06em;
}
.target.atwar { border-color: var(--red); }
.pick.off { opacity: .45; }

/* ---------------------------------------------------------------- rankings */

.rankNum {
  flex: none; width: 26px; text-align: center;
  font-weight: 800; font-size: 13px; color: var(--muted);
}
.rank.mine { border-color: var(--gold); background: #1a2a1f; }
.rank.mine .rankNum { color: var(--gold); }
.avatar.small { width: 34px; height: 34px; border-radius: 10px; }

/* ---------------------------------------------------------------- testing */

/* Deliberately plain and slightly ugly. It is not part of the game and should
   not be mistaken for it. */
.devPanel { border-style: dashed; border-color: #4a5f55; background: #121b18; }
.devPanel > p { margin-bottom: 12px; }
.devTool {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.devTool b { display: block; font-size: 13px; }
.devTool small { display: block; color: var(--muted); font-size: 11px; line-height: 1.45; margin-top: 3px; }
.devTool .btn { flex: none; }

/* ---------------------------------------------------------------- modals */

.modalBack { position: fixed; inset: 0; z-index: 40; background: #0009; display: flex; align-items: flex-end; }
.modal {
  width: 100%; max-width: 520px; margin: auto;
  background: #17251f; border: 1px solid var(--line); border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(18px + var(--safeB)); max-height: 88vh; overflow: auto;
}
.modal h2 { margin: 0 0 6px; font-size: 19px; }
.modal > p { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

.field { margin: 12px 0; }
.field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select {
  width: 100%; padding: 12px; border: 1px solid var(--line);
  border-radius: 12px; background: #0c1713; color: var(--text); outline: 0;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }

.presetRow { display: grid; grid-auto-flow: column; gap: 8px; margin: 4px 0 12px; }
.preset {
  padding: 9px 6px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text); font-weight: 700; font-size: 13px;
  display: grid; gap: 1px; justify-items: center;
}
/* Shares of what is available, with the resulting figure under each one so the
   player is never guessing what "50%" comes to. */
.preset b { font-size: 13px; }
.preset small { font-size: 10px; font-weight: 500; color: var(--muted); }
.preset.on small { color: var(--gold); }
.preset.on { border-color: var(--gold); color: var(--gold); background: #1f2a1f; }

.quote { border: 1px solid var(--line); border-radius: 14px; background: #0f1a16; padding: 4px 12px; }
.verdict {
  margin: 10px 0 4px; padding: 9px; border-radius: 10px; text-align: center;
  font-weight: 800; font-size: 13px; background: var(--panel2); color: var(--muted);
}
.verdict.good { background: #16301f; color: var(--green); }
.verdict.warn { background: #33290f; color: var(--amber); }
.verdict.bad { background: #331714; color: var(--red); }

.pickList { display: grid; gap: 8px; margin-bottom: 4px; }
.pick {
  display: block; text-align: left; padding: 12px;
  border: 1px solid var(--line); border-radius: 13px; background: var(--panel); color: var(--text);
}
.pick b { display: block; font-size: 13px; }
.pick small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.pick .metric { display: block; margin-top: 6px; font-size: 12px; }
.pick.on { border-color: var(--gold); }

/* ---------------------------------------------------------------- onboarding */

.onboard {
  min-height: 100vh; max-width: 520px; margin: auto;
  padding: calc(18px + var(--safeT)) 14px calc(24px + var(--safeB));
}
.onboard h1 { font-size: 28px; margin: 14px 0 6px; }
.onboard > p { color: var(--muted); font-size: 13px; line-height: 1.55; }

.seasonEnd { border-color: var(--gold); background: #1c2a1f; margin-bottom: 16px; }

.starterList { display: grid; gap: 8px; }
.starter {
  display: flex; align-items: center; gap: 12px; text-align: left; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 15px; background: var(--panel); color: var(--text);
}
.starter .art { width: 46px; height: 46px; flex: none; }
.starter b { display: block; font-size: 13px; }
.starter small { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.45; margin-top: 2px; }
.starter.selected { border-color: var(--gold); }

/* Height is pinned in JS to the tallest character write-up, so switching
   between them never reflows the page. The grid keeps it from collapsing if
   that measurement cannot run. */
.infoBox { display: grid; align-content: start; gap: 2px; }
.infoBox .placeholder { color: var(--muted); }
.infoBox h3 { margin-bottom: 6px; }

.raceGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 12px; }
.racePick {
  border: 1px solid var(--line); border-radius: 15px; background: var(--panel);
  padding: 7px; color: var(--text); text-align: center;
}
.racePick .art { display: block; width: 100%; aspect-ratio: 1; }
.racePick b { display: block; font-size: 10px; }
/* A quiet cue that these do something when you point at them. */
@media (hover: hover) and (pointer: fine) {
  .racePick, .starter { transition: transform .12s, border-color .12s; }
  .racePick:hover, .starter:hover { transform: translateY(-2px); border-color: var(--gold); }
}
.racePick.selected { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold); }

.callingPick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.callingPick button {
  padding: 12px; border: 1px solid var(--line); border-radius: 13px;
  background: var(--panel); color: var(--text); text-align: left;
}
.callingPick button b, .callingPick button small { display: block; }
.callingPick button small { color: var(--muted); margin-top: 3px; font-size: 11px; }
.callingPick button.selected { border-color: var(--gold); }

/* ---------------------------------------------------------------- coach marks */

#coach { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
/* Four panels form the dim, leaving a real hole so the highlighted control is
   still tappable and the rest of the screen is not. */
.coachVeil { position: absolute; left: 0; right: 0; background: #050a08d9; pointer-events: auto; }
.coachRing {
  position: absolute; border-radius: 16px; pointer-events: none;
  box-shadow: 0 0 0 2px var(--gold), 0 0 22px 4px #efc26455;
}
.coachCard {
  position: absolute; left: 12px; right: 12px; max-width: 496px;
  margin: auto; pointer-events: auto;
  background: #1b2c26; border: 1px solid var(--gold); border-radius: 18px; padding: 15px;
  box-shadow: 0 14px 34px #000a;
}
.coachCard.centre { top: 50%; transform: translateY(-50%); }
.coachCard h3 { margin: 6px 0 6px; font-size: 16px; }
.coachCard p { margin: 0; font-size: 13px; line-height: 1.55; color: #d6e2db; }
.coachCount { font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--gold); }
/* The step you just finished, acknowledged inside the card that tells you what
   is next. A toast for this used to land on top of this very card. */
.coachDone {
  display: block; margin-bottom: 6px;
  font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: var(--green);
}
.coachDone::before { content: "\2713  "; }
.coachBtns { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.coachWait { font-size: 11.5px; color: var(--gold); font-weight: 700; }

/* ---------------------------------------------------------------- toast */

#toast {
  position: fixed; z-index: 70; left: 50%; bottom: calc(88px + var(--safeB));
  transform: translate(-50%, 20px); width: min(90%, 400px);
  padding: 12px 14px; border-radius: 12px;
  background: #eef7ef; color: #13231b; font-size: 12.5px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #ffd5d1; color: #49110d; }
/* Out of the coach card's way while the walkthrough is running. */
#toast.top { top: calc(12px + var(--safeT)); bottom: auto; transform: translate(-50%, -20px); }
#toast.top.show { transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 360px) {
  .resources { grid-template-columns: 1fr 1fr; }
  .heroArt { width: 132px; height: 132px; }
  .hero .copy { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
