:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #f1ece2;
  --text: #1d2433;
  --muted: #6b7180;
  --line: #e2dccf;
  --navy: #1c2b4a;
  --navy-2: #2c3f66;
  --gold: #b8913f;
  --gold-soft: #f3e7c9;
  --green: #2f7a54;
  --red: #b23b3b;
  --ch: #b8913f;
  --res: #8a93a6;
  --top: #4f6a94;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(20 25 40 / 6%), 0 4px 16px rgb(20 25 40 / 5%);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 Inter, system-ui, sans-serif;
}
a { color: var(--navy-2); }
h1, h2, h3 { font-family: 'Cormorant Garamond', Georgia, serif; color: var(--navy); line-height: 1.15; margin: 0 0 .5em; }
h1 { font-size: 2.2rem; }
h2 { font-size: 1.6rem; margin-top: 1.4em; }
h3 { font-size: 1.25rem; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* yläpalkki */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; gap: 16px; min-height: 60px; }
.brand { color: #fff; text-decoration: none; font-family: 'Cormorant Garamond', serif; font-size: 1.4rem; font-weight: 700; white-space: nowrap; }
.brand-mark { display: inline-block; background: var(--gold); color: var(--navy); font: 700 .75rem Inter, sans-serif; padding: 3px 6px; border-radius: 4px; vertical-align: middle; margin-right: 6px; }
#nav { display: flex; gap: 4px; margin-left: auto; align-items: center; flex-wrap: wrap; }
#nav a, #nav button.link { color: #dfe5f2; text-decoration: none; padding: 6px 10px; border-radius: 6px; font-size: .92rem; background: none; border: 0; cursor: pointer; font-family: inherit; }
#nav a:hover, #nav a.active, #nav button.link:hover { background: var(--navy-2); color: #fff; }
.menu-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
@media (max-width: 760px) {
  .menu-toggle { display: block; }
  .brand { font-size: 1.15rem; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  #nav { display: none; position: absolute; top: 60px; left: 0; right: 0; background: var(--navy); flex-direction: column; align-items: stretch; padding: 8px 16px 16px; }
  #nav.open { display: flex; }
}

main.wrap { padding-top: 32px; padding-bottom: 40px; min-height: 70vh; }
@media (max-width: 760px) { main.wrap { padding-top: 20px; } .hero { padding: 24px 20px; } }
.footer { color: var(--muted); font-size: .85rem; padding-bottom: 32px; }

/* kortit ja ruudukot */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: 16px; }

.hero { background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; border-radius: var(--radius); padding: 32px; margin-bottom: 24px; }
.hero h1 { color: #fff; }
.hero p { color: #d7deec; max-width: 640px; }
.stat { display: inline-block; margin-right: 28px; }
.stat b { display: block; font-size: 1.5rem; color: var(--gold-soft); font-family: 'Cormorant Garamond', serif; }

/* napit ja lomakkeet */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--navy); background: var(--navy); color: #fff; padding: 8px 16px; border-radius: 8px; font: 500 .92rem Inter, sans-serif; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--navy-2); }
.btn.ghost { background: transparent; color: var(--navy); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.small { padding: 4px 10px; font-size: .82rem; }
.btn:disabled { opacity: .6; cursor: default; }

form .field { margin-bottom: 16px; }
label { display: block; font-weight: 500; margin-bottom: 4px; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; cursor: pointer; font-weight: 400; margin: 0; }
.check:has(input:checked) { border-color: var(--navy); background: #e9edf6; }
.check.disabled { opacity: .5; }
.input-action { display: flex; gap: 8px; align-items: center; }
.input-action input { flex: 1; min-width: 0; }
.input-action .btn { white-space: nowrap; }
.hint { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.error { background: #fbeaea; color: var(--red); border: 1px solid #efc9c9; padding: 10px 12px; border-radius: 8px; margin-bottom: 16px; }
.notice { background: var(--gold-soft); border: 1px solid #e6d3a3; padding: 10px 12px; border-radius: 8px; }
.toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.toggle label { margin: 0; padding: 8px 14px; cursor: pointer; font-weight: 400; background: #fff; }
.toggle input { display: none; }
.toggle label:has(input:checked) { background: var(--navy); color: #fff; }

/* merkit */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; letter-spacing: .02em; background: var(--surface-2); color: var(--navy); white-space: nowrap; }
.badge.on { background: #e1f1e8; color: var(--green); }
.badge.off { background: #eceef2; color: var(--muted); }
.lvl-INTRO { background: #e8eef7; color: #3c5a8a; }
.lvl-GREEN { background: #e1f1e8; color: #2f7a54; }
.lvl-NOVICE { background: #f6ecd8; color: #92692a; }
.lvl-OPEN { background: #f3dfe3; color: #8e2f45; }
.place { display: inline-flex; min-width: 2.2em; justify-content: center; font-weight: 600; }
.ribbon { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: .72rem; font-weight: 700; color: #fff; white-space: nowrap; }
.ribbon.CHAMPION { background: var(--ch); }
.ribbon.RESERVE { background: var(--res); }
.ribbon.TOP_TEN { background: var(--top); }
.reg-id { font-family: ui-monospace, Consolas, monospace; font-size: .88rem; font-weight: 600; letter-spacing: .03em; color: var(--navy-2); margin: 0; }
.title-sym { font-family: 'Segoe UI Symbol', 'Noto Sans Symbols 2', sans-serif; letter-spacing: .1em; color: var(--gold); }

/* taulukot */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
tr.unplaced td { color: var(--muted); }

.points { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.points .card { padding: 14px; }
.points b { font-size: 1.6rem; font-family: 'Cormorant Garamond', serif; color: var(--navy); }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--gold); }

.class-group h2 { border-bottom: 2px solid var(--gold); padding-bottom: 4px; }
.class-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.class-row + .class-row { border-top: 1px solid var(--line); }
.class-row > summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 12px 16px; margin: 0; color: var(--text); font-size: .92rem; list-style: none; }
.class-row > summary::-webkit-details-marker { display: none; }
.class-row > summary::before { content: '▸'; color: var(--gold); transition: transform .15s; }
.class-row[open] > summary::before { transform: rotate(90deg); }
.class-row > summary:hover { background: var(--surface-2); }
.class-row[open] > summary { background: var(--surface-2); }
.class-name { font-weight: 600; color: var(--navy); min-width: 220px; }
.class-podium { display: flex; gap: 14px; flex-wrap: wrap; margin-left: auto; }
.podium { white-space: nowrap; }
.class-row .table-wrap { padding: 4px 16px 0; }
.class-row .show-rest { margin: 8px 16px 14px; }
.class-row td.place { width: 3em; }
.class-row td.pts { width: 3.5em; color: var(--green); font-weight: 600; }
tr.hit td { background: var(--gold-soft); }
@media (max-width: 760px) { .class-podium { margin-left: 0; width: 100%; } .class-name { min-width: 0; } }
details summary { cursor: pointer; color: var(--navy-2); font-size: .85rem; margin-top: 6px; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }

.step { display: flex; flex-direction: column; }
.step p.muted { flex: 1; }
.step a, .step-done { font-size: .9rem; font-weight: 500; margin: 0; }
.step-done { color: var(--green); }

.filler-name { font-style: italic; color: var(--muted); }
tr.filler td { color: var(--muted); font-style: italic; }
.badge.filler-tag { background: #eceef2; color: var(--muted); font-style: normal; font-weight: 500; }

.discipline { display: flex; flex-direction: column; }
.discipline h3 { margin: 0 0 6px; }
.discipline > p { flex: 1; }
.sources { font-size: .8rem; border-top: 1px solid var(--line); padding-top: 8px; }
.sources ul { margin: 4px 0 0; padding-left: 18px; }
.sources li + li { margin-top: 2px; }
.discipline > p.note { flex: 0; font-style: italic; color: var(--muted); }

/* keskitetty ruudukko: vajaa viimeinen rivi asettuu keskelle */
.grid.centered { display: flex; flex-wrap: wrap; justify-content: center; }
.grid.centered > * { flex: 0 1 calc((100% - 32px) / 3); min-width: min(260px, 100%); }

/* kapea + leveä kortti rinnakkain (esim. Kokoluokat ja Luokkaryhmät) */
.grid.split { margin-top: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid.split { grid-template-columns: minmax(230px, 1fr) 3fr; } }

.settings { grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); max-width: 820px; }
.saved { color: var(--green); font-weight: 500; }

/* Hall of Fame */
.hof-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); margin-top: 24px; }
.hof-card h3 { margin-bottom: 8px; }
.hof-card td:nth-child(n+3) { white-space: nowrap; }
.hof-types { grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); }
.hof-type { display: flex; flex-direction: column; gap: 2px; }
.rank { display: inline-flex; width: 1.7em; height: 1.7em; align-items: center; justify-content: center; border-radius: 50%; font-weight: 700; font-size: .8rem; background: var(--surface-2); color: var(--navy); }
.rank-1 { background: var(--ch); color: #fff; }
.rank-2 { background: var(--res); color: #fff; }
.rank-3 { background: #a8754a; color: #fff; }
.hof-summary b { display: block; font-size: 2.2rem; line-height: 1.1; font-variant-numeric: lining-nums; }
[hidden] { display: none !important; }
textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--text); resize: vertical; }
textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.import-table input, .import-table select { min-width: 110px; }
.import-table input[name=height_cm] { width: 90px; min-width: 0; }
.import-table input.missing { border-color: var(--gold); background: var(--gold-soft); }
.warn { color: #92692a; }
.import-table td:first-child { width: 1%; min-width: 140px; }
