:root {
  --ground: #1f2638;
  --panel: #2a3350;
  --panel-raised: #34406a;
  --line: #4a5782;
  --ink: #eef0f8;
  --muted: #a8b0cb;
  --accent: #52d6b8;
  --accent-ink: #0f2a25;
  --amber: #f2b45c;
  --danger: #ff93a4;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --hex: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--ground); }

body {
  margin: 0;
  min-height: 100vh;
  font: 16px/1.5 var(--sans);
  color: var(--ink);
  background: var(--ground);
}

a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }

:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }

.site {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
  padding: 14px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { font: 600 1.35rem var(--serif); color: var(--ink); text-decoration: none; margin-right: auto; }
.nav { display: flex; gap: 6px; }
.nav a { color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 6px; }
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--panel-raised); }
.account { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.92rem; }

.btn {
  font: 600 1rem var(--sans);
  color: var(--ink);
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: #7ae6cd; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); padding: 6px 10px; }

main { max-width: 1180px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px) 120px; }
.page-title { font-size: clamp(1.7rem, 3vw, 2.3rem); margin-bottom: 6px; }
.lede { color: var(--muted); max-width: 62ch; margin: 0 0 22px; }

.notice { padding: 12px 16px; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); margin: 0 0 18px; }
.notice-error { border-color: var(--danger); color: var(--danger); }

.gate { max-width: 560px; margin: 48px auto; text-align: center; }
.gate h1 { font-size: 2rem; margin-bottom: 12px; }
.gate p { color: var(--muted); margin: 0 0 22px; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-bottom: 20px; }
.toolbar label { color: var(--muted); }
.select {
  font: 1rem var(--sans);
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
}
.counter { margin-left: auto; color: var(--muted); }

/* The two items face each other, a hexagon between them (the board is a hex grid). */
.duel { display: grid; grid-template-columns: 1fr auto 1fr; gap: 20px; align-items: start; }
.vs {
  position: sticky;
  top: 24px;
  align-self: start;
  margin-top: 90px;
  width: 64px;
  height: 74px;
  clip-path: var(--hex);
  background: var(--amber);
  color: #3a2706;
  display: grid;
  place-items: center;
  font: 700 1.2rem var(--serif);
}

.gear {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 22px;
  min-width: 0;
}
.gear-head { display: flex; gap: 16px; align-items: center; margin-bottom: 14px; }
.gear-head h2 { font-size: 1.5rem; overflow-wrap: anywhere; }
.slot-name { margin: 2px 0 0; color: var(--amber); font-weight: 600; }
.description { margin: 0 0 14px; font-family: var(--serif); font-size: 1.05rem; line-height: 1.6; }
.muted { color: var(--muted); }
/* Line breaks inside game text show as line breaks. */
.description, .card-tip-text, .fields dd { white-space: pre-line; }

/* Item pictures sit in a square frame. Pixel art is enlarged by whole-number multiples only. */
.icon-frame {
  flex: none;
  width: 112px;
  height: 112px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-raised);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.icon-frame-small { width: 56px; height: 56px; border-radius: 8px; }
.icon-frame img { display: block; max-width: none; }
.icon-sprite { background-repeat: no-repeat; }
.pixel { image-rendering: pixelated; }
.icon-initial { font: 600 2.4rem var(--serif); color: var(--muted); }
.icon-frame-small .icon-initial { font-size: 1.3rem; }

.detail { border-top: 1px solid var(--line); padding: 12px 0 2px; }
.detail h3 { font-size: 1rem; color: var(--muted); font-family: var(--sans); font-weight: 600; margin-bottom: 8px; }

