:root {
  --bg: #f4f6f8; --panel: #fff; --ink: #1c2530; --muted: #65717e; --line: #dde3e9;
  --top: #16202b; --top-ink: #e6edf3; --accent: #0f766e; --accent-ink: #fff; --accent-soft: #e6f4f2;
  --warn: #9a5b00; --warn-soft: #fff4e0; --bad: #b42318; --bad-soft: #fdecea; --ok: #1a7f37; --ok-soft: #e8f5ec;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 1.5rem 0 .5rem; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; display: block; margin-top: 4px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; white-space: nowrap; }

.topbar { background: var(--top); color: var(--top-ink); }
.topbar-inner { display: flex; align-items: center; gap: 28px; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; color: var(--top-ink); text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: #b8c4cf; text-decoration: none; padding: 17px 12px; border-bottom: 3px solid transparent; }
.nav a:hover { color: #fff; }
.nav a.on { color: #fff; border-bottom-color: #2dd4bf; }
.who { display: flex; align-items: center; gap: 12px; color: #b8c4cf; }
.linkbtn { background: none; border: 0; color: inherit; cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
.topbar .linkbtn { color: #b8c4cf; }
main { padding-top: 22px; padding-bottom: 30px; min-height: 60vh; }

.pagehead { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: 10px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.panel-title { font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin-bottom: 12px; }
details.panel > summary { cursor: pointer; font-weight: 600; }
details.panel[open] > summary { margin-bottom: 12px; }
.empty { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row-end { display: flex; justify-content: flex-end; align-items: center; gap: 14px; margin-top: 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-top: 14px; align-items: start; }

label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: .9rem; }
label.check { flex-direction: row; align-items: center; font-weight: 400; gap: 8px; }
input, select, textarea { font: inherit; color: inherit; background: #fff; border: 1px solid #c6ced6; border-radius: 6px; padding: 9px 11px; font-weight: 400; }
textarea { width: 100%; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #5eead4; outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.btn { display: inline-block; font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 6px; border: 1px solid #c6ced6; background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: #0d5f59; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.danger { color: var(--bad); }

.alert, .flash, .note { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 16px; border: 1px solid; }
.alert { background: var(--bad-soft); border-color: #f5c2bd; color: #7a1a12; }
.flash { background: var(--ok-soft); border-color: #b7dfc3; }
.note { background: var(--accent-soft); border-color: #b5ddd8; border-left: 4px solid var(--accent); position: relative; }
.note .close { position: absolute; right: 10px; top: 6px; background: none; border: 0; font-size: 1.3rem; cursor: pointer; color: var(--muted); }

.auth { max-width: 420px; margin: 30px auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; }
.auth h1 { margin-bottom: 16px; }

.usage { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: .85rem; }
.building { margin-top: 12px; color: var(--accent); font-weight: 600; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); background: #f8fafb; }
.table td { padding: 8px; border-bottom: 1px solid #eef1f4; vertical-align: top; }
.table.compact td { padding: 5px 8px; }
.table .qty { width: 2.5em; color: var(--muted); }
.table.cards { table-layout: fixed; }
.table.cards td:nth-child(2) { width: 38%; }
.table.cards td:nth-child(3) { width: 16%; }
.table.cards td:nth-child(5) { width: 5.5em; }
.clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr.unowned td, figure.unowned { opacity: .75; }
.tag { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 10px; background: #e9edf1; color: #475462; vertical-align: 1px; }
.tag.buy { background: var(--warn-soft); color: var(--warn); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input { min-width: 220px; }
.seg { display: inline-flex; border: 1px solid #c6ced6; border-radius: 6px; overflow: hidden; text-transform: none; letter-spacing: 0; }
.seg a { padding: 5px 12px; text-decoration: none; color: var(--ink); font-size: .85rem; font-weight: 600; }
.seg a.on { background: var(--top); color: #fff; }
.pager { display: flex; gap: 16px; justify-content: center; margin-top: 14px; }
.cols { columns: 3 220px; padding-left: 18px; }

.cardgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.cardgrid figure { margin: 0; }
.cardgrid img { width: 100%; border-radius: 4.75% / 3.5%; display: block; aspect-ratio: 488 / 680; background: #e9edf1; }
.cardgrid figcaption { font-size: .78rem; color: var(--muted); margin-top: 4px; }
.noimg { aspect-ratio: 488 / 680; background: #e9edf1; border-radius: 6px; display: flex; align-items: center; justify-content: center; text-align: center; padding: 8px; font-size: .85rem; }

.deckhead { display: flex; gap: 24px; margin-bottom: 18px; flex-wrap: wrap; }
.deckhead .cmdr { width: 240px; border-radius: 4.75% / 3.5%; box-shadow: 0 4px 18px rgba(0,0,0,.18); align-self: flex-start; }
.deckinfo { flex: 1; min-width: 280px; }
.deckinfo p { margin: 6px 0; }
.request { font-style: italic; }
.badge { display: inline-block; font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 12px; background: #e9edf1; margin-right: 4px; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.errors { color: var(--bad); }
.stats { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.stats div, .tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-width: 84px; }
.stats b, .tile b { display: block; font-size: 1.15rem; }
.stats span, .tile span { font-size: .75rem; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin: 12px 0; }
.tile { border-top: 3px solid var(--accent); padding: 12px 16px; }
.tile b { font-size: 1.5rem; }
.curve { display: flex; gap: 6px; align-items: flex-end; height: 128px; max-width: 420px; }
.curve .bar { padding-top: 18px; }
.curve .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; position: relative; padding-bottom: 18px; }
.curve .fill { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.curve b { font-size: .75rem; position: absolute; top: 0; }
.curve i { font-style: normal; font-size: .75rem; color: var(--muted); position: absolute; bottom: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.copyrow { display: flex; gap: 8px; margin: 8px 0; }
.copyrow input { flex: 1; font-family: ui-monospace, monospace; font-size: .85rem; }
#decklist { font-family: ui-monospace, monospace; font-size: .85rem; }

.footer { color: var(--muted); font-size: .78rem; text-align: center; padding-top: 18px; padding-bottom: 28px; border-top: 1px solid var(--line); }
.footer p { margin: 4px 0; }

@media (max-width: 700px) {
  .nav { order: 3; flex: 1 1 100%; overflow-x: auto; }
  .who { margin-left: auto; }
  .topbar-inner { gap: 0 16px; }
  .nav a { padding: 10px 10px; }
  .deckhead .cmdr { width: 160px; }
}
