/* mtgkit — mobile first. Dark by default because deck tuning happens at night
   and a white screen at a kitchen table is unkind. */

:root {
  color-scheme: dark;
  --bg: #141418;
  --surface: #1e1e24;
  --surface-2: #26262e;
  --line: #33333d;
  --text: #ecedf1;
  --muted: #9a9aa8;
  --accent: #9147c9;
  --accent-soft: #2b1c3a;
  --ok: #4a9d6a;
  --warn: #c9963f;
  --bad: #c25757;
  --radius: 14px;
  --tap: 44px;                       /* Apple HIG minimum touch target */
  /* Magic's five colours, at the printed-card values rather than pure hues:
     a saturated blue pip on a dark card is unreadable, and these are the
     tones Wizards actually uses on the frames. */
  --mana-w: #f5efd8;
  --mana-u: #a6cbe6;
  --mana-b: #b3a9a8;
  --mana-r: #eda28c;
  --mana-g: #a3d0a8;
  --mana-c: #ccc9c4;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f5f3;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --line: #dedbd6;
  --text: #1d1d20;
  --muted: #6b6b74;
  --accent: #7b3aad;
  --accent-soft: #efe4f7;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        system-ui, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

/* ------------------------------------------------------------------ chrome */

#top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
#top h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 650;
          letter-spacing: -.01em; }
.icon {
  min-width: var(--tap); min-height: var(--tap);
  display: grid; place-items: center;
  background: none; border: 0; color: var(--text);
  font-size: 19px; border-radius: 10px; cursor: pointer;
}
.icon:active { background: var(--surface-2); }

#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs button {
  min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; background: none; border: 0;
  color: var(--muted); font-size: 11px; cursor: pointer;
}
#tabs button span { font-size: 17px; line-height: 1; }
#tabs button.on { color: var(--accent); }

/* ------------------------------------------------------------------ layout */

.pad { padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
}
.card h2 { margin: 0 0 4px; font-size: 15px; font-weight: 650; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.gap { gap: 8px; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.center { text-align: center; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
       font-size: 12px; background: var(--surface-2);
       padding: 1px 5px; border-radius: 5px; word-break: break-all; }

/* ----------------------------------------------------------------- buttons */

button.primary, button.ghost, button.wide, button.sm {
  font: inherit; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); min-height: var(--tap); padding: 0 14px;
}
button.primary { background: var(--accent); border-color: var(--accent);
                 color: #fff; font-weight: 600; }
button.wide { width: 100%; margin-top: 10px; }
button.sm { min-height: 34px; padding: 0 10px; font-size: 13px; }
button:disabled { opacity: .45; cursor: default; }
button.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }

/* Anchors styled as buttons: a real <a> is what makes download and
   open-in-new-tab work on iOS Safari, where JS-driven navigation to an
   attachment silently does nothing. */
.btnlink { display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2);
  color: var(--text); text-decoration: none; font-size: 14px; }
.btnlink.primary { background: var(--accent); border-color: var(--accent);
  color: #fff; font-weight: 600; }
.btnlink.wide { width: 100%; }

/* ------------------------------------------------------------------ inputs */

label { display: block; margin: 10px 0 0; font-size: 13px;
        color: var(--muted); }
input[type=text], input:not([type]), textarea, select {
  width: 100%; margin-top: 5px; padding: 11px 12px;
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; min-height: var(--tap);
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
           font-size: 13px; line-height: 1.45; resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent);
                              outline-offset: -1px; }
label.check { display: flex; align-items: center; gap: 9px;
              min-height: var(--tap); color: var(--text); }
label.check input { width: auto; min-height: 0; margin: 0; }

/* ------------------------------------------------------------------ pieces */

.pill { background: var(--surface-2); border-radius: 999px;
        padding: 4px 11px; font-size: 13px; font-weight: 600;
        white-space: nowrap; }
.pill.ok   { background: color-mix(in srgb, var(--ok) 22%, transparent);
             color: var(--ok); }.pill.warn { background: color-mix(in srgb, var(--warn) 22%, transparent);
             color: var(--warn); }
.pill.bad  { background: color-mix(in srgb, var(--bad) 22%, transparent);
             color: var(--bad); }

.census { display: grid; grid-template-columns: repeat(3, 1fr);
          gap: 7px; margin-top: 12px; }
.cell { background: var(--surface-2); border-radius: 10px;
        padding: 9px 8px; text-align: center; }
.cell .k { font-size: 10px; letter-spacing: .06em; color: var(--muted);
           text-transform: uppercase; }
