:root {
  --bg: #101012;
  --bg-panel: #17171b;
  --bg-elevated: #1e1e23;
  --bg-hover: #232329;
  --border: #2a2a30;
  --border-soft: #202024;
  --text: #ececee;
  --text-muted: #8d8d96;
  --text-faint: #56565e;
  --accent: #e3432f;
  --accent-soft: rgba(227, 67, 47, 0.14);
  --accent-hover: #ff5a44;

  --stato-in-corso: #d9b23c;
  --stato-completato: #3fae6a;
  --stato-in-pausa: #4f8fd1;
  --stato-droppato: #5b5b63;
  --stato-stagione-finita: #9575d6;
  --stato-da-iniziare: #3a3a40;

  --radius: 3px;
  --font-display: 'Anton', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

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

[hidden] { display: none !important; }

/* ===== halftone texture ===== */
.halftone {
  background-image: radial-gradient(circle, rgba(227,67,47,0.35) 1px, transparent 1px);
  background-size: 10px 10px;
}

/* ===== stamp mark ===== */
.stamp-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 700;
  transform: rotate(-8deg);
  margin-bottom: 14px;
}
.stamp-mark.small {
  width: 34px;
  height: 34px;
  font-size: 16px;
  border-width: 2px;
  margin-bottom: 0;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.06em;
  font-size: 34px;
  margin: 0;
}
.wordmark.small { font-size: 18px; }

/* ===== buttons ===== */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  padding: 9px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}
.btn:hover { background: var(--bg-hover); border-color: var(--text-faint); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { color: var(--text); }
.btn-danger {
  background: transparent;
  border-color: #6b2b26;
  color: #e0655a;
}
.btn-danger:hover { background: rgba(224,101,90,0.1); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ===== auth screen ===== */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle, rgba(227,67,47,0.28) 1px, transparent 1px) 0 0/12px 12px,
    var(--bg);
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  text-align: center;
}
.auth-sub {
  color: var(--text-muted);
  font-size: 14px;
  margin: 8px 0 28px;
  line-height: 1.5;
}
.auth-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.field input, .field select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.auth-actions { display: flex; gap: 10px; margin-top: 6px; }
.auth-actions .btn { flex: 1; }
.auth-error {
  color: #e0655a;
  font-size: 13px;
  background: rgba(224,101,90,0.1);
  border: 1px solid #6b2b26;
  border-radius: var(--radius);
  padding: 8px 10px;
  margin: 0;
}
.auth-notice {
  color: var(--stato-completato);
  font-size: 13px;
  margin-top: 16px;
}
.auth-toggle {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  margin: 4px 0 0;
}
.link-btn-plain {
  background: none;
  border: none;
  color: var(--accent-hover);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  padding: 0 0 0 4px;
}
.link-btn-plain:hover { text-decoration: underline; }

/* ===== app shell ===== */
.app-screen { min-height: 100vh; }

