:root {
  --bg: #0e1116;
  --surface: #171b22;
  --surface2: #1f2530;
  --border: #2a3140;
  --text: #e8ebf0;
  --muted: #8b94a5;
  --accent: #3ddc97;
  --accent-ink: #06281a;
  --danger: #ff5c6c;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100dvh; display: flex; flex-direction: column; }
a { color: var(--accent); }
h1 { margin: 8px 0 4px; font-size: 28px; }
h2 { margin: 0 0 12px; font-size: 20px; }
.muted { color: var(--muted); }
.page, .app { width: 100%; max-width: 520px; margin: 0 auto; padding: 16px 16px 8px; flex: 1; }

/* Lomake */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; display: grid; gap: 12px; margin-top: 16px; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, select { width: 100%; padding: 12px; font-size: 16px; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.error { color: var(--danger); margin: 0; }

/* Napit */
button, .btn { font: inherit; color: var(--text); background: var(--surface2); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px 14px; cursor: pointer; text-align: center; text-decoration: none; display: inline-block; }
button:active, .btn:active { transform: scale(.97); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
button.danger { color: var(--danger); border-color: #5a2a33; }
button.ghost { background: transparent; }
button:disabled { opacity: .5; }

/* Laskuri */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.meta { color: var(--muted); font-size: 14px; text-align: center; flex: 1; }
.icon { padding: 8px 12px; text-decoration: none; color: var(--text); font-size: 15px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { background: var(--surface); border: 2px solid var(--border); border-radius: 16px; padding: 12px; text-align: center; min-width: 0; }
.card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61, 220, 151, .15); }
.card .name { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.active .name { color: var(--text); font-weight: 600; }
.card .rem { font-size: clamp(48px, 17vw, 84px); font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.card.canout .rem { color: var(--accent); }
.card .sub { display: flex; justify-content: space-between; gap: 4px; font-size: 12px; color: var(--muted); }
.card .sub b { color: var(--text); font-weight: 600; }

.entry { display: flex; align-items: baseline; justify-content: space-between; margin: 14px 4px 6px; }
.entry-val { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }
.quick { display: grid; grid-template-columns: repeat(9, 1fr); gap: 6px; margin-bottom: 8px; }
.quick button { padding: 8px 0; font-size: 14px; color: var(--muted); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pad button { min-height: 58px; font-size: 24px; font-weight: 600; }
.pad button.ok { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 800; }
.actions { display: flex; gap: 8px; margin-top: 10px; }
.actions button { flex: 1; }

.history { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.history li { display: flex; justify-content: space-between; padding: 6px 10px; background: var(--surface); border-radius: 8px; }
.history li.bust b { color: var(--danger); }
.history li b { color: var(--text); }

/* Ikkunat */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .7); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.overlay[hidden] { display: none; }
.dialog { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 20px; display: grid; gap: 12px; }
.stats { width: 100%; border-collapse: collapse; font-size: 14px; }
.stats td, .stats th { padding: 6px 4px; text-align: center; border-bottom: 1px solid var(--border); }
.stats td:first-child, .stats th:first-child { text-align: left; color: var(--muted); font-weight: 400; }

.toast { position: fixed; left: 50%; bottom: calc(56px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--surface2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 12px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 20; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { border-color: var(--danger); }

.site-footer { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); text-align: center; font-size: 12px; color: var(--muted); }
.site-footer a { color: var(--muted); }

/* ---------- Sivut: navigaatio, sisältö, taulukot ---------- */
.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5; }
.nav a, .nav .linkbtn { color: var(--muted); text-decoration: none; padding: 8px 10px; border-radius: 10px; font-size: 15px; }
.nav a:hover, .nav .linkbtn:hover { color: var(--text); background: var(--surface2); }
.nav .brand { color: var(--text); font-weight: 800; margin-right: 6px; }
.admin-nav form { margin-left: auto; }
.page.wide, .page.wide + * { max-width: 1100px; }
.page { padding-bottom: 24px; }
section { margin-top: 28px; }
h3 { margin: 18px 0 8px; font-size: 16px; color: var(--muted); font-weight: 600; }
.small { font-size: 13px; }
.quiet { color: var(--muted); opacity: .7; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-head h1, .section-head h2 { margin: 8px 0; }
.meta-line { color: var(--muted); margin: 4px 0 12px; }
.notice { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.notice.ok { border-color: #1f6b4a; background: rgba(61, 220, 151, .08); }
.notice.err { border-color: #7a2a35; background: rgba(255, 92, 108, .08); color: #ffb3bb; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); color: var(--muted); }
.chip.ok { color: var(--accent); border-color: #1f6b4a; }
.chip.live { color: #ffc857; border-color: #6b5320; }
.small-btn { padding: 6px 12px; font-size: 14px; }
.wide-btn { width: 100%; margin-top: 8px; }
.linkbtn { background: none; border: 0; padding: 0; cursor: pointer; color: var(--accent); font: inherit; }
.danger-text { color: var(--danger) !important; }
form.inline, .inline { display: inline; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input { flex: 1; }
.check { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.check input { width: auto; }
fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 10px; margin: 0; min-width: 0; }
legend { color: var(--muted); padding: 0 6px; font-size: 14px; }
textarea { width: 100%; padding: 12px; font: inherit; color: var(--text); background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.copyrow { display: flex; gap: 8px; }
.copyrow input { flex: 1; font-size: 13px; }
.danger-zone { border-color: #5a2a33; }
.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.plain li { display: flex; justify-content: space-between; gap: 10px; background: var(--surface); padding: 8px 12px; border-radius: 10px; flex-wrap: wrap; }
.names { margin: 8px 0; padding-left: 22px; columns: 2; }
code { background: var(--surface2); padding: 1px 6px; border-radius: 6px; }

.tbl { width: 100%; border-collapse: collapse; font-size: 15px; }
.tbl th, .tbl td { padding: 8px 6px; text-align: center; border-bottom: 1px solid var(--border); }
.tbl th { color: var(--muted); font-weight: 600; font-size: 13px; }
.tbl td.l, .tbl th.l { text-align: left; }
.tbl.kv td:first-child { color: var(--muted); }
.tbl.kv td:last-child { text-align: right; }
.tbl input { width: 90px; padding: 8px; }
.matches-admin .grp td { background: var(--surface); color: var(--muted); font-size: 13px; text-align: left; }
.score-form input { width: 56px; padding: 6px; text-align: center; }
.pair-row { align-items: center; margin-bottom: 8px; }
.pair-no { flex: 0 0 24px; color: var(--muted); }

.cards-list { display: grid; gap: 10px; }
.event { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 14px; text-decoration: none; color: var(--text); }
.event:hover { border-color: var(--accent); }
.event .when { flex: 0 0 96px; display: grid; }
.event .what { flex: 1; min-width: 0; }
.event .title { font-weight: 700; }
.event .side { display: grid; gap: 4px; justify-items: end; text-align: right; font-size: 13px; }

.tabs { display: flex; gap: 6px; margin: 14px 0; }
.tabs a { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); text-decoration: none; }
.tabs a.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.share { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

/* ---------- Kaaviot ---------- */
.rounds { display: flex; gap: 22px; overflow-x: auto; padding: 8px 2px 14px; align-items: stretch; }
.round { flex: 0 0 210px; display: flex; flex-direction: column; }
.round-title { color: var(--muted); font-size: 13px; text-align: center; margin-bottom: 8px; }
.matches { display: flex; flex-direction: column; justify-content: space-around; gap: 12px; flex: 1; }
.match { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.match.is-live { border-color: #6b5320; }
.match .side { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 14px; }
.match .side:last-of-type { border-bottom: 0; }
.match .side.win { color: var(--accent); font-weight: 700; }
.match .side.empty { color: var(--muted); }
.match .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.match .foot { padding: 4px 10px; font-size: 12px; color: var(--muted); background: var(--surface2); }
.match .live { color: #ffc857; }
.group { margin-bottom: 26px; }
.gm-round { margin-top: 14px; }
.gm-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }

@media (max-width: 560px) {
  .event { flex-wrap: wrap; }
  .event .when { flex-basis: 100%; display: flex; gap: 8px; }
  .names { columns: 1; }
  .row { flex-wrap: wrap; }
}
