:root {
  --bg: #faf6f5;
  --surface: #ffffff;
  --ink: #1d1d1b;
  --muted: rgba(29, 29, 27, 0.65);
  --line: #ece6e3;
  --accent: #8ab400;
  --accent-soft: #e7f5c4;
  --accent-ink: #3b5b00;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  --font: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; }

/* header */
.site-header { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--line); }
.site-header-inner { max-width: 960px; margin: 0 auto; padding: 8px 16px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand img { height: 36px; display: block; }
.brand-tag { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.tabs { order: 3; width: 100%; display: flex; }
.tab { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 44px; padding: 4px 4px; font-weight: 700; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }
.link { display: inline-flex; align-items: center; min-height: 44px; background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--ink); text-decoration: none; cursor: pointer; }
.link:hover { text-decoration: underline; }
@media (min-width: 768px) {
  .site-header-inner { padding-top: 0; }
  .tabs { order: 0; width: auto; }
  .tab { flex: 0 0 auto; padding: 4px 8px; }
}

/* layout and controls */
.page { max-width: 960px; margin: 0 auto; padding: 16px; }
.page-title { font-size: 20px; margin: 4px 0 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar > .input { flex: 1 1 180px; width: auto; }
.segmented { display: inline-flex; gap: 3px; padding: 3px; background: var(--line); border-radius: 999px; }
.segmented button { border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 700; color: var(--ink); padding: 4px 14px; min-height: 44px; border-radius: 999px; cursor: pointer; }
.segmented button.is-on { background: var(--ink); color: #fff; }
.segmented button:disabled { cursor: not-allowed; opacity: 0.6; }
.input { width: 100%; min-height: 44px; padding: 8px 12px; font: inherit; font-size: 16px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.input:focus { outline: 2px solid var(--accent-ink); outline-offset: 1px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px; border: 0; border-radius: 10px; font: inherit; font-weight: 800; text-decoration: none; cursor: pointer; }
.btn-primary { background: var(--accent); color: var(--ink); }
.btn-ghost { background: var(--line); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { min-height: 44px; padding: 4px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-grow { flex: 1; }
.btn-toggle.is-on { background: var(--ink); color: #fff; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.chip { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent-ink); }
.badge { display: inline-block; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px; background: var(--ink); color: #fff; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.message { padding: 10px 12px; border-radius: 10px; font-weight: 600; margin: 8px 0; }
.message-success { background: var(--accent-soft); color: var(--accent-ink); }
.message-danger { background: #fbe4e1; color: #8a1f12; }
.message-info { background: var(--line); color: var(--ink); }
.card { background: var(--surface); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.card-title { font-size: 16px; margin: 0 0 8px; }
.card + .card { margin-top: 16px; }
.section-label { font-size: 12px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 16px 4px 8px; }
.grid-2 { display: grid; gap: 16px; }
.actions-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-form .input { flex: 1 1 180px; width: auto; }
@media (min-width: 768px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ranking */
.rank-cards { display: flex; flex-direction: column; gap: 6px; }
.rank-card { display: grid; grid-template-columns: 28px 1fr auto auto; align-items: center; gap: 10px; min-height: 56px; padding: 10px 12px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.rank-card-rank { font-weight: 800; text-align: right; }
.rank-card-main { display: flex; flex-direction: column; min-width: 0; }
.rank-card-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-card-sub { font-size: 12px; color: var(--muted); }
.rank-card-points, .num { font-variant-numeric: tabular-nums; font-weight: 800; text-align: right; }
.rank-table { display: none; width: 100%; border-collapse: separate; border-spacing: 0 4px; }
.rank-table th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); text-align: left; padding: 4px 12px; }
.rank-table th.num { text-align: right; }
.rank-table th.group,
.rank-table .count { text-align: center; }
.rank-table td.count { font-variant-numeric: tabular-nums; font-weight: 800; }
.rank-table td { background: var(--surface); padding: 10px 12px; }
.rank-table td:first-child { border-radius: 10px 0 0 10px; font-weight: 800; }
.rank-table td:last-child { border-radius: 0 10px 10px 0; }
.rank-table tr.is-clickable { cursor: pointer; }
.rank-table tr.is-clickable:hover td { background: #fffdf8; }
.rank-table a { text-decoration: none; font-weight: 700; }
.download { display: inline-block; margin-top: 16px; }
@media (min-width: 768px) {
  .rank-cards { display: none; }
  .rank-table { display: table; }
}

/* results */
.result-list { display: flex; flex-direction: column; gap: 8px; }
.result-card { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 0 12px; }
.result-summary { display: flex; align-items: center; gap: 10px; min-height: 52px; font-weight: 700; cursor: pointer; list-style: none; }
.result-summary::-webkit-details-marker { display: none; }
.result-summary::after { content: "▾"; margin-left: auto; color: var(--muted); }
.result-card[open] .result-summary::after { content: "▴"; }
.result-size { color: var(--muted); font-weight: 600; }
.placements { list-style: none; margin: 0; padding: 0 0 8px; }
.placements li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.placement-pos { font-weight: 800; }
.placement-points { font-weight: 800; font-variant-numeric: tabular-nums; }
.result-actions { display: flex; gap: 8px; padding: 0 0 12px; }

/* profile */
.back-link { display: inline-block; font-weight: 700; color: var(--accent-ink); text-decoration: none; }
.profile-hero { background: var(--surface); border-radius: 14px; padding: 16px; box-shadow: var(--shadow); }
.profile-name { font-size: 22px; margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { display: flex; flex-direction: column; background: var(--bg); border-radius: 10px; padding: 8px; text-align: center; }
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--muted); }
.profile-result { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 8px; padding: 10px 12px; margin-bottom: 6px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.profile-result-points { font-weight: 800; color: var(--accent-ink); font-variant-numeric: tabular-nums; }

/* admin: result entry */
.entry-form { padding-bottom: 88px; }
.slot-list { display: flex; flex-direction: column; gap: 8px; }
.slot { display: grid; grid-template-columns: 32px 1fr 84px; align-items: start; gap: 8px; padding: 10px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.slot-pos { font-weight: 800; padding-top: 12px; text-align: center; }
.slot-players { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.input-points { text-align: right; font-weight: 800; }
.sticky-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; gap: 8px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); }
@media (min-width: 768px) {
  .entry-form { padding-bottom: 0; }
  .sticky-bar { position: sticky; margin-top: 16px; border: 1px solid var(--line); border-radius: 12px; }
}
.search { position: relative; }
.search .input.is-chosen { border-color: var(--accent); background: #fbfff0; }
.search-menu { position: absolute; left: 0; right: 0; top: calc(100% + 2px); z-index: 20; background: var(--surface); border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14); overflow: hidden; }
.search-item { display: block; width: 100%; min-height: 44px; padding: 12px; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; font: inherit; color: var(--ink); cursor: pointer; }
.search-item:first-child { border-top: 0; }
.search-item:hover { background: var(--bg); }
.search-item-new { color: var(--accent-ink); font-weight: 700; }

/* admin: players */
.player-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.player-item { display: grid; grid-template-columns: 1fr; gap: 6px; padding: 10px 12px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.player-item-main { display: flex; align-items: baseline; gap: 8px; }
.player-item-name { font-weight: 700; }
.player-item-points { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player-item-actions { display: flex; flex-wrap: wrap; gap: 6px; }
@media (min-width: 768px) { .player-item { grid-template-columns: 1fr auto auto; align-items: center; } }

/* admin: settings */
.division-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) 64px 88px 44px; align-items: center; gap: 6px; padding: 8px 0; border-top: 1px solid var(--line); background: var(--surface); }
.division-row .input { padding: 8px; }
.division-row .btn { min-width: 44px; padding: 0; }
.division-row.is-sorting { transition: transform 0.15s ease; }
.division-row.is-dragging { position: relative; z-index: 2; transition: none; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14); }
.drag-handle { touch-action: none; cursor: grab; font-size: 18px; }
.is-dragging .drag-handle { cursor: grabbing; }
.division-head { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); border-top: 0; }
.division-rest { color: var(--muted); font-weight: 600; text-align: center; }
.scheme-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.scheme-row > span { flex: 1 1 200px; }
.danger-zone { margin-top: 24px; padding: 16px; background: var(--surface); border: 2px solid var(--danger); border-radius: 12px; }
.danger-zone h2 { margin: 0 0 8px; font-size: 18px; color: var(--danger); }
@media (min-width: 768px) {
  /* Fixed side columns: each row is its own grid, so `auto` would size the empty header cells to 0. */
  .division-row { grid-template-columns: 44px 1fr 100px 140px 44px; }
}

/* dialog and toast */
.dialog { width: min(420px, calc(100vw - 32px)); padding: 20px; border: 0; border-radius: 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.dialog::backdrop { background: rgba(29, 29, 27, 0.45); }
.dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog-title { margin: 0; font-size: 17px; }
.dialog-text { margin: 0; color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: 96px; z-index: 50; max-width: calc(100vw - 32px); transform: translateX(-50%); padding: 10px 16px; border-radius: 999px; font-weight: 700; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); }
.toast-success { background: var(--ink); color: #fff; }
.toast-danger { background: var(--danger); color: #fff; }

/* login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: min(400px, 100%); padding: 24px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.login-logo { display: block; height: 48px; margin: 0 auto 8px; }
.login-card h1 { text-align: center; font-size: 20px; }
.login-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
