:root {
  --bg: #0e141b;
  --surface: #151c25;
  --surface-2: #1b2430;
  --surface-3: #232e3c;
  --border: #283444;
  --text: #d5dde6;
  --muted: #8493a4;
  --faint: #5b6878;
  --accent: #66c0f4;
  --completed: #5cb87a;
  --skipped: #d6b24a;
  --dropped: #d9625a;
  --none: #4a5563;
  --radius: 8px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Header */
.top {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "brand stats" "progress progress";
  gap: 10px 24px;
  padding: 14px 20px 12px;
  background: linear-gradient(180deg, #17202b, var(--bg));
  border-bottom: 1px solid var(--border);
}
.brand { grid-area: brand; display: flex; align-items: center; gap: 10px; }
h1 { font-size: 17px; font-weight: 600; margin: 0; letter-spacing: .2px; }
.mode {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  padding: 2px 7px; border-radius: 99px; background: var(--surface-3); color: var(--muted);
}
.mode.edit { background: rgba(102, 192, 244, .15); color: var(--accent); }
.stats { grid-area: stats; display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.stat {
  display: flex; align-items: baseline; gap: 6px;
  padding: 5px 11px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
}
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; }
.stat i { width: 8px; height: 8px; border-radius: 50%; align-self: center; }
.progress { grid-area: progress; position: relative; height: 22px; background: var(--surface); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #2a6f97, var(--accent)); transition: width .4s ease; }
.progress-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--text); text-shadow: 0 1px 2px #000; }

/* Toolbar */
.toolbar { display: flex; gap: 12px; align-items: center; padding: 10px 20px; flex-wrap: wrap; }
#search {
  flex: 0 1 320px; min-width: 180px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  padding: 7px 11px; border-radius: var(--radius); outline: none;
}
#search:focus { border-color: var(--accent); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  padding: 5px 11px; border-radius: 99px; cursor: pointer; font-size: 12.5px;
}
.chip:hover { color: var(--text); }
.chip.active { background: var(--surface-3); color: var(--text); border-color: #3a4a5e; }

/* Board */
.tabs { display: none; }
.board {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(300px, 1.3fr) repeat(3, minmax(240px, 1fr));
  gap: 12px; padding: 0 20px 16px;
}
.column {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.column-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13px;
}
.column-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.column-head .count { margin-left: auto; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.column-list { flex: 1; overflow-y: auto; padding: 6px; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
.column.drop-ok { border-color: var(--col-color); box-shadow: inset 0 0 0 1px var(--col-color); background: color-mix(in srgb, var(--col-color) 6%, var(--surface)); }
.column-empty { color: var(--faint); text-align: center; padding: 24px 8px; font-size: 12.5px; }

/* Letter separators in the library column */
.letter { position: sticky; top: -6px; z-index: 1; padding: 6px 8px 3px; font-size: 11px; font-weight: 700; color: var(--faint); background: var(--surface); letter-spacing: .8px; }

/* Cards */
.card {
  --status: var(--none);
  display: flex; align-items: center; gap: 9px;
  padding: 6px 8px 6px 10px; margin: 2px 0;
  border-radius: 6px; cursor: pointer; user-select: none;
  background: var(--surface-2); border: 1px solid transparent;
  border-left: 3px solid var(--status);
  transition: background .12s, transform .12s, opacity .12s, border-color .12s;
}
.card:hover { background: var(--surface-3); }
.card.completed { --status: var(--completed); }
.card.skipped { --status: var(--skipped); }
.card.dropped { --status: var(--dropped); }
.card.completed .card-name { color: #cfeedd; }
.card.dragging { opacity: .35; transform: scale(.98); }
.card.selected { border-color: var(--accent); }
.edit .card { cursor: grab; }
.card img { width: 32px; height: 32px; border-radius: 4px; flex: none; background: var(--surface-3); object-fit: cover; }
.card-main { min-width: 0; flex: 1; }
.card-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; gap: 8px; color: var(--muted); font-size: 11.5px; }
.card-meta .num { color: var(--accent); }
.card-meta .reason { color: var(--skipped); opacity: .85; }
.card-flags { display: flex; gap: 4px; flex: none; }
.flag { font-size: 10.5px; padding: 1px 6px; border-radius: 99px; background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.flag.warn { color: var(--skipped); border-color: rgba(214, 178, 74, .4); }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 9; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(100%); transition: transform .22s ease; z-index: 10; overflow-y: auto;
}
body.drawer-open .drawer { transform: none; }
body.drawer-open .scrim { opacity: 1; pointer-events: auto; }
.drawer-close, .lightbox-close {
  position: absolute; top: 10px; right: 10px; z-index: 2; width: 32px; height: 32px;
  border-radius: 50%; border: 0; background: rgba(0, 0, 0, .55); cursor: pointer; font-size: 20px; line-height: 1;
}
.hero { width: 100%; aspect-ratio: 460 / 215; object-fit: cover; display: block; background: var(--surface-3); }
.d-body { padding: 16px 18px 28px; display: flex; flex-direction: column; gap: 16px; }
.d-title { font-size: 19px; font-weight: 600; margin: 0; }
.d-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.links { display: flex; gap: 8px; flex-wrap: wrap; }
.links a { padding: 5px 10px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12.5px; }
.section h3 { margin: 0 0 8px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); font-weight: 600; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.fact { background: var(--surface-2); border-radius: 6px; padding: 7px 10px; }
.fact b { display: block; font-size: 15px; font-variant-numeric: tabular-nums; }
.fact span { color: var(--muted); font-size: 11.5px; }
.status-row { display: flex; gap: 6px; flex-wrap: wrap; }
.status-btn { padding: 6px 12px; border-radius: 6px; cursor: pointer; background: var(--surface-2); border: 1px solid var(--border); }
.status-btn[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) 18%, var(--surface-2)); }
.status-btn:disabled { cursor: default; opacity: .6; }
.note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.note.warn { color: var(--skipped); }
/* Tiers: gold S, green to red for A-D, purple F */
.tier-S { --t: #f5c542; } .tier-A { --t: #5cc97b; } .tier-B { --t: #a3cf52; }
.tier-C { --t: #e3a646; } .tier-D { --t: #e0605a; } .tier-F { --t: #a77be6; }
.tier-dot {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 50%; padding: 0;
  font-size: 12px; font-weight: 800; line-height: 1;
  color: #0b1620; background: var(--t); border: 1px solid transparent;
}
.tier-dot.tier-S { box-shadow: 0 0 0 2px rgba(245, 197, 66, .25), 0 0 10px rgba(245, 197, 66, .45); }
.tier-dot.empty { color: var(--faint); background: transparent; border: 1px dashed var(--border); font-weight: 500; }
button.tier-dot { cursor: pointer; transition: transform .1s, border-color .1s, opacity .1s; }
button.tier-dot:hover:not(:disabled) { transform: scale(1.12); }
.card .tier-dot.empty { opacity: 0; }
.card:hover .tier-dot.empty, .card .tier-dot.empty:focus-visible { opacity: 1; }
.tier-picker {
  position: fixed; z-index: 15; display: flex; gap: 6px; padding: 7px;
  background: var(--surface-3); border: 1px solid #36465a; border-radius: 99px; box-shadow: var(--shadow);
}
.tier-picker[hidden] { display: none; }
.tier-picker .tier-dot { width: 28px; height: 28px; }
.tier-picker .tier-dot.on, .tiers .tier-dot.on { outline: 2px solid var(--text); outline-offset: 2px; }
.tiers { display: flex; gap: 8px; }
.tiers .tier-dot.big { width: 36px; height: 36px; font-size: 15px; }
.tiers .tier-dot:not(.on) { opacity: .55; }
.tiers .tier-dot:disabled { cursor: default; }
.tiers-stat { gap: 5px; align-items: center; }
.tiers-stat .tier-dot { width: 20px; height: 20px; font-size: 11px; }
.tiers-stat b { font-size: 13px; margin-right: 4px; }
textarea {
  width: 100%; min-height: 110px; resize: vertical;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px;
  padding: 9px 11px; font: inherit; outline: none;
}
textarea:focus { border-color: var(--accent); }
textarea[readonly] { resize: none; }
.shot { background: var(--surface-2); border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.shot + .shot { margin-top: 10px; }
.shot img { width: 100%; display: block; cursor: zoom-in; aspect-ratio: 16 / 9; object-fit: cover; background: var(--surface-3); }
.shot-head { display: flex; gap: 8px; align-items: center; padding: 8px 12px 0; font-size: 12px; color: var(--muted); }
.shot-head .num { color: var(--accent); font-weight: 600; }
.comment { padding: 8px 12px; white-space: pre-wrap; font-size: 13px; }
.comment + .comment { border-top: 1px solid var(--border); }
.comment.other { color: var(--muted); }
.comment small { display: block; color: var(--faint); font-size: 11px; margin-bottom: 2px; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 20; background: rgba(5, 8, 12, .92); display: flex; align-items: center; justify-content: center; padding: 24px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 6px; box-shadow: var(--shadow); }

.toast {
  position: fixed; left: 50%; bottom: 18px; transform: translate(-50%, 20px);
  background: var(--surface-3); border: 1px solid var(--border); padding: 8px 14px; border-radius: 8px;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 30; font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Narrow screens: one column at a time, switched by tabs */
@media (max-width: 900px) {
  .top { grid-template-columns: 1fr; grid-template-areas: "brand" "stats" "progress"; padding: 12px 16px; }
  .stats { justify-content: flex-start; }
  .toolbar { padding: 8px 16px; }
  #search { flex: 1 1 100%; }
  .tabs { display: flex; gap: 6px; padding: 0 16px 8px; overflow-x: auto; }
  .tabs button { flex: none; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); }
  .tabs button.active { color: var(--text); background: var(--surface-3); }
  .board { display: block; padding: 0 16px 12px; }
  .column { height: 100%; }
  .column:not(.active) { display: none; }
}

/* Views: Board | Stats */
.views { display: flex; gap: 4px; margin-left: 8px; }
.view { background: transparent; border: 1px solid transparent; color: var(--muted); padding: 4px 11px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.view:hover { color: var(--text); }
.view.active { background: var(--surface-3); color: var(--text); border-color: var(--border); }

/* Extra filters */
.selects { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-left: auto; }
.selects label { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 12.5px; }
.selects select { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px; font: inherit; font-size: 12.5px; }
.selects select:focus { outline: none; border-color: var(--accent); }

/* Stats view */
body.stats-mode { overflow: auto; }
.stats-view { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px 28px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; align-content: start; }
.stats-view[hidden] { display: none; }
.tiles { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile b { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile span { color: var(--text); font-size: 12.5px; }
.tile small { color: var(--muted); font-size: 11.5px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; min-width: 0; }
.panel.wide { grid-column: 1 / -1; }
.panel h2 { margin: 0 0 4px; font-size: 13.5px; font-weight: 600; }
.hint { margin: 0 0 10px; color: var(--muted); font-size: 12px; }

/* Column charts: one series, accent color, value on the cap, hairline baseline */
.cols { display: flex; align-items: flex-end; gap: 10px; height: 180px; padding-top: 18px; border-bottom: 1px solid var(--border); }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; cursor: default; }
.col-bar { width: min(24px, 70%); background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.col:hover .col-bar, .month:hover .col-bar { filter: brightness(1.2); }
.col-val { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.col-key { position: absolute; bottom: -20px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.cols + *, .months + * { margin-top: 24px; }
.panel .cols { margin-bottom: 22px; }
.months { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.month { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.month .col-bar { width: 100%; max-width: 24px; border-radius: 3px 3px 0 0; }

/* Letter progress: horizontal bars on a track */
.letters { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 22px; }
.letter-row { display: grid; grid-template-columns: 18px 1fr 64px; align-items: center; gap: 8px; font-size: 12px; }
.letter-key { color: var(--muted); font-weight: 700; }
.letter-track { height: 10px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.letter-fill { height: 100%; background: var(--accent); border-radius: 99px; }
.letter-val { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

.records { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 8px 0 0; font-size: 13px; }
.records dt { color: var(--muted); }
.records dd { margin: 0; }
.tier-split { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }
.tier-split div { display: flex; gap: 6px; align-items: center; }

.tip { position: fixed; z-index: 40; pointer-events: none; background: var(--surface-3); border: 1px solid #36465a; border-radius: 6px; padding: 5px 9px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; }
.tip[hidden] { display: none; }

@media (max-width: 900px) {
  .stats-view { grid-template-columns: 1fr; padding: 12px 16px 24px; }
  .selects { margin-left: 0; }
}

/* The hidden attribute must win over the display rules above. */
.board[hidden], .toolbar[hidden], .tabs[hidden] { display: none !important; }

/* Letter rows are clickable and open the list of games still open under that letter */
.letter-row { cursor: pointer; border-radius: 6px; padding: 2px 4px; }
.letter-row:hover { background: var(--surface-2); }
.letter-row.on { background: var(--surface-3); }
.open-list { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.open-list h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.open-list ul { list-style: none; margin: 0; padding: 0; columns: 3 240px; column-gap: 22px; }
.open-list li { break-inside: avoid; display: flex; justify-content: space-between; gap: 10px; padding: 4px 6px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.open-list li:hover { background: var(--surface-2); }
.open-list li small { color: var(--muted); white-space: nowrap; }

/* Review of multi-comment threads */
.review-box { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 8px; padding: 8px 10px; border-radius: 6px; border: 1px solid rgba(214, 178, 74, .4); background: rgba(214, 178, 74, .08); color: var(--skipped); font-size: 12.5px; }
.review-box .status-btn { flex: none; color: var(--text); }
.thread summary { cursor: pointer; padding: 8px 12px; color: var(--muted); font-size: 12px; }
.thread summary:hover { color: var(--text); }

/* Public (read-only) view of the detail panel */
.status-label { display: inline-block; padding: 5px 12px; border-radius: 6px; border: 1px solid var(--c); background: color-mix(in srgb, var(--c) 16%, var(--surface-2)); font-size: 13px; }
.tier-public { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: 13px; }
.feedback-text { white-space: pre-wrap; line-height: 1.55; background: var(--surface-2); border-radius: 6px; padding: 10px 12px; }
