/* Glitterhoof: a storybook unicorn after dark. One deliberate dark look, no light theme.
   Layout: the battlefield fills the screen; a bottom tab bar appears as features unlock,
   and opening a tab slides its page in under a shorter arena. */
:root {
  --bg: #1b1420;
  --panel: #271e2e;
  --panel-2: #33283c;
  --line: #4a3c55;
  --fg: #f6efe4;
  --muted: #b8a9c2;
  --accent: #ff7fb8;
  --accent-ink: #2a0f1d;
  --gold: #f2c14e;
  --blood: #e0404d;
  --good: #7fe08a;
  --font-display: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --r: 14px;
  --tabbar: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 500 15px/1.4 var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.num { font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 1100px;
  margin: 0 auto;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  padding-block: 12px 0;
}

/* ------------------------------------------------------------ the battlefield */
.stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.app:not(.paged) .stage { padding-bottom: 12px; }
.app.paged .stage { flex: 0 0 auto; }
.arena-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 240px;
  border-radius: var(--r);
  overflow: hidden;
  background: #2b2233;
}
.app.paged .arena-wrap { flex: none; height: clamp(200px, 36vh, 380px); }
#arena { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }

.hud {
  position: absolute; left: 10px; top: 10px; right: 10px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  pointer-events: none;
}
.hud-left {
  display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: rgba(20, 10, 24, 0.55);
  border-radius: 14px;
  padding: 6px 10px;
  min-width: 0;
}
.hud-label { font: 700 15px/1 var(--font-display); color: #fff; }
.hud-sub { font-size: 12px; font-weight: 800; color: rgba(255, 255, 255, 0.75); }
.wave-pips { display: flex; gap: 4px; align-items: center; }
.pip { width: 12px; height: 7px; border-radius: 99px; background: rgba(255, 255, 255, 0.25); }
.pip.done { background: var(--fg); }
.pip.now { background: var(--accent); }
.pip.boss { width: 18px; }
.rank-line { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; color: rgba(255, 255, 255, 0.85); }
.rank-line b { color: #fff; }
.xpbar { display: inline-block; width: 64px; height: 6px; border-radius: 99px; background: rgba(255, 255, 255, 0.2); overflow: hidden; }
.xpbar > span { display: block; height: 100%; width: 0; background: #b77bff; border-radius: 99px; transition: width 0.2s; }
.xpbar.big { display: block; width: 100%; height: 10px; background: var(--panel-2); margin: 6px 0 8px; }
.rankcard { background: var(--panel-2); border-radius: 14px; padding: 12px; margin-bottom: 12px; }
.rankcard .xpbar.big { background: rgba(0, 0, 0, 0.3); }
.rankcard .bchip { background: rgba(0, 0, 0, 0.25); }
.rankcard .bchip b { color: var(--gold); font-size: 10px; text-transform: uppercase; }
.rankhead { display: flex; justify-content: space-between; align-items: baseline; font: 700 18px/1.2 var(--font-display); }
.hud-right { display: inline-flex; gap: 6px; align-items: center; pointer-events: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(20, 10, 24, 0.72);
  border-radius: 999px;
  padding: 6px 12px 6px 8px;
  font-weight: 800; font-size: 15px;
  color: #fff;
}
.coin {
  width: 18px; height: 18px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #ffe08a, var(--gold) 60%, #c8901c);
  box-shadow: inset 0 0 0 2px #c8901c;
  flex: none;
}
.hudbtn {
  min-width: 40px; height: 36px;
  border: 0; border-radius: 12px;
  background: rgba(20, 10, 24, 0.72);
  color: #fff; font-weight: 800;
  display: inline-grid; place-items: center;
  cursor: pointer; padding: 0 8px;
}
.hudbtn svg { width: 18px; height: 18px; fill: currentColor; }
.hudbtn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.pop { animation: pop 0.6s ease-out 2; }
@keyframes pop { 50% { transform: scale(1.15); box-shadow: 0 0 0 4px rgba(255, 127, 184, 0.45); } }

.farm-chip {
  position: absolute; right: 10px; top: 54px;
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(20, 10, 24, 0.72);
  border-radius: 999px;
  padding: 4px 4px 4px 12px;
  font-size: 13px; font-weight: 700; color: #fff;
  max-width: calc(100% - 20px);
}
.farm-chip button {
  border: 0; border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font-weight: 800; padding: 6px 12px; cursor: pointer; min-height: 32px; white-space: nowrap;
}

.banner {
  position: absolute; left: 50%; top: 26%;
  transform: translate(-50%, 0);
  font: 700 clamp(20px, 4vw, 34px)/1.1 var(--font-display);
  color: #fff;
  text-align: center;
  text-shadow: 0 3px 0 rgba(20, 10, 24, 0.75);
  pointer-events: none;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
}
.banner.show { opacity: 1; transform: translate(-50%, -6px); }
.banner.bad { color: #ff8a95; }
.banner.good { color: #ffe08a; }

.loot-feed {
  position: absolute; left: 10px; bottom: 10px;
  display: flex; flex-direction: column-reverse; gap: 4px;
  pointer-events: none;
  max-width: 70%;
}
.loot {
  background: rgba(20, 10, 24, 0.78);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 13px; font-weight: 800;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  animation: loot-in 0.25s ease-out;
}
.loot small { color: var(--muted); font-weight: 700; }
@keyframes loot-in { from { transform: translateX(-12px); opacity: 0; } }

/* overlays */
.overlay {
  position: absolute; inset: 0;
  background: rgba(16, 9, 20, 0.72);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px;
  padding: 14px;
  text-align: center;
}
.overlay h2 { margin: 0; font: 700 clamp(20px, 3vw, 28px)/1.1 var(--font-display); text-wrap: balance; }
.overlay p { margin: 0; color: var(--muted); max-width: 46ch; }
.unlock-card {
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 18px;
  padding: 18px 18px 14px;
  max-width: 380px;
  display: flex; flex-direction: column; gap: 10px; align-items: center;
}
.unlock-card .eyebrow { font-size: 11px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); }
.boost-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  width: min(100%, 680px);
}
.boost {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  cursor: pointer;
  min-height: 120px;
  justify-content: center;
  transition: transform 0.12s, border-color 0.12s;
}
.boost:hover { transform: translateY(-3px); }
.boost .tier { font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.boost .bname { font: 700 17px/1.15 var(--font-display); text-wrap: balance; }
.boost .bval { font-weight: 800; color: var(--good); }
.boost .key { font-size: 11px; color: var(--muted); }
@media (max-width: 560px) {
  .boost-cards { grid-template-columns: 1fr; }
  .boost { min-height: 0; flex-direction: row; justify-content: space-between; padding: 8px 12px; gap: 10px; }
  .boost .key { display: none; }
}

/* ------------------------------------------------------------ skills */
.skillbar { display: flex; gap: 8px; }
.skill {
  position: relative;
  flex: 1 1 0;
  max-width: 280px;
  min-width: 0;
  min-height: 60px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--panel);
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
}
.skill .sicon { width: 28px; height: 28px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.skill .sname { font: 700 15px/1.1 var(--font-display); }
.skill .sinfo { font-size: 12px; color: var(--muted); font-weight: 700; }
.skill.ready { border-color: var(--accent); background: #3a2340; }
.skill.ready .sicon { color: var(--accent); }
.skill .cd { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.skill kbd { position: absolute; right: 8px; top: 6px; font: 800 11px/1 var(--font-body); color: var(--muted); }
@media (max-width: 640px) {
  .skill { flex-direction: column; justify-content: center; gap: 2px; text-align: center; padding: 6px 4px; }
  .skill .sinfo, .skill kbd { display: none; }
  .skill .sname { font-size: 12px; }
}

/* ------------------------------------------------------------ pages */
.page {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--panel);
  border-radius: var(--r) var(--r) 0 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 14px 14px 0; }
.page-head h2 { margin: 0; font: 700 22px/1 var(--font-display); }
.page-meta { color: var(--muted); font-weight: 800; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.panel-body { padding: 12px 14px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.panel-body h3 {
  margin: 4px 0 0;
  font: 800 12px/1 var(--font-body);
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}

/* bottom tab bar */
.tabbar {
  display: flex;
  gap: 4px;
  margin-inline: calc(-1 * max(12px, env(safe-area-inset-left, 0px)));
  padding: 6px max(12px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: #140e18;
  border-top: 1px solid var(--line);
  flex: none;
}
.tab {
  position: relative;
  flex: 1 1 0;
  min-height: 52px;
  border: 0; border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 800; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  cursor: pointer;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab[aria-current="page"] { color: var(--fg); background: var(--panel-2); }
.tab .dot { position: absolute; top: 7px; right: calc(50% - 18px); width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.tab.new { animation: pop 0.6s ease-out 3; }

/* controls */
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn {
  border: 0; border-radius: 10px;
  background: var(--panel-2);
  padding: 10px 14px; min-height: 42px;
  font-weight: 800; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: #5a1f28; color: #ffd6da; }
.btn:disabled { opacity: 0.45; cursor: default; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

/* gear */
.slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.item {
  display: flex; gap: 10px; align-items: center;
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 8px 10px;
  min-width: 0;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.item.selected { border-color: var(--accent); }
.item.empty { cursor: default; color: var(--muted); }
.glyph {
  width: 34px; height: 34px; border-radius: 9px; flex: none;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid currentColor;
}
.glyph svg { width: 20px; height: 20px; }
.item .meta { min-width: 0; flex: 1; }
.item .iname, .item .isub { display: block; }
.item .iname { font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .isub { font-size: 12px; color: var(--muted); font-weight: 700; }
.delta { font-weight: 800; font-size: 13px; white-space: nowrap; }
.delta.up { color: var(--good); }
.delta.down { color: #ff8a95; }
.bag { display: flex; flex-direction: column; gap: 6px; }
@media (min-width: 760px) { .bag { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); } .slots { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.detail {
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.detail .dname { font: 700 18px/1.15 var(--font-display); }
.detail ul { margin: 0; padding-left: 18px; }
.detail li { margin: 2px 0; }
.legend-fx { color: #ffbf73; font-weight: 800; }

/* training & skills */
.train { display: grid; gap: 6px; }
@media (min-width: 760px) { .train { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  align-items: center;
  background: var(--panel-2);
  border-radius: 12px;
  padding: 8px 8px 8px 12px;
}
.tline .tname { font-weight: 800; }
.tline .tinfo { font-size: 12px; color: var(--muted); font-weight: 700; }
.tline.locked { opacity: 0.55; }
.buy {
  grid-row: span 2;
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 800; padding: 8px 12px; min-height: 44px; min-width: 92px;
  justify-content: center;
  cursor: pointer;
}
.buy:disabled { background: var(--line); color: var(--muted); cursor: default; }
.buy .coin { width: 14px; height: 14px; }

/* stats */
.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.stats td:last-child { text-align: right; font-weight: 800; }
.stats tr.group td { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; border-bottom: 0; padding-top: 12px; }
.stats .boosted { color: var(--good); font-size: 12px; margin-left: 6px; }
.bchips { display: flex; gap: 6px; flex-wrap: wrap; }
.bchip { background: var(--panel-2); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 800; }

/* settings */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--panel-2); border-radius: 12px; padding: 10px 12px; }
.toggle label { font-weight: 800; }
.toggle small { display: block; color: var(--muted); font-weight: 600; }
.switch { appearance: none; width: 46px; height: 28px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--fg); transition: transform 0.15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }
select, textarea {
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font: inherit; min-height: 42px;
}
textarea { width: 100%; min-height: 70px; resize: vertical; font-size: 12px; font-family: ui-monospace, monospace; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-weight: 800;
  z-index: 20;
}

@media (max-width: 420px) {
  .hud-sub { display: none; }
  .chip { padding: 5px 10px 5px 6px; font-size: 14px; }
  .hudbtn { min-width: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .banner, .boost, .loot, .pop, .tab.new { transition: none; animation: none; }
}
