:root {
  --bg: #0c0d13;
  --poster: #14161f;
  --card: #20233a;
  --tile: #262a42;
  --rule: #2e3250;
  --text: #f4f4f7;
  --muted: #b4b8cc;
  --faint: #8a8fa6;
  --accent: #ff8a5b;
  --display: "Space Grotesk", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
}

/* ---- Toolbar (not part of the exported image) ---- */

.toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: space-between; align-items: center;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.hint { color: var(--faint); font-size: 14px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions button {
  min-height: 40px; padding: 0 16px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--card); color: var(--text);
  font: 500 14px Inter, sans-serif; cursor: pointer;
}
.actions button:hover { background: var(--tile); }
.actions select {
  min-height: 40px; padding: 0 10px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--card); color: var(--text);
  font: 500 14px Inter, sans-serif; cursor: pointer;
}
.actions button:first-child { background: var(--accent); color: #2a1206; border-color: transparent; }

/* ---- Stage: scales the fixed 1080px poster to fit the window ---- */

.stage { padding: 24px 16px; display: flex; justify-content: center; overflow: hidden; }
.tile {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none; /* iOS long-press menu would fight touch dragging */
  -webkit-user-select: none;
  touch-action: manipulation;
}
.tile.ghost { box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6); outline: none; }
.scaler { transform-origin: top left; }

/* ---- Poster (1080 × 1350, Instagram 4:5) ---- */

.poster {
  width: 1080px; min-height: 1350px;
  padding: 64px;
  background: var(--poster);
  display: flex; flex-direction: column; gap: 32px;
}

[data-field] { outline: none; border-radius: 4px; }
[data-field]:hover { box-shadow: 0 0 0 2px var(--rule); }
[data-field]:focus { box-shadow: 0 0 0 2px var(--accent); }
/* Empty fields keep a faint placeholder so there's still something to click (app.js markEmpty).
   Hidden while typing and in the exported image. */
[data-field].is-empty:not(:focus)::before { content: attr(data-placeholder); opacity: 0.35; }
.poster.exporting [data-field].is-empty::before { content: none; }

.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; }
.titles { display: flex; flex-direction: column; gap: 8px; }
.eyebrow {
  font: 500 22px var(--display);
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent);
}
.poster h1 {
  margin: 0;
  font: 700 72px/1 var(--display); letter-spacing: -0.02em;
}
.subtitle { font-size: 26px; color: var(--muted); }
.where { font-size: 22px; color: var(--faint); text-align: right; white-space: nowrap; }
/* A bigger target than the text itself (the poster is drawn small on phones); the negative
   margin keeps the layout where it was. */
.where [data-field] { display: inline-block; min-width: 140px; padding: 6px 10px; margin: -6px -10px; }

