:root {
  --bg: #14161c;
  --card: #1d2029;
  --border: #2f3441;
  --fg: #e8e9ed;
  --muted: #9aa0ae;
  --accent: #c8a45c;
  --accent-dim: #8a7440;
}

* { box-sizing: border-box; }

.hidden { display: none; }

body {
  margin: 0;
  padding: 24px;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main { max-width: 760px; margin: 0 auto; }

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: .02em; }
.sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin: 0 0 10px;
}

.hint { color: var(--muted); font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; }

.row { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-bottom: 8px; }
.row.weather { gap: 10px; }
.row label { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }

input[type="text"], input:not([type]), textarea, select, input[type="number"] {
  background: #12141a;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--fg);
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
}
input[type="number"] { width: 64px; }
input[type="checkbox"] { accent-color: var(--accent); }

textarea { width: 100%; resize: vertical; font-family: inherit; }
/* ---- board layout (mirrors the game's field: 3 rows per side) ---------- */

#bar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding-bottom: 12px; margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
#bar h1 { margin: 0; font-size: 18px; }
#meta { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
#meta label, #weatherbar label {
  display: flex; gap: 6px; align-items: center;
  font-size: 12px; color: var(--muted);
}

#table {
  background: linear-gradient(180deg, #171a1b 0%, #14161c 50%, #171a1b 100%);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px;
}

.half { position: relative; }
.half.op { padding-bottom: 14px; border-bottom: 1px dashed #2a2f3a; }
.half.me { padding-top: 14px; }

.rows { display: flex; flex-direction: column; gap: 6px; }

.row {
  position: relative;
  display: flex; align-items: stretch; gap: 10px;
  min-height: 62px;
  padding: 5px 40px 5px 74px;
  background: #191c22;
  border: 1px solid var(--border);
  border-radius: 6px;
  transition: background .1s, border-color .1s;
}

/* row name comes from data-row, so no extra markup */
.row::before {
  content: attr(data-rowlabel);
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); width: 52px; white-space: nowrap;
}

.row .count {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums;
  min-width: 22px; text-align: right;
}

.row .units {
  display: flex; gap: 5px; align-items: center;
  flex-wrap: wrap; min-height: 50px; flex: 1; justify-content: center;
}

