/* Dungeon Training Guild
   Crypt-blue stone, torchlight for actions and records, cyan for the System's voice.
   The pixel face (Unifont) is reserved for the System: wordmark, notices, celebrations. */
@font-face {
  font-family: "DTG Pixel";
  src: url("/static/fonts/pixel.woff") format("woff");
  font-display: swap;
}

:root {
  --crypt: #161a24;
  --crypt-deep: #10131b;
  --flagstone: #222838;
  --flagstone-hi: #2a3144;
  --mortar: #39425a;
  --torch: #ffae3d;
  --torch-deep: #d9861a;
  --system: #7ee8fa;
  --parchment: #efe6d2;
  --dim: #a7aec2;
  --faint: #6f778d;
  --blood: #ff7a6b;
  --good: #8fe39a;
  --radius-s: 6px;
  --radius-m: 10px;
  --pixel: "DTG Pixel", ui-monospace, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tabbar-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(255, 174, 61, 0.10), transparent 60%),
    var(--crypt);
  color: var(--parchment);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--torch); }
:focus-visible { outline: 2px solid var(--system); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
#app { overflow-x: clip; max-width: 560px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 18px; }
.wordmark { font-family: var(--pixel); font-size: 18px; color: var(--torch); letter-spacing: 0.5px; text-decoration: none; }
.topbar .back { background: none; border: 0; color: var(--dim); padding: 6px 0; cursor: pointer; }
h1 { font-size: 26px; line-height: 1.15; margin: 0 0 6px; font-weight: 700; letter-spacing: -0.2px; }
h2 { font-size: 18px; margin: 28px 0 10px; font-weight: 650; }
h3 { font-size: 16px; margin: 0; font-weight: 650; }
p { margin: 0 0 12px; }
.lede { color: var(--dim); margin-bottom: 20px; }
.muted { color: var(--dim); }
.faint { color: var(--faint); font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- surfaces ---------- */
.slab {
  background: linear-gradient(180deg, var(--flagstone-hi), var(--flagstone));
  border: 1px solid var(--mortar);
  border-radius: var(--radius-m);
  padding: 14px;
}
.slab + .slab { margin-top: 10px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--mortar); }
.list > li:first-child { border-top: 0; }
.row-link {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; padding: 12px 2px; background: none; border: 0; text-align: left; cursor: pointer;
  color: inherit; text-decoration: none;
}
.row-link .sub { color: var(--dim); font-size: 14px; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--mortar); color: var(--dim); }
.pill.pr { color: var(--crypt); background: var(--torch); border-color: var(--torch); font-weight: 650; }
.pill.legacy { color: var(--system); border-color: rgba(126, 232, 250, 0.4); }