/* 3 cards, or up to 5 once BGG details give hours and weight: equal columns either way. */
.stats { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 16px; }
.stat[hidden] { display: none; }
.stat-value .unit { font-size: 0.5em; color: var(--faint); margin-left: 2px; }
.stat {
  background: var(--card); border-radius: 16px; padding: 18px 22px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-label { font-size: 20px; color: #a3a8c3; }
.stat-value { font: 700 48px/1 var(--display); }

/* ---- Awards: game of the con, biggest surprise, biggest letdown ---- */

.awards { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; }
.awards[hidden], .award[hidden] { display: none; }
.awards.no-side { grid-template-columns: minmax(0, 1fr); }
/* Without a winner, the two small cards sit side by side. */
.awards.no-top { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.awards.no-top .award-side { display: contents; }
.award-side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.award-side .award { flex: 1; }
.award {
  display: flex; align-items: center; gap: 18px; min-width: 0;
  padding: 14px; border-radius: 16px;
  background: var(--card); cursor: pointer;
}
.award-cover { flex-shrink: 0; width: 150px; height: 150px; border-radius: 12px; overflow: hidden; background: var(--tile); }
.award-small .award-cover { width: 64px; height: 64px; border-radius: 10px; }
.award-cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.award-cover .initial {
  display: flex; align-items: center; justify-content: center; height: 100%;
  font: 700 48px var(--display); color: var(--faint);
}
.award-small .award-cover .initial { font-size: 24px; }
.award-body { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.award-label {
  font: 500 16px var(--display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent);
}
.award-small .award-label { font-size: 13px; color: var(--muted); }
.award-name { font: 700 34px/1.1 var(--display); overflow-wrap: anywhere; }
.award-small .award-name { font-size: 20px; }
/* The game's tier, as a small chip in the tier's colors. */
.award-chip {
  display: inline-block; vertical-align: 0.15em; margin-left: 0.35em;
  padding: 0.2em 0.45em; border-radius: 0.3em;
  font: 700 0.55em/1 var(--display);
}
.award-facts { font-size: 18px; color: var(--muted); }
.award-facts:empty { display: none; }
.award-note { font-size: 20px; line-height: 1.35; color: var(--text); }
.poster.exporting .award-note.is-empty { display: none; }

/* The poster has a fixed 4:5 shape: on a short list the tier rows share the spare height
   (taller labels, tiles centered in each row) instead of leaving a gap at the bottom. */
.tiers { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.tier { flex: 1 1 auto; display: flex; gap: 16px; }
.tier-label {
  width: 104px; min-height: 120px; flex-shrink: 0;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font: 700 60px var(--display);
}
.tier-games {
  flex: 1; min-height: 120px;
  display: flex; flex-wrap: wrap; gap: 12px; align-content: center;
  border-radius: 12px;
}
.tier-games.over { box-shadow: inset 0 0 0 2px var(--rule); }

/* --size is set per tier by app.js so a crowded tier shrinks instead of wrapping. */
.tile {
  --size: 120px;
  position: relative;
  width: var(--size); height: var(--size);
  border-radius: calc(var(--size) * 0.1); overflow: hidden;
  background: var(--tile);
  padding: calc(var(--size) * 0.1);
  display: flex; align-items: flex-end;
  font-size: calc(var(--size) * 0.15); font-weight: 600; line-height: 1.2;
  cursor: grab; user-select: none;
}
.tile:focus-visible, .tile.selected { outline: 3px solid var(--accent); outline-offset: 2px; }
.tile.dragging { opacity: 0.35; }
.tile img {
  position: absolute; inset: 0;
  width: 100%; height: 100%; object-fit: cover;
  pointer-events: none;
}
/* --fit (set per tile by app.js) shrinks the text for long words like "Dorfromantik" so they
   fit whole; breaking inside a word is only the last resort. */
.tile .name {
  position: relative; width: 100%; min-width: 0;
  display: flex; align-items: flex-end; gap: 0.25em;
  font-size: calc(var(--size) * 0.15 * var(--fit, 1));
}
.tile .name-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
/* NEW and bought, at the bottom right of the name; sized from the name's font so they fit the band. */
.tile .name-marks { display: flex; gap: 0.2em; flex-shrink: 0; margin-left: auto; padding-bottom: 0.05em; }
.tile .name-marks .badge {
  height: 1.3em; min-width: 1.3em; padding: 0 0.35em;
  font-size: 0.8em; box-shadow: none;
}
.tile .name-marks .badge-bought { padding: 0; width: 1.3em; }
/* Long names: the badges get their own line, still bottom right (app.js MARKS_INLINE_MIN). */
.tile .name.marks-below { flex-wrap: wrap; row-gap: 0.2em; }
.tile .name.marks-below .name-text { flex-basis: 100%; }
.tile .name.marks-below .name-marks { padding-bottom: 0; }
.tile .name-marks .badge-bought svg { width: 0.85em; height: 0.85em; }
/* With a cover, the name sits on a dark band so it stays readable over any art. */
.tile.has-cover { padding: 0; }
.tile.has-cover .name {
  width: 100%;
  padding: 6px 8px;
  background: rgba(12, 13, 19, 0.82);
  font-size: calc(var(--size) * 0.11 * var(--fit-strip, 1)); line-height: 1.2;
}
/* Too small to read: the cover art carries the title on its own. */
/* Its NEW and bought marks still show, on their own in the bottom-right corner. */
.tile.has-cover.tiny .name { background: none; padding: 4px; }
.tile.has-cover.tiny .name-text { display: none; }
.tile.has-cover.tiny .name-marks .badge { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }

/* ---- Badges ---- */

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  height: 22px; min-width: 22px; padding: 0 6px;
  border-radius: 999px;
  font: 700 12px/1 var(--display); letter-spacing: 0.04em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.badge-new { background: var(--accent); color: #2a1206; }
.badge-plays { background: #f4f4f7; color: #14161f; }
.badge-bought {
  padding: 0; width: 22px;
  background: #f4f4f7;
}
.badge-bought svg {
  width: 14px; height: 14px;
  fill: none; stroke: #14161f; stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
}

.legend {
  display: flex; flex-wrap: wrap; gap: 24px;
  font-size: 18px; color: var(--muted);
}
.legend[hidden], .legend-item[hidden] { display: none; }
.legend-item { display: inline-flex; align-items: center; gap: 8px; }

/* ---- Tile editor: floating panel, a bottom sheet on phones ---- */

.tile-editor {
  position: fixed; z-index: 20;
  left: 50%; bottom: 16px; transform: translateX(-50%);
  width: min(560px, calc(100% - 32px));
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--rule); border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  display: flex; flex-direction: column; gap: 12px;
  font-size: 15px;
}
.tile-editor[hidden] { display: none; }
.editor-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.editor-head strong { font: 600 18px var(--display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.editor-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.editor-label { width: 48px; color: var(--muted); font-size: 14px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }

.tile-editor button {
  min-height: 44px; min-width: 44px; padding: 0 14px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--tile); color: var(--text);
  font: 600 16px var(--display); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.tile-editor button:hover { border-color: var(--faint); }
.tile-editor button:disabled { opacity: 0.4; cursor: default; }
.tile-editor button[aria-pressed="true"] { background: var(--tier-color); color: var(--tier-ink); border-color: transparent; }
.tile-editor button svg {
  width: 20px; height: 20px;
  fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
}
#editor-done { background: var(--accent); color: #2a1206; border-color: transparent; font-family: Inter, sans-serif; font-weight: 500; }

.editor-badges label { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.editor-badges input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); }
.editor-badges input[type="number"] {
  width: 64px; min-height: 40px; padding: 0 8px;
  border: 1px solid var(--rule); border-radius: 8px;
  background: var(--bg); color: var(--text);
  font: 16px Inter, sans-serif; /* 16px stops iOS zooming in on focus */
}

#editor-tiers button, .seg button { font-family: var(--display); }
#cover-add, #cover-remove { font: 500 15px Inter, sans-serif; }

/* Leave room to scroll the poster above the open editor. */
body.editing .stage { padding-bottom: 400px; }

/* ---- Cover photo framing ---- */

.cropper {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(5, 6, 10, 0.8);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.cropper[hidden] { display: none; }
.cropper-panel {
  width: min(400px, 100%);
  padding: 20px;
  background: var(--card);
  border: 1px solid var(--rule); border-radius: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.cropper-panel strong { font: 600 20px var(--display); }
.cropper-hint { font-size: 14px; color: var(--muted); }
#cropper-canvas {
  width: 100%; aspect-ratio: 1; height: auto;
  border-radius: 12px;
  background: var(--bg);
  touch-action: none; /* the canvas handles drag and pinch itself */
  cursor: grab;
}
.cropper-zoom { display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--muted); min-height: 44px; }
.cropper-zoom input { flex: 1; accent-color: var(--accent); min-height: 44px; }
.cropper-actions { display: flex; gap: 8px; }
.cropper-actions button {
  flex: 1; min-height: 48px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--tile); color: var(--text);
  font: 500 16px Inter, sans-serif; cursor: pointer;
}
#cropper-use, #add-submit { background: var(--accent); color: #2a1206; border-color: transparent; }

/* ---- Add game ---- */

.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input {
  min-height: 48px; padding: 0 12px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--bg); color: var(--text);
  font: 16px Inter, sans-serif; /* 16px stops iOS zooming in on focus */
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg.grow { flex: 1; }
.seg.grow .tier-btn { flex: 1; }
.tier-btn {
  min-height: 44px; min-width: 44px; padding: 0 12px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--tile); color: var(--text);
  font: 600 16px var(--display); cursor: pointer;
}
.tier-btn[aria-pressed="true"] { background: var(--tier-color); color: var(--tier-ink); border-color: transparent; }
.form-error { margin: 0; font-size: 14px; color: #ffb4a8; }
#cover-match { font: 500 15px Inter, sans-serif; }

/* ---- Lists ---- */

#save-list:disabled { opacity: 0.55; cursor: default; }
.view-note {
  flex-basis: 100%; margin: 0;
  padding: 8px 12px; border-radius: 10px;
  background: #2a2410; color: #f3dc8a; font-size: 14px;
}
.view-note[hidden] { display: none; }
.list-section { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }
.section-label {
  margin: 0; font: 600 13px Inter, sans-serif;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.current-title { margin: 0; font: 600 18px var(--display); }
.current-state, .fine-print { margin: 0; font-size: 14px; color: var(--muted); }
.fine-print[hidden], .current-state:empty { display: none; }
.seg.wrap { flex-wrap: wrap; }
.cropper-panel button.plain,
.list-section .seg button {
  min-height: 44px; padding: 0 14px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--tile); color: var(--text);
  font: 500 15px Inter, sans-serif; cursor: pointer;
}
.list-section .seg button[hidden] { display: none; }
.list-section .seg button:hover { border-color: var(--faint); }
.list-section .seg button.danger { background: transparent; color: #ffb4a8; border-color: #5a2e36; }
#new-list { background: var(--accent); color: #2a1206; border-color: transparent; }
.result .result-text .result-year { font-size: 13px; }

/* ---- BGG search results ---- */

.add-panel { max-height: calc(100dvh - 32px); overflow-y: auto; }
.add-status { margin: 0; min-height: 1.2em; font-size: 14px; color: var(--muted); }
.add-status:empty { display: none; }
.results {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 6px;
  max-height: 300px; overflow-y: auto;
}
.results:empty { display: none; }
.result {
  width: 100%; min-height: 56px; padding: 6px;
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--rule); border-radius: 10px;
  background: var(--tile); color: var(--text);
  font: 15px Inter, sans-serif; text-align: left; cursor: pointer;
}
.result:hover { border-color: var(--faint); }
.result[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.result img, .result .no-thumb {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 6px; object-fit: cover; background: var(--bg);
}
.result-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.result-name { font-weight: 600; overflow-wrap: anywhere; }
.result-year { font-size: 13px; color: var(--muted); }
.form-error[hidden] { display: none; }

.tile-editor button.danger { background: transparent; color: #ffb4a8; border-color: #5a2e36; font: 500 15px Inter, sans-serif; }
.tile-editor button.danger:hover { border-color: #ffb4a8; }

/* ---- Hints: mouse vs touch wording ---- */

.hint-touch { display: none; }
@media (hover: none) {
  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
}

/* ---- Phones ---- */

@media (max-width: 600px) {
  .toolbar { padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); }
  .hint { font-size: 13px; }
  .actions { width: 100%; }
  .actions button { flex: 1; padding: 0 8px; min-height: 44px; }
  .actions select { min-height: 44px; }
  .stage { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); }

  .tile-editor {
    left: 0; bottom: 0; transform: none;
    width: 100%;
    border-radius: 16px 16px 0 0; border-bottom: 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
  .seg { flex: 1; }
  #editor-tiers button { flex: 1; }
}

.credit {
  margin-top: -12px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  font-size: 14px; color: var(--faint);
}
.credit[hidden], .credit img[hidden] { display: none; }
/* BGG's logo has dark text made for light backgrounds: show it unaltered on a white chip. */
.credit img {
  height: 46px; width: auto; box-sizing: border-box;
  padding: 6px 10px;
  background: #ffffff; border-radius: 8px;
}