.fields { display: grid; grid-template-columns: minmax(90px, max-content) 1fr; gap: 4px 14px; margin: 0; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.entity { background: var(--ground); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.entity-title { font: 600 1.05rem var(--serif); margin-bottom: 6px; }
.entity-type { color: var(--muted); font: 400 0.85rem var(--sans); margin-left: 8px; }
.entity .entity { background: var(--panel); }

/* Cards are shown as names only. Details appear on hover or keyboard focus. */
.card-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.card-chip {
  position: relative;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: help;
}
.card-chip:hover, .card-chip:focus { border-color: var(--accent); }
.card-label { font-weight: 600; }
.card-count { color: var(--amber); font-weight: 600; }
.card-tip {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  width: max-content;
  max-width: min(300px, 80vw);
  padding: 12px 14px;
  background: var(--ground);
  border: 1px solid var(--accent);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  cursor: default;
}
.card-chip:hover .card-tip, .card-chip:focus .card-tip { display: block; }
.card-tip-head { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.card-tip-name { font: 600 1.05rem var(--serif); }
.card-tip-cost { color: var(--amber); font-weight: 600; white-space: nowrap; }
.card-tip-text { margin: 8px 0 0; line-height: 1.45; }
.card-tip-range { margin: 8px 0 0; color: var(--muted); }

.choosebar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: center;
  margin: 24px -16px 0;
  padding: 14px 16px;
  background: var(--ground);
  border-top: 1px solid var(--line);
}
.choosebar .btn-primary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 14px 18px; }

.status { min-height: 1.5em; margin: 10px 0 0; color: var(--muted); }
.status-error { color: var(--danger); }

/* Results */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 20px; }
.tab { font: 600 0.95rem var(--sans); color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: 7px 16px; cursor: pointer; }
.tab[aria-selected="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.row { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.row[open] { border-color: var(--accent); }
.row summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: 2.2rem 56px minmax(120px, 1.4fr) minmax(140px, 2fr) 5rem 6rem; gap: 14px; align-items: center; padding: 12px 16px; }
.row summary::-webkit-details-marker { display: none; }
.rank { font: 600 1.3rem var(--serif); color: var(--muted); text-align: right; }
.row-name { font: 600 1.1rem var(--serif); overflow-wrap: anywhere; }
.row-sub { display: block; font: 400 0.82rem var(--sans); color: var(--muted); }
.bar { height: 10px; background: var(--ground); border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar-early span { background: var(--muted); }
.score { display: block; margin-top: 4px; font-size: 0.9rem; }
.score-margin { color: var(--muted); }
.stat { text-align: right; font-variant-numeric: tabular-nums; }
.row-body { padding: 4px 18px 18px; }
.footnote { color: var(--muted); max-width: 70ch; margin-top: 28px; font-size: 0.92rem; }

@media (max-width: 860px) {
  .duel { grid-template-columns: 1fr; }
  .vs { position: static; margin: 0 auto; width: 52px; height: 60px; }
  .choosebar { grid-template-columns: 1fr 1fr; }
  .choosebar .btn-quiet { grid-column: 1 / -1; order: 3; }
  .row summary { grid-template-columns: 1.6rem 56px 1fr 4.5rem; }
  .row summary .bar-cell { grid-column: 1 / -1; order: 5; }
  .row summary .stat-games { display: none; }
}

@media (prefers-reduced-motion: no-preference) {
  .gear { animation: arrive 180ms ease-out; }
  @keyframes arrive { from { opacity: 0.4; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* Cards */
.card-face-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 14px; }
.card-face-head h2 { font-size: 1.5rem; overflow-wrap: anywhere; }
.cost-badge { flex: none; display: inline-flex; align-items: baseline; gap: 8px; background: var(--amber); color: #3a2706; border-radius: 999px; padding: 4px 16px; font-weight: 600; }
.cost-badge strong { font: 700 1.35rem var(--serif); }
.icon-frame-card { width: 168px; height: 168px; }
.card-art { margin: 0 auto 16px; }
.card-range { margin: 12px 0 0; color: var(--amber); font-weight: 600; }
.card-facts { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.fact { background: var(--ground); border: 1px solid var(--line); border-radius: 999px; padding: 3px 14px; font-size: 0.92rem; }

/* Live total on the results page */
.live-line { margin: 0 0 6px; font-size: 1.15rem; }
.live-line strong { font: 700 1.5rem var(--serif); color: var(--accent); font-variant-numeric: tabular-nums; }
.live-note { color: var(--muted); font-size: 0.9rem; margin-left: 6px; }
.tabs[hidden] { display: none; }
