:root {
  --bg: #0d0f13;
  --bg-2: #14171d;
  --bg-3: #1c2029;
  --line: #262b36;
  --text: #e8eaf0;
  --tyst: #8b93a5;
  --accent: #f0603f;
  --accent-2: #ffb27a;
  --ok: #4ec9a0;
  --radie: 12px;
  --max: 1280px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
h1 { font-size: 1.9rem; letter-spacing: -.02em; margin: 0 0 .3rem; }
h2 { font-size: 1.15rem; letter-spacing: -.01em; margin: 2rem 0 .9rem; display: flex; align-items: baseline; gap: .75rem; }
.tyst { color: var(--tyst); }
.mer { font-size: .85rem; font-weight: 400; color: var(--accent-2); margin-left: auto; }

/* ---------- toppmeny ---------- */
.top {
  display: flex; align-items: center; gap: 1.25rem;
  padding: .75rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: rgba(13, 15, 19, .9);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; letter-spacing: -.02em; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 9px; display: block; flex: 0 0 auto;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .12) inset, 0 2px 8px rgba(0, 0, 0, .35);
}
.top nav { display: flex; gap: .25rem; }
.top nav a { padding: .4rem .7rem; border-radius: 8px; color: var(--tyst); font-size: .93rem; }
.top nav a:hover { color: var(--text); background: var(--bg-3); }
.top nav a.on { color: var(--text); background: var(--bg-3); }
.sok { margin-left: auto; }
.sok input {
  width: min(240px, 30vw); padding: .45rem .7rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font-size: .9rem;
}
.sok input:focus, .filter input:focus, .filter select:focus, .staplad input:focus, .taggedit input:focus {
  outline: 2px solid rgba(240, 96, 63, .5); outline-offset: 1px;
}
.who { display: flex; align-items: center; gap: .5rem; font-size: .88rem; color: var(--tyst); }
.lank { background: none; border: 0; color: var(--accent-2); font: inherit; cursor: pointer; padding: 0; }
.lank:hover { text-decoration: underline; }

main { width: 100%; max-width: var(--max); margin: 0 auto; padding: clamp(1.25rem, 3vw, 2.5rem) clamp(1rem, 4vw, 2.5rem) 4rem; flex: 1; }
body.wide main { max-width: none; padding: 0; }

.fot { border-top: 1px solid var(--line); color: var(--tyst); font-size: .8rem; padding: 1rem clamp(1rem, 4vw, 2.5rem); }
body.wide .fot { display: none; }

.intro { margin-bottom: 1rem; }