.topbar {
  border-bottom: 1px solid var(--border);
  background:
    radial-gradient(circle, rgba(227,67,47,0.18) 1px, transparent 1px) 0 0/10px 10px,
    var(--bg-panel);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.topbar-stats { display: flex; gap: 24px; margin-right: auto; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat-value { font-family: var(--font-mono); font-size: 18px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.user-email { font-size: 13px; color: var(--text-muted); }

.content { max-width: 1400px; margin: 0 auto; padding: 24px; }

/* ===== toolbar ===== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.toolbar-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: auto;
}
.input, .select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
}
.input { width: 170px; }
.input:focus, .select:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-faint); }

/* ===== table ===== */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
}
.tracker-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tracker-table thead {
  background: var(--bg-elevated);
}
.tracker-table th {
  text-align: left;
  padding: 10px 10px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tracker-table th[data-sort] { cursor: pointer; user-select: none; }
.tracker-table th[data-sort]:hover { color: var(--text); }
.sort-ind { font-size: 10px; color: var(--accent); }

.tracker-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-panel);
  vertical-align: middle;
}
.tracker-table tbody tr:hover td { background: var(--bg-hover); }

.col-n { width: 36px; color: var(--text-faint); font-family: var(--font-mono); }
.col-titolo { min-width: 220px; font-weight: 600; cursor: pointer; }
.col-titolo:hover { color: var(--accent-hover); }
.col-cap { width: 88px; text-align: center; font-family: var(--font-mono); }
.col-perc { width: 56px; font-family: var(--font-mono); }
.col-stato { width: 130px; }
.col-voto { width: 50px; font-family: var(--font-mono); text-align: center; }
.col-commento { min-width: 160px; color: var(--text-muted); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-sito { width: 100px; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.col-link { width: 60px; }
.col-actions { width: 36px; }

.cap-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.cap-value {
  min-width: 24px;
  text-align: center;
}

.chip-cap-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 24px;
  height: 24px;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: var(--font-mono);
  line-height: 1;
}
.chip-cap-btn:hover { border-color: var(--accent); color: var(--accent-hover); }

.perc-bar-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.perc-bar-track {
  width: 34px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.perc-bar-fill { height: 100%; background: var(--accent); }

.status-pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}
.status-da-iniziare { color: var(--text-faint); border-color: var(--border); }
.status-in-corso { color: var(--stato-in-corso); background: rgba(217,178,60,0.12); }
.status-completato { color: var(--stato-completato); background: rgba(63,174,106,0.12); }
.status-in-pausa { color: var(--stato-in-pausa); background: rgba(79,143,209,0.12); }
.status-droppato { color: var(--stato-droppato); background: rgba(91,91,99,0.18); }
.status-stagione-finita { color: var(--stato-stagione-finita); background: rgba(149,117,214,0.12); }

/* row left-border accent by status */
.row-in-corso { box-shadow: inset 3px 0 0 var(--stato-in-corso); }
.row-completato { box-shadow: inset 3px 0 0 var(--stato-completato); }
.row-in-pausa { box-shadow: inset 3px 0 0 var(--stato-in-pausa); }
.row-droppato { box-shadow: inset 3px 0 0 var(--stato-droppato); }
.row-stagione-finita { box-shadow: inset 3px 0 0 var(--stato-stagione-finita); }

.link-btn {
  color: var(--accent-hover);
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }
.link-empty { color: var(--text-faint); font-size: 12px; }

.row-edit-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 15px;
  padding: 4px;
}
.row-edit-btn:hover { color: var(--text); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
  background: var(--bg-panel);
}

/* ===== modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 8, 9, 0.72);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: backdrop-in 0.15s ease;
}
@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px 28px 28px;
  max-height: 88vh;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,0.55), 0 0 0 1px rgba(227,67,47,0.06);
  position: relative;
  animation: modal-in 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}
.modal::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), transparent 85%);
  border-radius: 10px 10px 0 0;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
}
.modal h2 {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.03em;
  font-size: 21px;
  margin: 0;
}
.modal-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.modal-close:hover { color: var(--accent-hover); border-color: var(--accent); }

.book-form { display: flex; flex-direction: column; gap: 16px; }
.book-form .field span {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.book-form input, .book-form select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 14px;
  width: 100%;
  transition: border-color 0.12s ease;
}
.book-form input:focus, .book-form select:focus { border-color: var(--accent); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }
.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 18px;
  border-top: 1px solid var(--border-soft);
}
.modal-actions-right { display: flex; gap: 10px; }

.import-hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0 0 14px;
}
.import-hint code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-elevated);
  padding: 1px 4px;
  border-radius: 2px;
}
.import-textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 10px 12px;
  resize: vertical;
}
.import-textarea:focus { border-color: var(--accent); }
.import-preview {
  font-size: 13px;
  color: var(--stato-completato);
  margin: 12px 0 0;
}

/* ===== toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-color: #6b2b26; color: #e0655a; }

/* ===== responsive ===== */
@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; gap: 12px; }
  .topbar-stats { order: 3; width: 100%; margin-right: 0; }
  .toolbar-filters { margin-left: 0; width: 100%; }
  .input { flex: 1; min-width: 120px; }
  .content { padding: 14px; }
  .table-wrap { overflow-x: auto; }
  .tracker-table { min-width: 900px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}