/* ---------- the System's voice ---------- */
.system {
  position: relative;
  border: 2px solid var(--system);
  background: rgba(126, 232, 250, 0.06);
  padding: 14px 16px;
  clip-path: polygon(10px 0, calc(100% - 10px) 0, 100% 10px, 100% calc(100% - 10px), calc(100% - 10px) 100%, 10px 100%, 0 calc(100% - 10px), 0 10px);
  font-family: var(--pixel);
  font-size: 16px;
  line-height: 1.45;
  color: var(--parchment);
}
.system .who { color: var(--system); display: block; margin-bottom: 4px; }
.system + * { margin-top: 16px; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 14px; color: var(--dim); margin-bottom: 6px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  background: var(--crypt-deep); border: 1px solid var(--mortar); border-radius: var(--radius-s);
  font-size: 17px;
}
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--system); outline: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.error { color: var(--blood); font-size: 15px; margin: 8px 0; }
.hint { color: var(--faint); font-size: 14px; margin-top: -6px; margin-bottom: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; border-radius: var(--radius-s);
  border: 1px solid var(--mortar); background: var(--flagstone-hi); cursor: pointer;
  font-weight: 600; text-decoration: none; color: var(--parchment);
}
.btn.primary { background: var(--torch); border-color: var(--torch); color: #2a1a05; }
.btn.primary:active { background: var(--torch-deep); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(255, 122, 107, 0.5); color: var(--blood); background: transparent; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.seg { display: flex; border: 1px solid var(--mortar); border-radius: var(--radius-s); overflow: hidden; }
.seg button { flex: 1; min-height: 40px; background: none; border: 0; border-left: 1px solid var(--mortar); cursor: pointer; color: var(--dim); font-size: 14px; }
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed=true] { background: var(--flagstone-hi); color: var(--parchment); font-weight: 600; }

/* ---------- home ---------- */
.streak { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; align-items: center; }
.streak .big { font-family: var(--pixel); font-size: 44px; line-height: 1; color: var(--torch); grid-row: span 2; }
.pips { display: flex; gap: 6px; margin-top: 10px; }
.pips i { width: 22px; height: 8px; border-radius: 2px; background: var(--mortar); }
.pips i.on { background: var(--torch); }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

/* ---------- logger ---------- */
.ex-block { padding: 12px 12px 8px; }
.ex-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.ex-head .last { color: var(--faint); font-size: 13px; }
.icon-btn { background: none; border: 0; color: var(--faint); cursor: pointer; padding: 6px; min-width: 36px; min-height: 36px; font-size: 18px; }
.sets { width: 100%; border-collapse: collapse; table-layout: fixed; }
.sets col.c-idx { width: 34px; }
.sets col.c-rm { width: 38px; }
.sets th { font-size: 12px; color: var(--faint); font-weight: 500; text-align: left; padding: 0 4px 4px; }
.sets td { padding: 3px 4px; }
.sets td.idx { width: 28px; color: var(--faint); font-size: 14px; text-align: center; }
.sets td.idx.warm { color: var(--system); }
.sets input { width: 100%; min-width: 0; min-height: 44px; padding: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.sets td.rm { width: 34px; }
.add-set { margin-top: 6px; width: 100%; min-height: 40px; background: none; border: 1px dashed var(--mortar); border-radius: var(--radius-s); color: var(--dim); cursor: pointer; }
.savebar { position: sticky; bottom: calc(var(--tabbar-h) + 12px + env(safe-area-inset-bottom)); margin-top: 18px; }
.draft-note { font-size: 13px; color: var(--faint); text-align: center; margin-top: 6px; }

/* ---------- sheet (exercise picker) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(8, 10, 15, 0.7); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 560px; margin: 0 auto;
  max-height: 88dvh; display: flex; flex-direction: column; overflow: hidden;
  background: var(--flagstone); border: 1px solid var(--mortar); border-bottom: 0;
  border-radius: 16px 16px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
  animation: rise 160ms ease-out;
}
.sheet .scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; margin: 10px -4px 0; padding: 0 4px; }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- records ---------- */
.rec-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; }
.rec { background: var(--crypt-deep); border-radius: var(--radius-s); padding: 8px 10px; }
.rec .v { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec .l { font-size: 12px; color: var(--dim); }
.chart { width: 100%; height: auto; display: block; margin-top: 8px; }

/* ---------- totals ---------- */
.tally { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tally .slab { margin: 0; }
.tally .v { font-size: 26px; font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.1; }
.tally .l { color: var(--dim); font-size: 14px; }
.tally .wide { grid-column: span 2; }
.tally .loot .v { font-family: var(--pixel); font-weight: 400; color: var(--torch); font-size: 34px; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(16, 19, 27, 0.96); border-top: 1px solid var(--mortar);
  display: flex; justify-content: center;
}
.tabbar nav { display: grid; grid-template-columns: repeat(5, 1fr); width: 100%; max-width: 560px; }
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--faint); text-decoration: none; font-size: 12px; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a[aria-current=page] { color: var(--parchment); }
.tabbar a.log { color: var(--torch); }
.tabbar a.log svg { width: 34px; height: 34px; }

/* ---------- celebration ---------- */
.celebrate {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; justify-content: center;
  padding: 24px; background: rgba(10, 12, 18, 0.94); overflow: hidden;
}
.celebrate .inner { position: relative; z-index: 2; max-width: 520px; margin: 0 auto; width: 100%; }
.celebrate h1 { font-family: var(--pixel); font-weight: 400; color: var(--torch); font-size: 34px; margin-bottom: 14px; }
.celebrate .pr-line { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--mortar); }
.celebrate .pr-line .what { color: var(--dim); font-size: 14px; }
.celebrate .pr-line .val { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.celebrate .pr-line .was { display: block; font-weight: 400; color: var(--faint); font-size: 13px; }
.spark { position: absolute; top: -12px; width: 8px; height: 14px; z-index: 1; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom));
  z-index: 70; width: min(520px, calc(100% - 32px)); animation: rise 160ms ease-out;
}
.toast .system { background: #1a2734; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); }

@media (prefers-reduced-motion: reduce) {
  .spark { display: none; }
  .sheet, .toast { animation: none; }
}
@media (min-width: 600px) { #app { padding-top: 28px; } }
