/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;
  --bg: #0e0d0b;
  --bg-2: #161410;
  --surface: #1c1a15;
  --surface-2: #26231c;
  --line: #34302699;
  --text: #f4efe4;
  --muted: #a8a191;
  --faint: #6f695c;
  --gold: #d9b45a;
  --gold-2: #f0d48a;
  --gold-ink: #1a1408;
  --fresh: #fa320a;
  --green: #5fbf77;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 8px 24px rgb(0 0 0 / 0.35);
  --radius: 12px;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --gutter: clamp(16px, 4vw, 40px);
  --max: 1320px;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f7f3ea;
    --bg-2: #efe9dc;
    --surface: #fffdf8;
    --surface-2: #f1ebdf;
    --line: #d9d0bd;
    --text: #1d1a14;
    --muted: #645d4f;
    --faint: #958c7a;
    --gold: #a37a12;
    --gold-2: #7d5c06;
    --gold-ink: #fffdf6;
    --shadow: 0 1px 2px rgb(60 40 0 / 0.08), 0 8px 24px rgb(60 40 0 / 0.08);
  }
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  scrollbar-gutter: stable;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
img {
  display: block;
  max-width: 100%;
}
a {
  color: inherit;
}
button,
input,
select {
  font: inherit;
  color: inherit;
}
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.wrap {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}
h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  border-bottom: 1px solid var(--line);
  /* Clear the notch / Dynamic Island when launched from the home screen (viewport-fit=cover). */
  padding-top: env(safe-area-inset-top);
}
.site-header .wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.15rem;
  font-weight: 600;
  margin-right: auto;
  white-space: nowrap;
}
.brand svg {
  color: var(--gold);
}
.header-progress {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.header-progress b {
  color: var(--text);
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  position: relative;
}
.icon-btn:hover {
  border-color: var(--gold);
}
.lock-open {
  display: none;
}
.can-edit .lock-open {
  display: block;
}
.can-edit .lock-closed {
  display: none;
}
[data-sync]::after {
  content: '';
  position: absolute;
  right: 0;
  bottom: 0;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid var(--bg);
  background: var(--faint);
}
[data-sync='ok']::after {
  background: var(--green);
}
[data-sync='pending']::after {
  background: var(--gold);
}
[data-sync='error']::after {
  background: var(--fresh);
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 64px;
  padding: 28px 0 calc(40px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 0.82rem;
}
.site-footer a {
  color: var(--muted);
}

/* ---------- Buttons / chips ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn:hover {
  border-color: var(--gold);
}
.btn-gold {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
}

/* ---------- Stars ---------- */
.stars {
  --size: 18px;
  position: relative;
  display: inline-flex;
  width: calc(var(--size) * 5);
  height: var(--size);
  flex: none;
}
.stars-bg,
.stars-fill {
  position: absolute;
  inset: 0;
  -webkit-mask: var(--star-mask) 0 0 / var(--size) var(--size) repeat-x;
  mask: var(--star-mask) 0 0 / var(--size) var(--size) repeat-x;
}
.stars-bg {
  background: var(--surface-2);
}
.stars-fill {
  background: var(--gold);
  width: calc(var(--rating, 0) / 5 * 100%);
  transition: width 0.15s;
}
:root {
  --star-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.5l2.94 6.1 6.56.86-4.8 4.6 1.2 6.54L12 17.4l-5.9 3.2 1.2-6.54-4.8-4.6 6.56-.86z'/%3E%3C/svg%3E");
}
.stars-input {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(10, 1fr);
}
.stars-input button {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
  min-height: 0;
}
.stars-input button:focus-visible {
  outline-offset: 0;
}
.stars-lg {
  --size: 40px;
}

/* ---------- Poster ---------- */
.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2) center / cover no-repeat;
}
.poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.poster-fallback {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 12px;
  text-align: center;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--gold-2);
  background: radial-gradient(120% 80% at 50% 0%, var(--surface-2), var(--bg-2));
  border: 1px solid var(--line);
  border-radius: inherit;
}

/* ---------- Gen Z mode ---------- */
html.genz .nz,
html:not(.genz) .gz {
  display: none !important;
}
.genz-btn {
  width: auto;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--muted);
}
.genz-btn[aria-pressed='true'] {
  border-color: transparent;
  background: linear-gradient(90deg, #ff5fa2, #a66bff, #4fc3ff);
  color: #fff;
}
html.genz h1 em {
  background: linear-gradient(90deg, #ff5fa2, #a66bff, #4fc3ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent !important;
}

/* ---------- Unlock dialog ---------- */
.dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop {
  background: rgb(0 0 0 / 0.6);
  backdrop-filter: blur(3px);
}
.dialog h2 {
  margin: 0 0 6px;
}
.dialog p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.92rem;
}
.dialog input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 16px; /* prevents iOS zoom-on-focus */
}
.dialog-error {
  margin-top: 10px !important;
  color: var(--fresh) !important;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- Not found / error pages ---------- */
.message {
  padding-top: clamp(28px, 6vw, 64px);
}
.message a {
  color: var(--gold);
}

/* ---------- Blazor error bar ---------- */
#blazor-error-ui {
  display: none;
  position: fixed;
  inset: auto 0 0;
  z-index: 1000;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  background: var(--surface-2);
  color: var(--text);
  border-top: 1px solid var(--line);
  box-shadow: var(--shadow);
}
#blazor-error-ui .reload {
  color: var(--gold);
}
#blazor-error-ui .dismiss {
  float: right;
  cursor: pointer;
}
