[hidden] { display: none !important; }
:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --text: #0f1b2a;
  --muted: #5d6b7e;
  --line: #dde3eb;
  --brand: #0b1d33;
  --accent: #1f7ae0;
  --accent-soft: #e3effd;
  --good: #1a8f55;
  --good-soft: #e1f5ea;
  --bad: #c73a3a;
  --bad-soft: #fbe7e7;
  --gold: #c08a00;
  --gold-soft: #fff4d6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 27, 42, .06), 0 4px 14px rgba(15, 27, 42, .05);
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a121d; --surface: #111c2a; --surface-2: #172536; --text: #e7edf5; --muted: #93a2b5; --line: #223246;
    --brand: #060d16; --accent: #4fa3ff; --accent-soft: #14304f; --good: #3cc47f; --good-soft: #12301f;
    --bad: #f07070; --bad-soft: #3a1a1a; --gold: #f2c14e; --gold-soft: #3a2f10;
    --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.35rem; } h2 { font-size: 1.1rem; } h3 { font-size: 1rem; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .tiny { font-size: .72rem; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; } .center { text-align: center; }
.row { display: flex; align-items: center; gap: .5rem; }
.row.wrap { flex-wrap: wrap; } .row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: .75rem; }
.hidden { display: none !important; }

/* Yläpalkki */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; background: var(--brand); color: #fff;
}
.brand { color: #fff; font-weight: 700; display: flex; white-space: nowrap; flex: none; align-items: center; gap: .5rem; font-size: 1.05rem; }
.puck { width: 18px; height: 10px; border-radius: 50%; background: #e8eef6; box-shadow: 0 3px 0 #4a5d75; }
.period-chip { margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: .78rem; background: rgba(255,255,255,.12); padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 1.3rem; padding: 4px 6px; cursor: pointer; }
.menu {
  position: fixed; right: 10px; top: calc(env(safe-area-inset-top) + 52px); z-index: 30; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; min-width: 190px; overflow: hidden;
}
.menu a, .menu button { padding: 12px 16px; text-align: left; background: none; border: 0; color: var(--text); cursor: pointer; border-bottom: 1px solid var(--line); }
.menu > :last-child { border-bottom: 0; }

main { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 20px); }
.loading { padding: 3rem 0; text-align: center; color: var(--muted); }

/* Alapalkki */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 0 7px; color: var(--muted); font-size: .7rem; font-weight: 600; }
.tabbar a .ti { font-size: 1.25rem; line-height: 1.2; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active .ti { filter: none; opacity: 1; }
.badge { position: absolute; top: 4px; left: 55%; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--bad); color: #fff; font-size: .62rem; font-style: normal; display: grid; place-items: center; }
.badge.live { background: var(--good); }

/* Kortit */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.card + .card, .card + .section, .section + .card { margin-top: 12px; }
.card.flush { padding: 0; overflow: hidden; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.card-h h2 { margin: 0; }
.section { margin-top: 18px; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 0 2px 6px; }
.hero { background: linear-gradient(135deg, #0b1d33, #173b63); color: #fff; }
.hero .muted { color: #b6c6da; }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.kpi { background: rgba(255,255,255,.08); border-radius: 10px; padding: 8px 10px; }
.card:not(.hero) .kpi { background: var(--surface-2); }
.kpi b { display: block; font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.kpi span { font-size: .72rem; opacity: .8; }

/* Taulukot / listat */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.me td { background: var(--accent-soft); }
tr.link { cursor: pointer; }
.rank { width: 28px; font-weight: 700; color: var(--muted); }
.rank.r1 { color: var(--gold); }
.table-wrap { overflow-x: auto; }

.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 58px; }
.item:last-child { border-bottom: 0; }
.item .main { flex: 1; min-width: 0; }
.item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .sub { font-size: .8rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .pts { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; min-width: 48px; }
.item .pts small { display: block; font-weight: 500; color: var(--muted); font-size: .7rem; }
.item.captain { background: var(--gold-soft); }
.item.locked .name::after { content: " 🔒"; font-size: .75rem; }
.pos { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; font-size: .75rem; font-weight: 800; flex: none; }
.pos.C { background: #e0ecff; color: #1b4f9c; } .pos.W, .pos.L, .pos.R { background: #e3f6ea; color: #17693e; }
.pos.D { background: #fff0db; color: #8a5200; } .pos.G { background: #f3e6ff; color: #6a2b9c; }
@media (prefers-color-scheme: dark) {
  .pos.C { background: #16305a; color: #9cc3ff; } .pos.W, .pos.L, .pos.R { background: #143522; color: #8fe0b1; }
  .pos.D { background: #3a2a10; color: #ffcf8a; } .pos.G { background: #2d1a42; color: #d6b0ff; }
}
.team-abbr { font-weight: 700; font-size: .75rem; color: var(--muted); }

/* Painikkeet */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 10px; padding: 9px 14px; font-weight: 600; cursor: pointer; min-height: 40px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .82rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.icon { width: 36px; height: 36px; padding: 0; min-height: 0; border-radius: 10px; }
.btn.cap { font-weight: 800; color: var(--gold); }
.btn.cap.on { background: var(--gold); border-color: var(--gold); color: #fff; }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: .82rem; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .72rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
.tag.good { background: var(--good-soft); color: var(--good); } .tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.gold { background: var(--gold-soft); color: var(--gold); } .tag.blue { background: var(--accent-soft); color: var(--accent); }

/* Lomakkeet */
label.field { display: block; }
label.field span { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.switch { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.switch input { width: 20px; height: 20px; }
.auth-wrap { max-width: 400px; margin: 6vh auto 0; }
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo .puck { width: 44px; height: 24px; margin: 0 auto 12px; box-shadow: 0 7px 0 #4a5d75; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg button { border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.error { color: var(--bad); font-size: .88rem; }
.notice { background: var(--accent-soft); color: var(--text); border-radius: 10px; padding: 10px 12px; font-size: .88rem; }
.notice.warn { background: var(--gold-soft); }

/* Päivävalitsin */
.datebar { display: flex; align-items: center; gap: 8px; }
.datebar .d { flex: 1; text-align: center; font-weight: 700; }

/* Alapaneeli */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--surface); border-radius: 18px 18px 0 0;
  max-height: 86vh; overflow-y: auto; padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 760px; margin: 0 auto;
  animation: up .18s ease-out;
}
.sheet::before { content: ""; display: block; width: 40px; height: 4px; background: var(--line); border-radius: 2px; margin: 4px auto 12px; }
@keyframes up { from { transform: translateY(40px); } to { transform: none; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px); z-index: 50; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; max-width: 90vw; box-shadow: var(--shadow); }
.toast.err { background: var(--bad); color: #fff; }

/* Drafti */
.clock { font-size: 2.3rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.clock.low { color: #ff8a8a; }
.onclock { border: 2px solid var(--good); }
.needs { display: flex; gap: 6px; flex-wrap: wrap; }
.need { padding: 4px 10px; border-radius: 99px; background: var(--surface-2); font-weight: 700; font-size: .8rem; }
.need.done { opacity: .45; text-decoration: line-through; }
.board { display: grid; gap: 4px; }
.pickrow { display: grid; grid-template-columns: 38px 1fr; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); font-size: .86rem; }
.pickrow .pn { font-weight: 800; color: var(--muted); font-size: .75rem; }
.upnext { display: flex; gap: 6px; overflow-x: auto; }
.upnext .u { flex: none; padding: 5px 10px; border-radius: 8px; background: rgba(255,255,255,.1); font-size: .78rem; }
.card:not(.hero) .upnext .u { background: var(--surface-2); }
.upnext .u.me { background: var(--good); color: #fff; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 10px; margin: 12px 0; }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 8px; font-weight: 600; font-size: .85rem; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.spark { display: flex; align-items: flex-end; gap: 2px; height: 44px; }
.spark i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .8; }
.empty { padding: 26px 14px; text-align: center; color: var(--muted); }

@media (min-width: 700px) {
  main { padding-top: 20px; }
  .tabbar { max-width: 760px; margin: 0 auto; border: 1px solid var(--line); border-bottom: 0; border-radius: 16px 16px 0 0; }
}

/* ---------- Kaukalo / kentälliset ---------- */
:root {
  --ice: #f3f8fd; --ice-edge: #c9d6e4; --rink-red: #d64545; --rink-blue: #2f6fd0; --crease: #cfe4fb;
  --tok-C: #1f6fd6; --tok-W: #179256; --tok-D: #cf7d12; --tok-G: #7a3fc4; --label-bg: rgba(255,255,255,.9);
}
@media (prefers-color-scheme: dark) {
  :root { --ice: #15263a; --ice-edge: #2c4560; --rink-red: #c25454; --rink-blue: #4b86e0; --crease: #1f3d5e; --label-bg: rgba(10,18,29,.82); }
}
.seg.mini { margin: 0; width: auto; display: inline-grid; grid-template-columns: auto auto; }
.seg.mini button { padding: 5px 12px; font-size: .8rem; }
.rinks { display: grid; gap: 12px; }
@media (min-width: 700px) { .rinks { grid-template-columns: 1fr 1fr; } }
.rink-card { padding: 10px; }
.rink-card + .rink-card { margin-top: 0; }
.rink-h { padding: 0 4px 8px; }
.rink { position: relative; width: 100%; aspect-ratio: 100 / 110; max-height: 560px; margin: 0 auto; }
.rink-bg { position: absolute; inset: 0; width: 100%; height: 100%; }
.rink-bg .ice { fill: var(--ice); }
.rink-bg .boards { fill: none; stroke: var(--ice-edge); stroke-width: 1.4; }
.rink-bg .red-line { stroke: var(--rink-red); stroke-width: 1.3; opacity: .85; }
.rink-bg .red-thin { fill: none; stroke: var(--rink-red); stroke-width: .5; opacity: .75; }
.rink-bg .blue-line { stroke: var(--rink-blue); stroke-width: 1.6; opacity: .85; }
.rink-bg .dot { fill: var(--rink-red); opacity: .8; }
.rink-bg .crease { fill: var(--crease); stroke: var(--rink-red); stroke-width: .4; }
.rink-bg .net { fill: none; stroke: var(--rink-red); stroke-width: .6; }
.tok {
  position: absolute; transform: translate(-50%, 0); display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: 0; padding: 0; cursor: pointer; width: 31%; max-width: 132px; color: var(--text); font: inherit;
  -webkit-tap-highlight-color: transparent;
}
.tok .disc {
  position: relative; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 1.05rem; color: #fff; background: var(--tok-C);
  box-shadow: 0 2px 6px rgba(0,0,0,.25), inset 0 -3px 0 rgba(0,0,0,.18); border: 2px solid rgba(255,255,255,.9);
  transition: transform .12s;
}
.tok:active .disc { transform: scale(.94); }
.tok.g-W .disc { background: var(--tok-W); } .tok.g-D .disc { background: var(--tok-D); } .tok.g-G .disc { background: var(--tok-G); }
.tok.is-cap .disc { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold), 0 2px 8px rgba(0,0,0,.3); }
.tok .capb { position: absolute; top: -6px; right: -8px; width: 20px; height: 20px; border-radius: 50%; background: var(--gold); color: #fff; font-style: normal; font-size: .7rem; display: grid; place-items: center; font-weight: 800; }
.tok .lockb { position: absolute; bottom: -4px; right: -8px; font-style: normal; font-size: .72rem; }
.tok .nm, .tok .pt, .tok .gm { background: var(--label-bg); border-radius: 6px; padding: 0 5px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.35; }
.tok .nm { font-weight: 700; font-size: .8rem; }
.tok .pt { font-size: .68rem; font-weight: 600; color: var(--muted); }
.tok .gm { font-size: .64rem; color: var(--muted); }
.tok .gm.live { color: var(--good); font-weight: 700; }
.tok.nogame .disc { opacity: .5; filter: grayscale(.4); }
.tok.nogame .gm { opacity: .8; }
.tok.empty { cursor: default; }
.tok.empty .disc { background: var(--surface-2); color: var(--muted); border-style: dashed; box-shadow: none; }
@media (max-width: 380px) { .tok .disc { width: 42px; height: 42px; font-size: .95rem; } .tok .nm { font-size: .74rem; } }