/* legal / illegal drop targets while a card is held or dragged */
.row.ok { border-color: var(--accent-dim); background: #1d2229; }
.row.ok.over { background: #26302a; border-color: var(--accent); }
.row.no { opacity: .45; }

/* ---- card tile --------------------------------------------------------- */

.tile {
  position: relative;
  width: 74px; height: 92px;
  display: flex; flex-direction: column;
  background: #232733;
  border: 1px solid #39404f;
  border-radius: 5px;
  overflow: hidden;
  cursor: grab;
  flex: 0 0 auto;
  transition: transform .08s;
}
.tile:hover { transform: translateY(-3px); border-color: var(--accent-dim); }
.tile:active { cursor: grabbing; }

/* remove button — top-right, outside the power/name flow */
.tilex {
  position: absolute; top: 0; right: 0;
  width: 18px; height: 18px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font: inherit; font-size: 13px; font-weight: 700; line-height: 1; color: var(--muted);
  background: rgba(20, 22, 30, .82);
  border: 0; border-bottom-left-radius: 4px;
  cursor: pointer; opacity: 0;
}
.tile:hover .tilex { opacity: 1; }
.tile:focus-within .tilex, .tilex:focus { opacity: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.settings { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0; }
.settings label { display: flex; align-items: center; gap: 6px; font-size: 12px; }
#notice { color: var(--accent); font-size: 13px; }
.input-warning { color: #e9ad80; font-size: 12px; }
.import-label { padding: 6px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
.import-label input { max-width: 170px; }
.pile-entry { text-align: left; background: #2a303e; color: var(--fg); padding: 5px 8px; font-size: 12px; }
.tilex:hover { color: #ff8c8c; background: rgba(40, 20, 24, .95); }

.tile .p {
  font-weight: 800; font-size: 16px; color: var(--accent);
  font-variant-numeric: tabular-nums;
  padding: 3px 6px 0; line-height: 1;
}
.tile .n {
  font-size: 10px; line-height: 1.15; padding: 3px 6px 0;
  color: var(--fg); flex: 1; overflow: hidden;
}
.tile .a {
  font-size: 8px; line-height: 1.1; padding: 2px 6px 4px;
  color: var(--muted); border-top: 1px solid #31374a;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}

.tile.hero { border-color: #6a5a2e; background: #262419; }
.tile.special { border-style: dashed; border-color: #7a6a3a; }
.tile.agile .p { color: #7fb0d8; }
.tile.weather { width: 66px; height: 66px; }
.tile.weather .p { display: none; }

/* cards already on the board are dimmer than cards in hand */
.half.me .row .tile { width: 62px; height: 76px; }
.half.me .row .tile .a { display: none; }
.half.op .tile { width: 62px; height: 76px; cursor: default; }
.half.op .tile:hover { transform: none; }
.half.op .tile .a { display: none; }

.hand {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 8px; min-height: 100px;
  background: #16181e; border: 1px dashed var(--border); border-radius: 6px;
}
.handline { margin: 8px 0; }
.hl-label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.emptyhint { font-size: 12px; color: var(--muted); font-style: italic; padding: 6px 2px; }

.scoreline {
  text-align: center; padding: 2px 0; font-size: 22px; font-weight: 800;
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.half.op .scoreline { color: #d98c8c; }
.half.me .scoreline { color: var(--accent); }

body.holding .tile { opacity: .55; }

/* ---- controls ---------------------------------------------------------- */

#weatherbar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  margin: 12px 0; font-size: 12px; color: var(--muted);
}
#weatherbar input:not([type="checkbox"]) { width: 170px; }
.grow { flex: 1; }

#actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }

button {
  background: var(--accent); color: #1a1408; border: 0;
  border-radius: 6px; padding: 9px 20px;
  font: inherit; font-size: 14px; font-weight: 600; line-height: 1; cursor: pointer;
}
button:hover { background: #d9b76e; }
button.alt { background: transparent; color: var(--muted); border: 1px solid var(--border); padding: 8px 14px; }
button.alt:hover { color: var(--fg); border-color: var(--accent-dim); background: transparent; }
button.tiny { padding: 3px 8px; font-size: 11px; }

.chk { display: flex; gap: 5px; align-items: center; font-size: 12px; color: var(--muted); cursor: pointer; }

/* the add-cards control lives at the edge of the half it fills: the opponent's
   picker sits above her board, yours below it */
.pickline { display: flex; align-items: center; gap: 6px; padding: 2px 0; }

.leaderslot {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 3px 40px 3px 74px;
  font-size: 12px; color: var(--muted);
}
.leaderslot select { max-width: 260px; }

/* ---- card picker ------------------------------------------------------- */

.picker { display: flex; align-items: center; gap: 6px; }
.pickcount { font-size: 11px; color: var(--muted); }

/* the scrim is a separate fixed element so it can cover the page without
   swallowing the picker's own clicks */
.scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(8, 9, 12, .62);
}

.pickerbox {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(560px, 92vw); max-height: 76vh; z-index: 50;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--accent-dim);
  border-radius: 10px; box-shadow: 0 18px 50px rgba(0,0,0,.6);
  padding: 12px 14px;
}

.pickerlist {
  flex: 1; min-height: 240px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  border-top: 1px solid var(--border); padding-top: 8px;
}
.pickerlist:empty::after {
  content: 'No card matches that.'; color: var(--muted); font-size: 12px; padding: 10px 2px;
}

.pickerhead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pickerhead strong { font-size: 13px; }
.pickerhead input { flex: 1; }

.pickitem {
  display: grid; grid-template-columns: 30px 1fr auto; gap: 10px;
  align-items: baseline; text-align: left;
  background: transparent; color: var(--fg);
  border: 1px solid transparent; border-radius: 5px;
  padding: 5px 8px; font: inherit; font-size: 13px; line-height: 1.3; cursor: pointer;
}
.pickitem:hover { background: #232733; border-color: var(--accent-dim); }
.pickitem .pk { color: var(--accent); font-weight: 700; text-align: right; }
.pickitem .pf { font-size: 11px; color: var(--muted); }

/* ---- advice panel ------------------------------------------------------ */

#advice {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 14px 16px;
}
.advice-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.advice-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }

#ranked { list-style: none; counter-reset: r; margin: 0; padding: 0; }

#ranked li {
  counter-increment: r;
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px;
  align-items: start;
  padding: 10px 0; border-top: 1px solid var(--border);
}
#ranked li::before {
  content: counter(r); color: var(--accent-dim); font-weight: 700; font-size: 13px;
  min-width: 18px; padding-top: 4px;
}
#ranked li .body { display: contents; }
#ranked li .name { font-weight: 600; grid-column: 2; }
#ranked li .name .kind {
  font-size: 11px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 3px;
  padding: 1px 5px; margin-left: 8px;
  text-transform: uppercase; letter-spacing: .05em;
}
#ranked li .kind.leader { color: var(--accent); border-color: var(--accent-dim); }
#ranked li .kind.pass { color: #d98c8c; border-color: #5c3636; }
#ranked li .score { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 700; grid-column: 3; }
#ranked li .why { grid-column: 2 / -1; color: var(--muted); font-size: 12px; margin: 2px 0 0; padding: 0; list-style: none; }
#ranked li .why li { display: list-item; padding: 0; border: 0; }
#ranked li .why li::before { content: "—"; color: var(--accent-dim); margin-right: 6px; }
#ranked li .tile { width: 54px; height: 66px; grid-row: 1 / span 2; }
#ranked li.r-pass, #ranked li.r-leader { grid-template-columns: auto 1fr auto; }
#ranked li.r-pass::before, #ranked li.r-leader::before { display: none; }

#unknown { color: #d98c8c; font-size: 12px; margin: 10px 0 0; }
#adviceStale { color: #e0b060; font-size: 12px; margin: 10px 0 0; }
#recordTools { border: 1px solid var(--border); border-radius: 6px; padding: 12px; margin-bottom: 16px; }
#recordTools summary { cursor: pointer; color: var(--accent); }
#recordTools[open] summary { margin-bottom: 12px; }
#recordTools > .chk { display: flex; margin: 8px 0; }
#recordDrawCount { width: 55px; }

@media (pointer: coarse) { .tilex { opacity: 1; min-width: 24px; min-height: 24px; } }
@media (max-width: 520px) {
  body { padding: 10px; }
  .leaderslot { padding: 6px 0; }
  .leaderslot select { max-width: 100%; width: 100%; }
  .settings label { width: 100%; flex-wrap: wrap; }
  .settings select { max-width: 100%; }
  .pickerhead { flex-wrap: wrap; }
  .pickerhead input { min-width: 0; width: 100%; }
  .pickitem { grid-template-columns: 25px 1fr; }
  .pickitem .pf { grid-column: 2; }
  .tilex { opacity: 1; }
  #actions button { padding: 8px 10px; }
}
