/* MagicDuel partner interface. Ink on the Realm's paper, one gold accent.
   Tokens first; every colour below reads a token, so the dark scheme is one block. */

:root {
  --paper: #EDEBE0;        /* the page: the Realm's own paper */
  --sheet: #FFFDF8;        /* a fresh page */
  --ink: #1E1C18;
  --ink-2: #6B6760;        /* muted ink: secondary text */
  --ink-3: #A39E93;        /* faint ink: hints, disabled */
  --line: #D9D5C8;
  --line-2: #EAE7DC;
  --gold: #FFCC00;         /* the house gold */
  --gold-2: #B98D00;       /* gold that can carry text */
  --gold-soft: #FFF3C2;
  --green: #2E7D4F;
  --green-soft: #E3F1E8;
  --red: #B3261E;
  --red-soft: #F8E5E3;
  --blue-soft: #E7ECF4;
  --focus: #1E1C18;
  --radius: 6px;
  --radius-lg: 10px;
  --rail: 232px;
  --font: "Avenir Next", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1B1A17;
    --sheet: #262420;
    --ink: #EDEBE0;
    --ink-2: #A8A397;
    --ink-3: #6F6A60;
    --line: #3C3933;
    --line-2: #2F2D28;
    --gold-2: #E4B500;
    --gold-soft: #3D3410;
    --green: #6DBF8E;
    --green-soft: #1F3328;
    --red: #E5766E;
    --red-soft: #3D211F;
    --blue-soft: #262C38;
    --focus: #EDEBE0;
  }
}
:root[data-theme="dark"] {
  --paper: #1B1A17; --sheet: #262420; --ink: #EDEBE0; --ink-2: #A8A397; --ink-3: #6F6A60;
  --line: #3C3933; --line-2: #2F2D28; --gold-2: #E4B500; --gold-soft: #3D3410;
  --green: #6DBF8E; --green-soft: #1F3328; --red: #E5766E; --red-soft: #3D211F; --blue-soft: #262C38; --focus: #EDEBE0;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body.pa {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  font-variant-numeric: tabular-nums;
}
a { color: inherit; text-decoration: underline; text-decoration-color: var(--ink-3); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--ink); }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 26px; font-weight: 600; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 12px; }
small, .small { font-size: 13px; color: var(--ink-2); }
code, .mono { font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 0.93em; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--sheet); padding: 8px 12px; z-index: 50; }
.skip:focus { left: 8px; }
[hidden] { display: none !important; }

/* ---- frame: rail + main --------------------------------------------------------------- */
.frame { display: flex; min-height: calc(100vh - 44px); }
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 12px 0 4px;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; flex: 1; }
.topbar-name { font-size: 13px; color: var(--ink-2); max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-menu {
  width: 44px; height: 44px; border: 0; background: none; padding: 12px; cursor: pointer;
  display: flex; flex-direction: column; justify-content: space-between;
}
.topbar-menu span { display: block; height: 2px; background: var(--ink); border-radius: 1px; }

.rail {
  width: var(--rail);
  flex: 0 0 var(--rail);
  padding: 20px 16px;
  border-right: 1px solid var(--line);
  background: var(--sheet);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; }
.brand-mark {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%;
  background: var(--gold);
  box-shadow: inset 0 0 0 3px var(--sheet), inset 0 0 0 4px var(--ink);
}
.brand-text { font-weight: 600; line-height: 1.15; }
.brand-text small { display: block; font-weight: 400; color: var(--ink-2); font-size: 12px; }
.rail-list { list-style: none; margin: 0; padding: 0; }
.rail-list a {
  display: block; padding: 9px 10px; margin: 2px 0; border-radius: var(--radius);
  text-decoration: none; color: var(--ink-2); font-weight: 500;
}
.rail-list a:hover { color: var(--ink); background: var(--line-2); }
.rail-list a.on { color: var(--ink); background: var(--gold-soft); box-shadow: inset 3px 0 0 var(--gold); }
.rail-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line-2); font-size: 13px; color: var(--ink-2); display: flex; flex-direction: column; gap: 2px; }
.rail-who { color: var(--ink); font-weight: 500; }
.rail-out { margin-top: 6px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }

.main { flex: 1; min-width: 0; padding: 28px 36px 48px; max-width: 1180px; }
.page-head { margin-bottom: 22px; }
.page-head .lead { margin: 6px 0 0; color: var(--ink-2); max-width: 64ch; }
.foot { padding: 18px 36px; font-size: 13px; color: var(--ink-2); }

/* ---- notices, flashes ------------------------------------------------------------------ */
.notice { padding: 10px 14px; border-radius: var(--radius); background: var(--blue-soft); margin-bottom: 18px; font-size: 14px; }
.notice-view { background: var(--gold-soft); }
.flash { padding: 10px 14px; border-radius: var(--radius); margin: 0 0 16px; font-size: 14px; }
.flash-ok { background: var(--green-soft); color: var(--green); }
.flash-err { background: var(--red-soft); color: var(--red); }
.flash-info { background: var(--blue-soft); }

/* ---- the ledger hero ------------------------------------------------------------------ */
.ledger {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 40px;
  padding: 22px 0 22px; margin-bottom: 8px;
  border-top: 2px solid var(--ink); border-bottom: 1px solid var(--line);
}
.ledger-main { display: flex; flex-direction: column; gap: 2px; }
.ledger-main .label { color: var(--ink-2); font-size: 14px; }
.ledger-main .amount { font-size: 44px; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.ledger-main .amount small { font-size: 18px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.ledger-side { display: grid; grid-template-columns: auto auto; gap: 2px 18px; font-size: 14px; color: var(--ink-2); }
.ledger-side b { color: var(--ink); font-weight: 500; text-align: right; }
.ledger-act { margin-left: auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.ledger-act .small { text-align: right; max-width: 30ch; }

/* ---- figures row --------------------------------------------------------------------- */
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; margin: 0 0 28px; border-bottom: 1px solid var(--line); }
.figure { padding: 14px 16px 14px 0; border-right: 1px solid var(--line-2); }
.figure:last-child { border-right: 0; }
.figure + .figure { padding-left: 16px; }
.figure .n { display: block; font-size: 26px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.1; }
.figure .l { display: block; font-size: 13px; color: var(--ink-2); margin-top: 3px; }
.figure .d { display: block; font-size: 12px; color: var(--ink-3); }

/* ---- sections and sheets ------------------------------------------------------------ */
.section { margin: 0 0 32px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.section-head .small { margin-left: auto; }
.sheet { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 18px 20px; }
.sheet + .sheet { margin-top: 16px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.three { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.terms { border-left: 3px solid var(--gold); padding: 4px 0 4px 14px; margin: 0 0 24px; color: var(--ink-2); max-width: 70ch; }
.terms b { color: var(--ink); font-weight: 500; }

/* ---- tables --------------------------------------------------------------------------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.t th { font-weight: 500; color: var(--ink-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td.n, table.t th.n { text-align: right; white-space: nowrap; }
table.t tr.total td { font-weight: 600; border-top: 1px solid var(--ink); border-bottom: 0; }
table.t .sub { display: block; font-size: 12px; color: var(--ink-2); }
table.t a.row { text-decoration: none; font-weight: 500; }
table.t a.row:hover { text-decoration: underline; }
table.t tr.clickable { cursor: pointer; }
table.t tr.clickable:hover td { background: var(--line-2); }
.empty { padding: 26px 0; color: var(--ink-2); }
.empty b { color: var(--ink); font-weight: 500; }
.bar-cell { position: relative; min-width: 140px; }
.bar-cell i { position: absolute; left: 0; top: 30%; height: 40%; background: var(--gold); border-radius: 2px; opacity: .8; }

/* ---- chips ---------------------------------------------------------------------------- */
.chip { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 12px; font-weight: 500; line-height: 1.5; white-space: nowrap; }
.chip-registered { background: var(--line-2); color: var(--ink-2); }
.chip-confirmed { background: var(--blue-soft); color: var(--ink); }
.chip-paid { background: var(--gold-soft); color: var(--gold-2); }
.chip-completed { background: var(--green-soft); color: var(--green); }
.chip-requested { background: var(--gold-soft); color: var(--gold-2); }
.chip-refused { background: var(--red-soft); color: var(--red); }
.chip-active { background: var(--green-soft); color: var(--green); }
.chip-pending { background: var(--gold-soft); color: var(--gold-2); }

/* ---- forms and buttons ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > span { font-size: 14px; font-weight: 500; }
.field .hint { font-size: 12px; color: var(--ink-2); font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=date], select, textarea {
  font: inherit; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 11px; width: 100%;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 2px var(--gold-soft); }
input[readonly] { color: var(--ink-2); background: var(--line-2); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 4px; width: auto; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row .field { flex: 1 1 160px; margin-bottom: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 38px; padding: 8px 16px; border-radius: var(--radius); cursor: pointer;
  font: inherit; font-weight: 500; text-decoration: none; line-height: 1.2;
  background: var(--sheet); color: var(--ink); border: 1px solid var(--ink);
}
.btn:hover { background: var(--line-2); }
.btn-primary { background: var(--ink); color: var(--sheet); border-color: var(--ink); }
.btn-primary:hover { background: #000; }
:root[data-theme="dark"] .btn-primary:hover { background: #fff; }
.btn-gold { background: var(--gold); color: #1E1C18; border-color: var(--gold); }
.btn-gold:hover { background: #F0BF00; }
.btn-small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.btn-quiet { border-color: var(--line); color: var(--ink-2); }
.btn[disabled], .btn.off { opacity: .5; cursor: not-allowed; }
.btn-danger { border-color: var(--red); color: var(--red); }

/* ---- links page ---------------------------------------------------------------------- */
.linkbox { display: flex; gap: 8px; align-items: stretch; }
.linkbox input { flex: 1; font-family: Consolas, "SF Mono", Menlo, monospace; font-size: 14px; }
.linkbox .btn { flex: 0 0 auto; }
.copied { color: var(--green); font-size: 13px; }
.banners { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.banners figure { margin: 0; }
.banners img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); }
.banners figcaption { font-size: 12px; color: var(--ink-2); margin-top: 4px; }

/* ---- charts (drawn by app.js) --------------------------------------------------------- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid { stroke: var(--line-2); stroke-width: 1; }
.chart .axis { fill: var(--ink-2); font-size: 11px; }
.chart .s0 { stroke: var(--ink); fill: var(--ink); }
.chart .s1 { stroke: var(--ink-3); fill: var(--ink-3); }
.chart .s2 { stroke: var(--gold-2); fill: var(--gold); }
.chart .s3 { stroke: var(--green); fill: var(--green); }
.chart .s4 { stroke: var(--red); fill: var(--red); }
.chart .s5 { stroke: #6B7FA8; fill: #6B7FA8; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: none; }
.chart .bar { stroke: none; }
.chart .hbar text, .chart .funnel text { fill: var(--ink); font-size: 12px; }
.chart .hbar .v, .chart .funnel .v { fill: var(--ink-2); }
.chart .funnel .step { fill: var(--ink-2); font-size: 11px; }
.chart .hover { stroke: var(--ink-3); stroke-dasharray: 3 3; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 8px 0 0; font-size: 13px; color: var(--ink-2); list-style: none; padding: 0; }
.chart-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 30;
  background: var(--ink); color: var(--sheet); font-size: 12px; line-height: 1.4;
  padding: 6px 9px; border-radius: var(--radius); white-space: nowrap;
}
.chart-tip b { display: block; font-weight: 600; margin-bottom: 2px; }
.chart-host { position: relative; }
.chart-empty { padding: 30px 0; text-align: center; color: var(--ink-2); font-size: 14px; }

/* ---- reports ------------------------------------------------------------------------- */
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.report-card { display: block; text-decoration: none; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--sheet); }
.report-card:hover { border-color: var(--ink); }
.report-card b { display: block; font-weight: 600; }
.report-card span { display: block; font-size: 13px; color: var(--ink-2); margin-top: 3px; }
.report-card .pin { float: right; color: var(--gold-2); font-size: 12px; }
.builder { display: grid; grid-template-columns: 300px 1fr; gap: 24px; align-items: start; }
.builder-form { position: sticky; top: 16px; }
.metric-list { display: grid; gap: 6px; }
.metric-list label { display: flex; gap: 8px; align-items: center; font-size: 14px; padding: 4px 6px; border-radius: 4px; }
.metric-list label:hover { background: var(--line-2); }
.metric-list input { width: auto; }
.builder-out { min-width: 0; }
.report-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.report-title h2 { font-size: 20px; }
.report-title .small { margin-left: auto; }
.note { font-size: 13px; color: var(--ink-2); margin: 8px 0 0; }

/* ---- player detail ----------------------------------------------------------------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border-bottom: 0; }
.timeline .mark { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink-3); margin-top: 4px; }
.timeline .mark.done { background: var(--gold); border-color: var(--gold-2); }
.timeline .mark.money { background: var(--green); border-color: var(--green); }
.timeline .when { font-size: 12px; color: var(--ink-2); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--ink-2); margin: 0; }
.kv dd { margin: 0; }
.pager { display: flex; gap: 12px; align-items: center; margin-top: 14px; font-size: 14px; }
.pager-link.off { color: var(--ink-3); }
.pager-where { color: var(--ink-2); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; flex: 0 1 200px; }
.filters .btn { margin-bottom: 0; }

/* ---- plan steps (account page) ------------------------------------------------------ */
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.steps li { padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; background: var(--sheet); }
.steps li b { display: block; font-size: 20px; font-weight: 600; }

/* ---- help ---------------------------------------------------------------------------- */
.faq h3 { margin: 22px 0 6px; }
.faq p, .faq li { max-width: 72ch; }
.faq ul { padding-left: 20px; }
.toc { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 14px; margin-bottom: 8px; }

/* ---- public pages (login, reset, apply) --------------------------------------------- */
.pa-public { display: flex; min-height: 100vh; }
.public { width: 100%; max-width: 420px; margin: 0 auto; padding: 48px 20px; display: flex; flex-direction: column; }
.public .sheet { padding: 24px; }
.public h1 { font-size: 22px; margin-bottom: 14px; }
.public-foot { margin-top: auto; padding-top: 30px; font-size: 12px; color: var(--ink-2); text-align: center; }
.brand-public { padding-bottom: 20px; }
.public-links { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; margin-top: 14px; flex-wrap: wrap; }
.public.wide { max-width: 640px; }
.honey { position: absolute; left: -9999px; }

/* ---- phones and small screens ------------------------------------------------------- */
@media (max-width: 900px) {
  .topbar { display: flex; }
  .frame { min-height: auto; display: block; }
  .rail {
    position: fixed; top: 0; left: 0; height: 100vh; z-index: 30;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.25);
  }
  .rail.open { transform: none; }
  .main { padding: 18px 16px 40px; max-width: none; }
  .foot { padding: 14px 16px; }
  .two, .three { grid-template-columns: 1fr; }
  .builder { grid-template-columns: 1fr; }
  .builder-form { position: static; }
  .ledger { gap: 12px 24px; }
  .ledger-main .amount { font-size: 38px; }
  .ledger-act { margin-left: 0; align-items: flex-start; width: 100%; }
  .ledger-act .small { text-align: left; }
  .figures { grid-template-columns: 1fr 1fr; }
  .figure { border-right: 0; padding-left: 0 !important; border-bottom: 1px solid var(--line-2); }
  h1 { font-size: 22px; }
  .rail-list a { padding: 12px 10px; }
  table.t th, table.t td { padding: 9px 8px; }
}
@media (max-width: 480px) {
  .figures { grid-template-columns: 1fr 1fr; }
  .figure .n { font-size: 22px; }
  .linkbox { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .rail { transition: none; }
}
@media print {
  .rail, .topbar, .foot, .btn, .filters { display: none !important; }
  .main { padding: 0; max-width: none; }
  body.pa { background: #fff; color: #000; }
}