.cell .v { font-size: 17px; font-weight: 650; margin-top: 2px; }
.cell.short { background: color-mix(in srgb, var(--warn) 16%, transparent); }
.cell.short .v { color: var(--warn); }

.item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
  min-height: var(--tap); cursor: pointer;
}
.item:last-child { border-bottom: 0; }
/* A selected choice in a pick-one list. */
.item.on { background: color-mix(in srgb, var(--accent) 16%, transparent);
           border-radius: 8px; }
.item.on .nm b { color: var(--accent); }
.item .nm { flex: 1; min-width: 0; }
.item .nm b { font-weight: 550; display: block;
              overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 12px; color: var(--muted); display: block; }
/* The reason line is the whole point of a suggestion, so it gets its own row
   rather than wrapping into the mana cost. */
.item .sub.why { color: var(--fg2, var(--muted)); margin-top: 2px; }
.score { font-variant-numeric: tabular-nums; font-weight: 650;
         min-width: 34px; text-align: right; }

.group-h { display: flex; justify-content: space-between;
           margin: 14px 0 2px; font-size: 12px; color: var(--muted);
           text-transform: uppercase; letter-spacing: .06em; }

.note { border-left: 3px solid var(--accent); padding: 8px 10px;
        background: var(--accent-soft); border-radius: 0 8px 8px 0;
        font-size: 13px; margin-top: 10px; }
.note.warn { border-color: var(--warn);
             background: color-mix(in srgb, var(--warn) 12%, transparent); }
.note.bad  { border-color: var(--bad);
             background: color-mix(in srgb, var(--bad) 12%, transparent); }

.swap { border: 1px solid var(--line); border-radius: 12px;
        padding: 11px; margin-top: 9px; background: var(--surface-2); }
.swap .out { color: var(--bad); }
.swap .in  { color: var(--ok); }
.swap .ln  { display: flex; gap: 8px; align-items: baseline;
             font-size: 14px; padding: 2px 0; }
.swap .ln b { flex: 1; font-weight: 550; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--surface-2);
        border-radius: 999px; padding: 7px 12px; font-size: 13px;
        cursor: pointer; min-height: 36px; display: inline-flex;
        align-items: center; gap: 6px; }
