:root {
  --bg: #f1f4f2;
  --card: #ffffff;
  --fg: #1c2320;
  --muted: #66756e;
  --border: #dde4e0;
  --accent: #1b8a4c;
  --accent-fg: #ffffff;
  --accent-soft: #e3f3e9;
  --danger: #c0392b;
  --danger-soft: #fbe9e7;
  --alt: #2a6fb0;
  --warn: #a8770a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101513;
    --card: #19211d;
    --fg: #e6ece8;
    --muted: #8fa098;
    --border: #2a3732;
    --accent: #38b171;
    --accent-fg: #07130c;
    --accent-soft: #16301f;
    --danger: #e06055;
    --danger-soft: #3a1d1a;
    --alt: #63a8e8;
    --warn: #d3a63a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; font-size: .85em; }

/* top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--accent);
  color: var(--accent-fg);
}
.brand { font-weight: 700; letter-spacing: .4px; color: var(--accent-fg); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.account-name { font-size: .85rem; color: var(--accent-fg); opacity: .9; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-ghost {
  background: rgba(255, 255, 255, .18);
  border-color: transparent;
  color: var(--accent-fg);
}
.btn-ghost:hover { border-color: var(--accent-fg); }
.btn-block { width: 100%; text-align: center; margin-top: 4px; }

/* auth pages */
.auth-wrap { max-width: 420px; margin: 6vh auto 0; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card form { margin-top: 14px; }
.auth-alt { margin-bottom: 0; }
.timer-chip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .2);
  color: var(--accent-fg);
  font-size: .82rem;
  max-width: 60%;
  overflow: hidden;
  white-space: nowrap;
}
.timer-chip:hover { text-decoration: none; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #8cf3ac; animation: pulse 1.4s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .25; } }

/* layout */
main { max-width: 800px; margin: 0 auto; padding: 16px 16px 32px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.page-head .muted { margin: 4px 0 0; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.count { margin: 0 0 10px; font-size: .85rem; }
.empty { color: var(--muted); padding: 14px 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2 { flex: 1; }

details.card > summary { cursor: pointer; font-weight: 600; }

/* flash */
.flash {
  max-width: 800px;
  margin: 12px auto 0;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--fg);
  border: 1px solid var(--border);
  font-size: .9rem;
}
.flash.error { background: var(--danger-soft); border-color: var(--danger); }

/* stats */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: .78rem; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row.ignored { opacity: .55; }
.row-main { flex: 1; display: flex; align-items: center; gap: 10px; color: inherit; min-width: 0; }
.row-main:hover { text-decoration: none; }
.row-main > span { display: block; min-width: 0; }
.row-title { font-weight: 600; display: block; }
.row-sub { color: var(--muted); font-size: .82rem; display: block; }
.row-side { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.row-actions { display: flex; gap: 6px; }
.avatar {
  flex: none;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
}
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; flex: none; background: var(--accent-soft); }
.thumb.placeholder { display: grid; place-items: center; font-weight: 700; color: var(--accent); }
.hero-thumb { width: 64px; border-radius: 10px; }

/* badges */
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: middle;
}
.badge-alt { background: var(--accent-soft); color: var(--alt); }
.badge-warn { background: transparent; border: 1px solid var(--warn); color: var(--warn); }

/* buttons */
.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  font: inherit;
  font-size: .88rem;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-small { padding: 3px 9px; font-size: .78rem; border-radius: 7px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }

/* forms */
label { display: block; margin-bottom: 10px; font-size: .88rem; }
input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="password"], select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 0 0 12px; padding: 10px 12px; }
legend { padding: 0 6px; font-size: .82rem; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 14px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { margin-top: 0; width: auto; flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.check input { margin: 0; width: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .85rem;
  cursor: pointer;
}
.chip input { margin: 0; }
.chip em { color: var(--muted); font-style: normal; font-size: .78rem; }

/* filter bar */
.filter-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.filter-bar label { margin: 0; }
.filter-bar input[type="search"] { width: auto; flex: 1; min-width: 160px; margin: 0; }
.filter-bar select { width: auto; margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.segmented a { padding: 6px 12px; font-size: .82rem; color: var(--muted); }
.segmented a.active { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.segmented a:hover { text-decoration: none; }

/* tables */
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: none; }
.table tr.winner td { background: var(--accent-soft); }
.scores .score-input { width: 90px; margin: 0; }
.scores .player-select { width: 100%; margin: 0; padding: 4px; font-size: .85rem; }
.scores .roles-cell { min-width: 130px; }
.scores .role-select { width: 100%; margin: 0 0 4px; padding: 4px; font-size: .85rem; }
.scores .new-role-input { width: 100%; margin: 0; padding: 6px 8px; font-size: .85rem; }
.scores input[type="checkbox"] { margin: 0; }

/* score sheets */
.sheet-title { margin: 18px 0 8px; font-size: .95rem; }
.sheet-scroll { overflow-x: auto; }
.sheet-grid th, .sheet-grid td { text-align: center; white-space: nowrap; }
.sheet-grid th:first-child, .sheet-grid td:first-child { text-align: left; }
.sheet-grid input[type="text"] { width: 80px; margin: 0; padding: 6px 8px; text-align: right; }
.sheet-grid input[type="checkbox"] { margin: 0; }
.sheet-grid tfoot th, .sheet-grid tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.sheet-editor input[type="text"] { width: 100%; }
.sheet-editor input[type="number"] { width: 80px; }
.sheet-editor select { width: auto; }
.sheet-editor th, .sheet-editor td { padding: 5px 6px; vertical-align: middle; }

/* photos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; margin-bottom: 12px; }
.photo { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.photo form { margin: 0; }

/* timer */
.timer-card { border-color: var(--accent); }.timer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.timer-clock { font-variant-numeric: tabular-nums; font-size: 2rem; font-weight: 700; color: var(--accent); }
.timer-clock small { display: block; text-align: right; font-size: .7rem; color: var(--muted); font-weight: 400; }

/* tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1;
  text-align: center;
  padding: 12px 4px;
  color: var(--muted);
  font-size: .8rem;
}
.tabbar a.active { color: var(--accent); font-weight: 700; }
.tabbar a:hover { text-decoration: none; }

@media (max-width: 480px) {
  .timer-clock { font-size: 1.5rem; }
  .page-head { flex-wrap: wrap; }
}
