:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1d1c1a;
  --muted: #6b6862;
  --border: #e3e0da;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --ok: #1f7a3d;
  --warn: #9a6400;
  --bad: #a3312b;
  --badge: #eeece7;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #201f1d;
    --text: #ecebe8;
    --muted: #a19d96;
    --border: #34322f;
    --accent: #6fb39d;
    --accent-text: #0f1a16;
    --ok: #6cc98a;
    --warn: #e0b04e;
    --bad: #ef8a83;
    --badge: #2c2b28;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

a { color: inherit; }
h2 { font-size: 18px; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.wrap { max-width: 920px; margin: 0 auto; padding: 0 16px; }

/* Yläpalkki */
.top {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.top-inner { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; }
.brand { font-size: 18px; margin: 0; }
.nav { display: flex; gap: 4px; }
.nav button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; font: inherit; color: var(--muted); cursor: pointer; }
.nav button.active { background: var(--badge); color: var(--text); font-weight: 600; }
.account { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* Lomake-elementit */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; min-height: 60px; resize: vertical; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { color: var(--bad); }
.btn:disabled { opacity: .5; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: 13px; }

.row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.grow { flex: 1 1 200px; }

/* Kirjautuminen */
.auth { max-width: 380px; margin: 48px auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.auth h2 { margin-top: 0; }
.auth form { display: grid; gap: 12px; }
.auth .switch { margin-top: 16px; text-align: center; }
.error { color: var(--bad); font-size: 14px; }

/* Työkalurivi ja BGG-haku */
.toolbar { display: flex; gap: 8px; margin: 20px 0 12px; flex-wrap: wrap; }
.search { position: relative; flex: 1 1 260px; }
.search input { width: 100%; }
.results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 5;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgb(0 0 0 / .12);
  max-height: 420px;
  overflow-y: auto;
}
.result { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: 0; }
.result .name { flex: 1; min-width: 0; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }

/* Suodattimet ja yhteenveto */
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.filters input[type=search] { margin-left: auto; flex: 0 1 200px; padding: 5px 10px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 20px; }

/* Pelilista */
.games { display: grid; gap: 8px; }
.game { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.game-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px; cursor: pointer; }
.thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--badge); flex: none; }
.game-title { flex: 1; min-width: 0; }
.game-title .name { font-weight: 600; overflow-wrap: anywhere; }
.game-body { border-top: 1px solid var(--border); padding: 12px; display: grid; gap: 12px; }

.badge { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--badge); white-space: nowrap; }
.badge.done { color: var(--ok); }
.badge.partial { color: var(--warn); }
.badge.none { color: var(--bad); }


/* Korttipakat */
.cards { display: grid; gap: 8px; }
.card { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.card .info { flex: 1 1 220px; }
.card-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; align-items: end; padding: 10px; border: 1px dashed var(--border); border-radius: 8px; }
.card-form .actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.size-custom { display: flex; gap: 4px; align-items: center; }
.size-custom input { width: 70px; }

/* Sleevit */
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { font-size: 13px; color: var(--muted); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.missing { color: var(--bad); font-weight: 600; }
.enough { color: var(--ok); }
.stepper { display: inline-flex; align-items: center; gap: 4px; }
.stepper input { width: 72px; text-align: right; }
.table-wrap { overflow-x: auto; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 8px;
  max-width: calc(100% - 32px);
  z-index: 20;
}
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 560px) {
  .account { margin-left: 0; width: 100%; justify-content: space-between; padding-bottom: 8px; }
  .filters input[type=search] { margin-left: 0; flex-basis: 100%; }
  .hide-mobile { display: none; }
}
.grid-size { display: grid; gap: 4px; }
.game-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0; }
label.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text); padding-bottom: 8px; }
.bgg-line { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.confirm { background: var(--badge); padding: 8px 10px; border-radius: 8px; }
.link:disabled { opacity: .4; cursor: default; }

/* Kaverit */
.friend-game { display: flex; align-items: center; gap: 12px; padding: 10px 12px; }
.friend-game a, .post a, .side-row a { text-decoration: none; }
.friend-game a:hover, .post a:hover, .side-row a:hover { text-decoration: underline; }
.owners { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.feed { display: grid; gap: 6px; }
.filters select { padding: 5px 10px; }
.filters label.check { padding-bottom: 0; font-size: 13px; }
.friend-list .card { background: var(--surface); }
.search-bar { margin-top: 20px; }
.big-search { width: 100%; font-size: 16px; padding: 12px 14px; border-radius: var(--radius); }
.tabs { margin-top: 12px; }
.search-result .owners { margin-top: 6px; }
.owners .label { min-width: 62px; }
.tabs .chip { font-size: 14px; padding: 6px 14px; }

/* Pelisyöte */
.social { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; align-items: start; }
.feed { display: grid; gap: 10px; }
.post { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 10px; }
.post.together { border-left: 3px solid var(--accent); }
.post-head { display: flex; gap: 12px; align-items: flex-start; }
.post-title { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.post-title .small { margin-top: 2px; text-transform: none; }
.post-thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--badge); flex: none; }
.post-players { display: flex; gap: 4px; flex-wrap: wrap; }
.badge.win { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--text); font-weight: 600; }
.post-comment { margin: 0; padding: 8px 12px; background: var(--badge); border-radius: 8px; font-size: 14px; }

.avatars { display: flex; flex: none; }
.avatars .avatar + .avatar { margin-left: -10px; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  flex: none;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  background: hsl(var(--hue, 200) 45% 42%);
  border: 2px solid var(--surface);
}
.avatar.me { background: var(--accent); color: var(--accent-text); }

.feed-side { display: grid; gap: 12px; position: sticky; top: 72px; }
.side-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.side-box h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.side-box p { margin: 0; }
.side-row { display: flex; gap: 10px; align-items: center; padding: 4px 0; font-size: 14px; }
.side-row > .muted { white-space: nowrap; }
.side-row .avatar { width: 28px; height: 28px; font-size: 11px; }
.thumb.tiny { width: 28px; height: 28px; border-radius: 4px; }

@media (max-width: 760px) {
  .social { grid-template-columns: minmax(0, 1fr); }
  .feed-side { position: static; }
  .post-thumb { width: 48px; height: 48px; }
}
.mapping select { width: 100%; min-width: 160px; }
.mapping td { vertical-align: middle; }
.show-mobile { display: none; }
@media (max-width: 560px) {
  .show-mobile { display: block; }
  .mapping th, .mapping td { padding: 6px 8px; }
  .mapping select { min-width: 0; }
}