.chip.on { background: var(--accent); border-color: var(--accent);
           color: #fff; }
.chip .n { opacity: .65; font-size: 11px; }

.steps { list-style: none; margin: 12px 0 0; padding: 0; }
.steps li { display: grid; grid-template-columns: 1fr auto;
            gap: 4px 10px; align-items: center;
            padding: 11px 0; border-bottom: 1px solid var(--line); }
.steps li:last-child { border-bottom: 0; }
.steps small { grid-column: 1 / -1; }
.steps .state { font-size: 19px; }
.steps .state.done { color: var(--ok); }

.kv { display: flex; justify-content: space-between; gap: 12px;
      padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.kv:last-child { border-bottom: 0; }

/* ------------------------------------------------------------------- sheet */

.sheet { position: fixed; inset: 0; z-index: 40;
         background: rgba(0,0,0,.5); display: flex; align-items: flex-end; }
/* [hidden] sets display:none at UA-stylesheet priority, which a later
   display:flex silently beats. Without this the sheet sits on every screen. */
.sheet[hidden], .toast[hidden], #tabs[hidden] { display: none; }
.sheet-inner {
  width: 100%; max-height: 86vh; overflow-y: auto;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(24px + env(safe-area-inset-bottom));
  animation: up .22s ease;
}
@keyframes up { from { transform: translateY(100%); } }
.grab { width: 38px; height: 4px; border-radius: 2px; background: var(--line);
        margin: 4px auto 12px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%);
         bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 60;
         background: var(--surface-2); border: 1px solid var(--line);
         padding: 11px 16px; border-radius: 999px; font-size: 14px;
         max-width: 90vw; }

/* Offline banner. Sits above the tab bar so it cannot be mistaken for part
   of the content it is warning about. */
.offline { position: fixed; left: 0; right: 0; z-index: 50;
  bottom: calc(60px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--warn) 88%, #000);
  color: #1a1a1a; font-size: 12px; font-weight: 550;
  padding: 8px 14px; text-align: center; }
.offline[hidden] { display: none; }

.spin { width: 17px; height: 17px; border: 2px solid var(--line);
        border-top-color: var(--accent); border-radius: 50%;
        animation: r .7s linear infinite; display: inline-block;
        vertical-align: -3px; }
@keyframes r { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------------- images */

.gallery { display: grid; gap: 9px; margin-top: 10px;
           grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.gallery figure { margin: 0; cursor: pointer; }
.gallery img { width: 100%; display: block; border-radius: 7px;
               background: var(--surface-2); aspect-ratio: 488 / 680; }
.gallery figcaption { font-size: 11px; color: var(--muted); margin-top: 3px;
                      overflow: hidden; text-overflow: ellipsis;
                      white-space: nowrap; }

.cardimg { text-align: center; margin-bottom: 12px; }
.cardimg img { width: 100%; max-width: 300px; border-radius: 12px;
               background: var(--surface-2); aspect-ratio: 488 / 680; }
.cardimg button { margin-top: 8px; }

/* Commander art on a deck row. The card image is cropped to the illustration
   window rather than shown whole: a full card at 46px is an unreadable grey
   rectangle, while the art alone is instantly recognisable. */
/* Deck rows use the shared .art crop from cardui.js; only the row spacing
   is special here. */
.item.deckrow { gap: 12px; }

.warnfg { color: var(--warn); }

/* ------------------------------------------------------------ mana pips */

.mana {
  display: inline-grid; place-items: center;
  width: 17px; height: 17px; border-radius: 50%;
  font-size: 10px; font-weight: 700; line-height: 1;
  color: #1a1a1a; background: var(--mana-c);
  margin-right: 2px; vertical-align: -3px;
  /* The inner ring is what makes a flat circle read as a printed symbol. */
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.22),
              0 1px 1px rgba(0,0,0,.35);
  font-variant-numeric: tabular-nums;
}
.m-w { background: var(--mana-w); }
.m-u { background: var(--mana-u); }
.m-b { background: var(--mana-b); }
.m-r { background: var(--mana-r); }
.m-g { background: var(--mana-g); }
.m-c { background: var(--mana-c); }
.mana.split { font-size: 8px; }
.mana.tiny-pip { width: 13px; height: 13px; font-size: 8px;
                 margin-right: 1px; vertical-align: -2px; }

.cost { white-space: nowrap; }
.costsep { color: var(--muted); font-size: 11px; margin: 0 3px 0 1px; }
.ident { display: inline-flex; align-items: center; }

/* ------------------------------------------------------------- card art */

/* The illustration window, not the whole card: a full card at 44px is a grey
   rectangle, while the art alone is instantly recognisable. */
.art { width: 44px; height: 44px; flex-shrink: 0; border-radius: 8px;
       overflow: hidden; background: var(--surface-2); position: relative; }
.art img { position: absolute; width: 152%; left: -26%; top: -13%;
           max-width: none; }
.art.empty::after { content: '?'; position: absolute; inset: 0;
                    display: grid; place-items: center;
                    color: var(--muted); font-size: 15px; }

/* ------------------------------------------------------- deck detail head */

.hero { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.hero .art { width: 64px; height: 64px; border-radius: 10px; }
.hero .hbody { flex: 1; min-width: 0; }
.hero h2 { margin: 0; }
.hero .sub { display: block; color: var(--muted); font-size: 12px;
             margin-top: 3px; white-space: nowrap; overflow: hidden;
             text-overflow: ellipsis; }

/* Fill bars. Six bare numbers make the reader do the subtraction; a visibly
   short bar says "fix this" without being read at all. */
.census .v .of { color: var(--muted); font-size: 11px; font-weight: 500; }
/* The track must contrast with the cell it sits on, and the cell background
   is already --surface-2 -- so a muted mix, which works in both themes. */
.meter { height: 3px; border-radius: 2px; margin-top: 6px; overflow: hidden;
         background: color-mix(in srgb, var(--muted) 32%, transparent); }
.meterfill { height: 100%; background: var(--accent); border-radius: 2px;
             transition: width .35s cubic-bezier(.4,0,.2,1); }
.cell.short .meterfill { background: var(--warn); }

/* Action hierarchy: one primary, three tools, then quieter exports. */
.tools { margin-top: 8px; }
button.sm { padding: 8px 10px; font-size: 12px; }
button.ghosty { background: transparent; color: var(--muted);
                box-shadow: inset 0 0 0 1px var(--line); }
button.ghosty:active { background: var(--surface-2); }

.item.sugrow { gap: 10px; }

@media (min-width: 720px) {
  body { padding-bottom: 0; }
  main { max-width: 780px; margin: 0 auto; }
  #tabs { position: sticky; max-width: 780px; margin: 0 auto;
          border-radius: 14px 14px 0 0; }
  .census { grid-template-columns: repeat(6, 1fr); }
}