/* ---------- rutnät och kort ---------- */
.grid {
  display: grid; gap: 1.1rem;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.kort { display: flex; flex-direction: column; gap: .5rem; }
.kort .omslag {
  aspect-ratio: 2 / 3; border-radius: var(--radie); overflow: hidden;
  background: var(--bg-3); border: 1px solid var(--line);
  transition: transform .15s ease, border-color .15s ease;
}
.kort:hover .omslag { transform: translateY(-3px); border-color: #3a4152; }
.kort .omslag img { width: 100%; height: 100%; object-fit: cover; }
.kort-text { display: flex; flex-direction: column; gap: .15rem; font-size: .88rem; }
.kort-text strong { font-weight: 600; line-height: 1.3; }
.kort-text span { color: var(--tyst); font-size: .78rem; }

.rad-scroll {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(160px, 180px);
  gap: 1rem; overflow-x: auto; padding-bottom: .5rem; scroll-snap-type: x proximity;
}
.rad-scroll .kort { scroll-snap-align: start; }
.fortsatt .rad { display: flex; align-items: center; gap: .5rem; }
.bar { flex: 1; height: 4px; border-radius: 3px; background: var(--bg-3); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bar.stor { height: 8px; border-radius: 6px; background: var(--bg-3); }
.framsteg { max-width: 560px; margin: .3rem 0 .9rem; display: flex; flex-direction: column; gap: .45rem; }
.framsteg p { margin: 0; font-size: .85rem; }
.kolista { list-style: none; margin: .4rem 0 .8rem; padding: 0; max-width: 640px; }
.kolista li { display: flex; align-items: center; gap: .6rem; padding: .35rem 0; border-bottom: 1px solid var(--line); font-size: .88rem; }
.kolista li span:first-child { flex: 1; }

/* ---------- listor och filter ---------- */
.lista-topp { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-bottom: 1.25rem; }
.lista-topp h1 { margin: 0; }
.filter { display: flex; flex-wrap: wrap; gap: .5rem; }
.filter input, .filter select, .staplad input, .taggedit input {
  padding: .45rem .65rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--text); font-size: .88rem;
}
.filter button, .taggedit button, .staplad button {
  padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg-3); color: var(--text); font: inherit; font-size: .88rem; cursor: pointer;
}
.filter button:hover, .taggedit button:hover { border-color: var(--accent); }

.tabell { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabell th { text-align: left; color: var(--tyst); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.tabell th, .tabell td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); }

/* ---------- seriesida ---------- */
.serie-topp { display: flex; gap: clamp(1rem, 3vw, 2rem); align-items: flex-start; margin-bottom: 1rem; }
.omslag.stor { width: clamp(140px, 22vw, 240px); flex: 0 0 auto; border-radius: var(--radie); overflow: hidden; border: 1px solid var(--line); background: var(--bg-3); }
.omslag.stor img { width: 100%; aspect-ratio: 2 / 3; object-fit: cover; }
.serie-meta { min-width: 0; }
.serie-meta h1 { margin-bottom: .25rem; }
.taggar { display: flex; flex-wrap: wrap; gap: .4rem; margin: .8rem 0; }
.serie-meta .smal { font-size: .82rem; }
.beskrivning {
  max-width: 68ch; margin: .4rem 0 0; color: #b9c0cd;
  font-size: .92rem; line-height: 1.6; white-space: pre-line;
}
.beskrivning p { margin: 0 0 .5rem; }
.beskrivning details summary { cursor: pointer; color: var(--accent-2); font-size: .85rem; }
.genrer .tagg { background: var(--bg-3); color: var(--text); border-color: var(--line); }
.tagg {
  font-size: .78rem; padding: .18rem .55rem; border-radius: 999px;
  background: rgba(240, 96, 63, .12); color: var(--accent-2); border: 1px solid rgba(240, 96, 63, .25);
}
.knappar { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: 1rem; }
.knappar form { margin: 0; display: flex; }
.knapp {
  display: inline-block; padding: .55rem 1.1rem; border-radius: 10px; font-size: .92rem; font-weight: 600;
  background: var(--accent); color: #fff; border: 1px solid transparent; cursor: pointer;
}
.knapp:hover { filter: brightness(1.08); }
.knapp.svag { background: transparent; border-color: var(--line); color: var(--text); font-weight: 500; }
.knapp:disabled { opacity: .5; cursor: default; }

.taggedit { margin-top: .9rem; font-size: .85rem; color: var(--tyst); }
.taggedit summary { cursor: pointer; }
.taggedit form { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }
.taggedit input { flex: 1; min-width: 200px; }

.kapitel { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.kap {
  display: flex; align-items: center; gap: .8rem; padding: .65rem .4rem;
  border-bottom: 1px solid var(--line); font-size: .92rem;
}
.kap:hover { background: var(--bg-2); }
.kapitel li.rad { display: flex; align-items: center; }
.kapitel li.rad > .kap { flex: 1; }
form.radera { flex: 0 0 auto; padding-right: .3rem; }
form.radera button {
  background: none; border: 0; color: var(--tyst); font-size: 1.05rem;
  line-height: 1; cursor: pointer; padding: .35rem .45rem; border-radius: 6px;
}
form.radera button:hover { color: #ff7b7b; background: rgba(240, 96, 63, .12); }
.knapp.fara { border-color: rgba(240, 96, 63, .5); color: #ff9d85; }
.knapp.fara:hover { background: rgba(240, 96, 63, .12); }
.kap .nr { color: var(--tyst); width: 3.2rem; flex: 0 0 auto; font-variant-numeric: tabular-nums; }
.kap .namn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kap .sidor { font-size: .8rem; flex: 0 0 auto; }
.pill { font-size: .72rem; padding: .12rem .5rem; border-radius: 999px; flex: 0 0 auto; }
.pill.klar { background: rgba(78, 201, 160, .14); color: var(--ok); }
.pill.pagaende { background: var(--bg-3); color: var(--tyst); }
.pill.saknas { background: rgba(240, 96, 63, .1); color: #ff9d85; border: 1px dashed rgba(240, 96, 63, .45); }
.pill.nasta { background: rgba(78, 201, 160, .14); color: var(--ok); }
.pill.sasong { background: rgba(255, 143, 98, .14); color: #ffb08f; font-size: .68rem; margin-right: .25rem; }
.pill.arkiv { background: rgba(255, 255, 255, .08); color: #c9cfdb; border: 1px solid var(--line); font-size: .7rem; vertical-align: middle; }

.kap.lucka {
  border-bottom: 1px dashed var(--line); color: var(--tyst);
  font-style: italic; background: transparent; cursor: default;
}
.kap.lucka .namn { color: var(--tyst); }
.saknas-antal { color: #ff9d85; }
.saknade-info { font-size: .82rem; margin: 0 0 .6rem; }

/* ---------- inloggning / ruta ---------- */
.ruta { max-width: 420px; margin: clamp(2rem, 8vh, 5rem) auto; background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; }
.ruta.ny { margin-top: 0; max-width: none; }
.ruta h1 { font-size: 1.5rem; }
.staplad { display: flex; flex-direction: column; gap: .9rem; margin-top: 1.25rem; }
.staplad label { display: flex; flex-direction: column; gap: .35rem; font-size: .85rem; color: var(--tyst); }
.staplad input { padding: .6rem .7rem; }
.losen { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.1rem; background: var(--bg-3); padding: .6rem .8rem; border-radius: 8px; border: 1px solid var(--line); }

.flash { padding: .6rem .9rem; border-radius: 10px; font-size: .88rem; margin: 0 0 1rem; }
.flash.ok { background: rgba(78, 201, 160, .12); color: var(--ok); }
.flash.fel { background: rgba(240, 96, 63, .14); color: #ff9d85; }
.tom { color: var(--tyst); }
pre { white-space: pre-wrap; font-size: .78rem; color: var(--tyst); }

/* ---------- läsaren (webtoon: vertikal stapel) ---------- */
body.wide { background: #0a0a0c; }
.lasare { background: #0a0a0c; min-height: 100vh; }

.lasare-progress {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: #171a21; z-index: 30;
}
.lasare-progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .12s linear; }

.lasare-topp {
  position: fixed; top: 3px; left: 0; right: 0; z-index: 25;
  display: flex; align-items: center; gap: 1rem; padding: .45rem .9rem;
  background: rgba(10, 11, 14, .93); backdrop-filter: blur(10px);
  border-bottom: 1px solid #1a1d24; font-size: .85rem;
  transition: transform .22s ease;
}
.lasare-topp.dold { transform: translateY(calc(-100% - 4px)); }
.kapnamn { color: var(--tyst); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidraknare { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--tyst); }
.sidraknare b { color: var(--text); }
.lasare-knappar { display: flex; align-items: center; gap: .4rem; }
.lasare-knappar button {
  padding: .3rem .6rem; border-radius: 7px; border: 1px solid #262b36;
  background: #14171d; color: var(--text); font: inherit; font-size: .78rem; cursor: pointer;
}
.lasare-knappar button:hover { border-color: var(--accent); }

.webtoon {
  max-width: 860px; margin: 0 auto; padding-top: 46px;
  display: flex; flex-direction: column; background: #0a0a0c;
}
.webtoon img {
  display: block; width: 100%; height: auto; margin: 0;
  background: #0a0a0c; user-select: none; -webkit-user-drag: none;
  /* Platshållare medan lazy-bilder inte laddats, så att slutkortet hamnar
     där det ska och inte direkt under första sidan. */
  min-height: 320px;
}

.lasare-slut { text-align: center; padding: 2.5rem 1rem 4rem; color: var(--tyst); }
.lasare-slut .knappar { justify-content: center; }

.till-toppen {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 26;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(20, 23, 29, .92);
  color: var(--text); font-size: 1.05rem; cursor: pointer;
}
.till-toppen:hover { border-color: var(--accent); }

@media (max-width: 640px) {
  .top { gap: .6rem; padding: .6rem .8rem; flex-wrap: wrap; }
  .sok { order: 5; width: 100%; margin: 0; }
  .sok input { width: 100%; }
  h1 { font-size: 1.5rem; }
  .serie-topp { flex-direction: column; }
  .omslag.stor { width: 140px; }
  .lasare-topp { gap: .5rem; padding: .4rem .6rem; }
  .kapnamn { display: none; }
  .lasare-knappar { margin-left: auto; }
  .webtoon { padding-top: 42px; }
}

/* Favorit- och nyhetsmärken på omslagen */
.omslag { position: relative; }
.badge { position: absolute; top: .35rem; font-size: .68rem; line-height: 1; padding: .22rem .4rem; border-radius: 999px; background: var(--bg-3); color: var(--tyst); }
.badge.fav { left: .35rem; color: var(--ok); }
.badge.nya { right: .35rem; background: var(--accent); color: #fff; }
.knapp.fav-pa { color: var(--ok); border-color: var(--ok); }
.fav-form { margin: 0 0 .35rem; }
.epost-form { display: flex; gap: .4rem; align-items: center; }
.epost-form input { padding: .25rem .45rem; font-size: .82rem; }

/* Läsaren på mobil: sajtens toppbar fälls undan när man scrollar neråt */
@media (max-width: 800px) {
  header.top { transition: transform .22s ease; }
  header.top.dold { transform: translateY(-100%); }
}
