:root {
  --bg: #e9edf1;
  --surface: #ffffff;
  --ink: #18212e;
  --muted: #5a6676;
  --line: #cfd6de;
  --focus: #f2b705;
  --shelf: #8a6a4a;
  --c-strategi: #2e5e8c;
  --c-ttr: #b23a2e;
  --c-samarbete: #3f8f5a;
  --c-duell: #7a4fa0;
  --c-familj: #d98e04;
  --c-party: #d9487c;
  --c-kortspel: #5b6470;
  --c-annat: #8d97a3;
  color-scheme: light;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121820; --surface: #1b2430; --ink: #e8edf3; --muted: #9aa6b4; --line: #2e3a49;
    --shelf: #6b5038; --c-strategi: #5b8fc4; --c-ttr: #d9604f; --c-samarbete: #5fb47a; --c-duell: #a07bc8;
    --c-familj: #e8a92e; --c-party: #e9719c; --c-kortspel: #8c97a6; --c-annat: #6d7784;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121820; --surface: #1b2430; --ink: #e8edf3; --muted: #9aa6b4; --line: #2e3a49;
  --shelf: #6b5038; --c-strategi: #5b8fc4; --c-ttr: #d9604f; --c-samarbete: #5fb47a; --c-duell: #a07bc8;
  --c-familj: #e8a92e; --c-party: #e9719c; --c-kortspel: #8c97a6; --c-annat: #6d7784;
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: inherit; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
}
h1, h2, h3, .people button, .name { font-family: "Bricolage Grotesque", "Atkinson Hyperlegible", system-ui, sans-serif; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
button, input, select { font: inherit; color: inherit; }

.top, main, .foot { max-width: 68rem; margin: 0 auto; padding-inline: 1.25rem; }
.top { padding-top: 2rem; display: flex; flex-wrap: wrap; align-items: end; gap: 1rem 2rem; }
h1 { font-size: clamp(2.4rem, 7vw, 4.2rem); font-weight: 800; letter-spacing: -0.035em; line-height: .95; margin: 0; }
.people { display: flex; flex-wrap: wrap; gap: .5rem; padding-bottom: .35rem; }
.people button {
  border: 2px solid var(--ink); background: transparent; border-radius: 999px;
  padding: .3rem .95rem; font-weight: 700; cursor: pointer;
}
.people button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* Hyllorna: det enda dekorativa greppet */
.shelves { margin: 2rem 0 1.5rem; display: grid; gap: 1.6rem; }
.shelf h2 { font-size: 1rem; font-weight: 700; margin: 0 0 .35rem; display: flex; gap: .6rem; align-items: baseline; }
.shelf h2 small { font-family: "Atkinson Hyperlegible", sans-serif; font-weight: 400; color: var(--muted); font-size: .85rem; }
.spines {
  display: flex; align-items: flex-end; gap: 2px; min-height: 100px;
  padding: 0 .4rem; border-bottom: 9px solid var(--shelf); border-radius: 0 0 3px 3px;
  overflow-x: auto; scrollbar-width: thin;
}
.spine {
  flex: 0 0 auto; width: 15px; border: 0; padding: 0; cursor: pointer;
  background: var(--cat); border-radius: 2px 2px 0 0;
  box-shadow: inset -3px 0 0 rgb(0 0 0 / .18), inset 2px 0 0 rgb(255 255 255 / .15);
  transition: opacity .2s, transform .15s;
}
.spine.exp { width: 8px; }
.spine.dim { opacity: .18; }
.spine:hover, .spine:focus-visible { transform: translateY(-5px); }

.controls { display: grid; gap: .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; }
.search input { width: 100%; padding: .7rem .9rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.row { display: flex; flex-wrap: wrap; gap: .6rem; }
.stepper { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 2.6rem; height: 2.6rem; border: 0; background: var(--bg); cursor: pointer; font-size: 1.2rem; }
.stepper output { min-width: 7.5rem; text-align: center; padding-inline: .5rem; }
.sel select { height: 2.75rem; padding: 0 .7rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
.cats { display: flex; flex-wrap: wrap; gap: .4rem; }
.cats button {
  display: inline-flex; align-items: center; gap: .45rem; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: .3rem .65rem; font-size: .9rem;
}
.cats button::before { content: ""; width: .7rem; height: 1rem; border-radius: 2px; background: var(--cat); }
.cats button[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); font-weight: 700; }
.cats .n { color: var(--muted); font-size: .8rem; }

.count { color: var(--muted); margin: 1.2rem 0 .4rem; }
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.item {
  width: 100%; text-align: left; border: 0; background: transparent; cursor: pointer;
  display: grid; grid-template-columns: 6px 1fr repeat(3, 5.5rem) 9rem; gap: 0 1rem; align-items: center;
  padding: .75rem 1rem .75rem 0;
}
.item:hover { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.item .bar { align-self: stretch; background: var(--cat); border-radius: 0 3px 3px 0; }
.name { font-weight: 700; font-size: 1.05rem; line-height: 1.25; }
.tag { display: inline-block; margin-left: .4rem; font: 400 .75rem "Atkinson Hyperlegible", sans-serif; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 .3rem; vertical-align: 2px; }
.cell { font-size: .92rem; }
.cell small { display: block; color: var(--muted); font-size: .75rem; }
.rating { font-weight: 700; font-variant-numeric: tabular-nums; }
.rating.approx { font-style: italic; font-weight: 400; color: var(--muted); }
.owners { font-size: .85rem; color: var(--muted); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.empty button { margin-top: .6rem; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: .4rem .8rem; cursor: pointer; }

@media (max-width: 720px) {
  .item { grid-template-columns: 6px 1fr auto; row-gap: .2rem; }
  .item .bar { grid-row: 1 / 4; }
  .item .cell.ra { grid-row: 1; grid-column: 3; text-align: right; }
  .item .cell.pl { grid-row: 2; grid-column: 2; }
  .item .cell.ti { grid-row: 2; grid-column: 3; text-align: right; }
  .item .owners { grid-row: 3; grid-column: 2 / 4; }
  .item .cell small { display: inline; margin-left: .25rem; }
  .item .cell.we { display: none; }
  .sel { flex: 1 1 10rem; }
  .sel select { width: 100%; }
}

.extras { margin: 2rem 0; display: grid; gap: .8rem; }
.extras details { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: .8rem 1rem; }
.extras summary { cursor: pointer; font-weight: 700; }
.extras table { width: 100%; border-collapse: collapse; margin-top: .6rem; font-size: .92rem; }
.extras td, .extras th { text-align: left; padding: .35rem .5rem .35rem 0; border-top: 1px solid var(--line); vertical-align: top; }
.extras th { color: var(--muted); font-weight: 400; }
.tw { overflow-x: auto; }

.foot { color: var(--muted); font-size: .85rem; padding-bottom: 2rem; }

dialog {
  width: min(34rem, calc(100vw - 2rem)); border: 0; border-radius: 16px; padding: 1.5rem;
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / .35);
}
dialog::backdrop { background: rgb(10 15 25 / .55); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.close { position: absolute; top: .6rem; right: .8rem; border: 0; background: none; font-size: 1.8rem; line-height: 1; cursor: pointer; color: var(--muted); }
dialog h2 { margin: 0 2rem .2rem 0; font-size: 1.6rem; line-height: 1.1; letter-spacing: -0.02em; }
.dcat { display: inline-flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .9rem; }
.dcat::before { content: ""; width: .7rem; height: 1rem; border-radius: 2px; background: var(--cat); }
dl.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(5.8rem, 1fr)); gap: .8rem; margin: 1.1rem 0; }
dl.facts div { background: var(--bg); border-radius: 10px; padding: .55rem .7rem; }
dl.facts dt { font-size: .78rem; color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 700; }
.mech { display: flex; flex-wrap: wrap; gap: .35rem; padding: 0; list-style: none; }
.mech li { border: 1px solid var(--line); border-radius: 6px; padding: .1rem .5rem; font-size: .85rem; }
dialog p { margin: .7rem 0; }
dialog a { color: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Länk och sidan Lägg till ---------- */
.addlink { margin-left: auto; align-self: center; color: var(--ink); font-weight: 700; text-underline-offset: 3px; }
.add main { max-width: 46rem; }
.add h1 { font-size: clamp(2rem, 6vw, 3.2rem); }
.steps { margin: 1.8rem 0; padding-left: 1.4rem; display: grid; gap: .4rem; font-size: 1.05rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 1.1rem 1.2rem; margin-bottom: 1rem; display: grid; gap: .7rem; }
.panel h2 { margin: 0; font-size: 1.25rem; }
.panel-head { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: space-between; }
.hint { margin: 0; color: var(--muted); font-size: .92rem; }
.prompt, .code {
  margin: 0; max-height: 22rem; overflow: auto; white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border-radius: 10px; padding: .9rem 1rem; font: .85rem/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.code { white-space: pre; max-height: none; }
.btn { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: .55rem 1rem; cursor: pointer; font-weight: 700; }
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: progress; }
.keyrow { display: flex; flex-wrap: wrap; gap: .6rem; }
.grow { flex: 1 1 14rem; }
.keyrow input, textarea { width: 100%; padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
textarea { font: .85rem/1.45 ui-monospace, "SF Mono", Menlo, Consolas, monospace; resize: vertical; }
.check { display: flex; gap: .5rem; align-items: center; font-size: .92rem; }
.status { margin: 0; min-height: 1.5em; }
.status.good, .result.good { color: var(--c-samarbete); }
.status.bad, .result.bad { color: var(--c-ttr); }
.result p { margin: .3rem 0; }
.result ul { margin: .3rem 0; padding-left: 1.2rem; color: var(--ink); font-size: .9rem; }
.drop { display: grid; place-items: center; border: 2px dashed var(--line); border-radius: 12px; padding: 1.2rem; cursor: pointer; color: var(--muted); text-align: center; }
.drop.over { border-color: var(--ink); color: var(--ink); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
