:root {
  --wall: #EEEBE5;
  --ink: #1F1E1C;
  --muted: #55524D;
  --faint: #8A857D;
  --hair: #D6D1C9;
  --accent: #8C6A45;
  --serif: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --ease: cubic-bezier(.4, 0, .2, 1);
  --fade-in: 700ms;
  --fade-out: 320ms;
  --interval: 12s;
}

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

html, body { margin: 0; background: var(--wall); color: var(--ink); }

body {
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  transition: opacity 200ms var(--ease);
}
button:hover { opacity: .55; }
button:focus-visible, a:focus-visible { outline: 1px solid var(--ink); outline-offset: 6px; }

.icon {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.i-play path { fill: currentColor; stroke: none; }
.i-pause { display: none; }
body.slideshow .i-play { display: none; }
body.slideshow .i-pause { display: block; }

/* ---------- vägg och rubrik ---------- */

.wall {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  padding: 28px 40px 36px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  transition: opacity 1200ms var(--ease);
}

.title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  color: var(--ink);
  text-decoration: none;
}

.controls { display: flex; align-items: center; gap: 4px; }

.filter {
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--muted);
  min-height: 44px;
  margin-right: 8px;
}
.filter::after { content: '  ×'; color: var(--faint); }

/* ---------- verket ---------- */

.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 0 0;
  touch-action: pan-y;
}

.work {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: fit-content;
  max-width: 100%;
  min-width: min(100%, 760px);
  opacity: 1;
  transition: opacity var(--fade-in) var(--ease), transform 450ms var(--ease);
}
.work.out {
  opacity: 0;
  transition: opacity var(--fade-out) var(--ease), transform 450ms var(--ease);
}
.work.dragging { transition: none; }

/* Etikett och väljare följer bildens bredd i stället för att bestämma den. */
.work > .label, .work > .picker { width: 0; min-width: 100%; }

.work img {
  display: block;
  align-self: center;
  width: auto;
  height: auto;
  max-width: min(100%, 1180px);
  max-height: max(calc(100svh - 300px), 260px);
  background: #E3DFD8;
  user-select: none;
  -webkit-user-drag: none;
}

.label {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px 40px;
  flex-wrap: wrap;
  padding-top: 6px;
  transition: opacity 1200ms var(--ease);
}

.when, .where {
  display: flex;
  flex-direction: column;
  gap: 7px;
  text-align: left;
}

.eyebrow {
  font-size: 10px;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
}

.when-date {
  font-family: var(--serif);
  font-style: italic;
  font-size: 38px;
  line-height: 1;
}

.where-place {
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1;
}

.meta {
  font-size: 12px;
  letter-spacing: .03em;
  color: var(--muted);
}

.where-block {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  margin-left: auto;
}
.where-block .where { text-align: right; align-items: flex-end; }

.minimap {
  position: relative;
  width: 128px;
  height: 64px;
  flex: none;
  overflow: hidden;
  background: var(--wall);
  border: 1px solid var(--hair);
}
.minimap:hover { opacity: .8; }
.minimap .maplibregl-canvas { cursor: pointer; }
.minimap .maplibregl-control-container { display: none; }

.picker {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 18px;
  animation: rise 360ms var(--ease);
}
.picker button {
  font-size: 12px;
  min-width: 44px;
  min-height: 44px;
  color: var(--faint);
}
.picker button.has { color: var(--muted); }
.picker button.current { color: var(--ink); }
.picker button:disabled { cursor: default; opacity: .45; }
.picker .close { margin-left: auto; font-size: 14px; color: var(--ink); }
.mapfilter {
  color: var(--ink);
  border-bottom: 1px solid var(--hair);
  min-height: 32px;
}
.mapfilter::after { content: none; }

.empty {
  font-family: var(--serif);
  font-style: italic;
  font-size: 22px;
  color: var(--muted);
}

/* ---------- bildspel ---------- */

.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 1px;
  width: 0;
  background: var(--muted);
  opacity: 0;
  transition: opacity 600ms var(--ease);
  z-index: 5;
}
body.slideshow .progress { opacity: .45; }
.progress.run { animation: grow var(--interval) linear forwards; }

body.slideshow { --fade-in: 1800ms; --fade-out: 1100ms; }
body.slideshow.idle { cursor: none; }
body.slideshow.idle .top,
body.slideshow.idle .label { opacity: 0; }

/* ---------- karta ---------- */

.mapview {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 28px 40px 36px;
  background: var(--wall);
  animation: appear 420ms var(--ease);
}

.map {
  flex: 1;
  margin-top: 16px;
  min-height: 240px;
  background: var(--wall);
}

.map .maplibregl-canvas:focus-visible { outline: 1px solid var(--ink); }

.maplibregl-popup.fragment-tip .maplibregl-popup-content {
  background: var(--wall);
  color: var(--ink);
  border: 1px solid var(--hair);
  border-radius: 0;
  box-shadow: none;
  padding: 6px 9px;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .04em;
}
.maplibregl-popup.fragment-tip .maplibregl-popup-tip { display: none; }

body.map-open { overflow: hidden; }

.map .maplibregl-ctrl-attrib,
.map .maplibregl-ctrl-attrib.maplibregl-compact {
  background: rgba(238, 235, 229, .85);
  border-radius: 0;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
}
.map .maplibregl-ctrl-attrib a { color: var(--faint); }
.map .maplibregl-ctrl-group {
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}
.map .maplibregl-ctrl-group button { width: 32px; height: 32px; opacity: .6; }
.map .maplibregl-ctrl-group button + button { border-top: 0; }

.map-empty {
  font-family: var(--serif);
  font-style: italic;
  font-size: 20px;
  color: var(--muted);
  padding-top: 20vh;
  text-align: center;
}

/* ---------- text- och inledningskort i flödet ---------- */

.work > .actions { width: 0; min-width: 100%; }

.card {
  width: min(calc(100vw - 80px), 780px);
  min-height: min(520px, calc(100svh - 320px));
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  padding: clamp(28px, 6vw, 72px);
  align-self: center;
}
.work[data-kind="text"] .card { background: #F6F4F0; border: 1px solid var(--hair); }
.work[data-kind="intro"] .card { border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }

.card-title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(34px, 5vw, 60px);
  line-height: 1.04;
  text-wrap: balance;
}
.card-body { max-width: 32em; }
.card-body p {
  margin: 0 0 .6em;
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.45;
  color: var(--muted);
}
.card-body p:last-child { margin-bottom: 0; }
.card-body h2, .card-body h3, .card-body h4 { font-family: var(--serif); font-weight: 400; font-style: italic; font-size: 24px; margin: 0 0 .4em; }
.card-body img { display: none; }
/* Långa inledningar visas avkortade tills man ber om resten. */
.card-body.clamped {
  max-height: 11.5em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(#000 60%, transparent);
  mask-image: linear-gradient(#000 60%, transparent);
}
.expand {
  align-self: flex-start;
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--muted);
  min-height: 32px;
  margin-top: -10px;
}

.more, .back {
  align-self: flex-start;
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  min-height: 44px;
}
.more { border-bottom: 1px solid var(--ink); }
.back { color: var(--muted); }

.when:disabled, .where:disabled { cursor: default; opacity: 1; }

/* ---------- rad under etiketten: serie, räknare, gilla ---------- */

.actions {
  display: flex;
  align-items: center;
  gap: 8px 20px;
  flex-wrap: wrap;
  border-top: 1px solid var(--hair);
  padding-top: 2px;
  margin-top: -6px;
  transition: opacity 1200ms var(--ease);
}
.actions .spacer { flex: 1; }
.series-link {
  font-family: var(--serif);
  font-size: 19px;
  min-height: 44px;
  text-align: left;
}
.counter { font-size: 11px; letter-spacing: .1em; color: var(--muted); }
.like {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 2px 0 10px;
  font-size: 11px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
}
.like svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linejoin: round;
  transition: fill 260ms var(--ease), transform 260ms var(--ease);
}
.like[aria-pressed="true"] { color: var(--ink); }
.like[aria-pressed="true"] svg { fill: var(--ink); stroke: var(--ink); animation: beat 420ms var(--ease); }

body.slideshow.idle .actions { opacity: 0; }

/* ---------- överlägg: register och läsvy ---------- */

body.overlay-open { overflow: hidden; }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 9;
  overflow-y: auto;
  padding: 28px 40px 48px;
  background: var(--wall);
  animation: appear 380ms var(--ease);
}

.reg {
  width: min(100%, 920px);
  margin: 0 auto;
  padding: clamp(24px, 8vh, 96px) 0 24px;
  display: flex;
  flex-direction: column;
}
.reg-eyebrow { padding-bottom: 18px; }
.reg-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 32px;
  width: 100%;
  padding: 22px 0;
  border-top: 1px solid var(--hair);
  text-align: left;
}
button.reg-row:hover { opacity: .6; }
.reg-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(38px, 5vw, 60px);
  line-height: 1;
  min-width: 4.2em;
}
.reg-meta { font-size: 12px; color: var(--muted); }
.reg-list { display: flex; flex-wrap: wrap; gap: 0 22px; flex: 1 1 320px; }
.reg-item {
  font-family: var(--serif);
  font-size: 22px;
  min-height: 44px;
  text-align: left;
}
.reg-texts {
  list-style: none;
  margin: 0;
  padding: 0 0 22px;
  columns: 2 300px;
  column-gap: 48px;
}
.reg-texts li { break-inside: avoid; }
.reg-year {
  font-size: 10px;
  letter-spacing: .2em;
  color: var(--accent);
  padding: 16px 0 4px;
}
.reg-text {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
  width: 100%;
  min-height: 40px;
  font-family: var(--serif);
  font-size: 19px;
  text-align: left;
}
.reg-date { font-family: var(--mono); font-size: 11px; color: var(--muted); white-space: nowrap; }
.reg > .reg-row:last-of-type, .reg-texts + .reg-row { border-bottom: 1px solid var(--hair); }
.reg-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  padding-top: 22px;
  border-top: 1px solid var(--hair);
  font-size: 11px;
  letter-spacing: .08em;
}
.reg-links a { color: var(--muted); min-height: 32px; display: inline-flex; align-items: center; }

.read {
  width: min(100%, 680px);
  margin: 0 auto;
  padding: 40px 0 80px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  outline: none;
}
.read-title {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: clamp(40px, 6vw, 66px);
  line-height: 1.02;
  text-wrap: balance;
}
.read-meta { display: flex; flex-wrap: wrap; gap: 6px 28px; font-size: 12px; color: var(--muted); }
.read-loading { font-family: var(--serif); font-style: italic; font-size: 22px; color: var(--muted); }
.rule { height: 1px; background: var(--hair); }

.read-body {
  font-family: var(--serif);
  font-size: 21px;
  line-height: 1.6;
  overflow-wrap: break-word;
}
.read-body > * { margin: 0 0 1em; }
.read-body h2, .read-body h3, .read-body h4 {
  font-weight: 400;
  font-style: italic;
  line-height: 1.15;
  margin: 1.4em 0 .5em;
}
.read-body h2 { font-size: 32px; }
.read-body h3 { font-size: 26px; }
.read-body h4 { font-size: 22px; }
.read-body a { color: var(--ink); text-decoration-color: var(--faint); text-underline-offset: 3px; }
.read-body img { display: block; max-width: 100%; height: auto; margin: 1.2em auto; background: #E3DFD8; }
.read-body blockquote { margin-left: 0; padding-left: 20px; border-left: 1px solid var(--hair); color: var(--muted); }
.read-body ul, .read-body ol { padding-left: 1.2em; }
.read-body table { border-collapse: collapse; font-size: 16px; width: 100%; display: block; overflow-x: auto; }
.read-body th, .read-body td { border-bottom: 1px solid var(--hair); padding: 6px 10px 6px 0; text-align: left; }
.read-body code, .read-body pre { font-family: var(--mono); font-size: 14px; }
.read-body pre { overflow-x: auto; }

.read-nav { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.read-nav button { font-family: var(--serif); font-size: 19px; min-height: 44px; text-align: left; max-width: 20em; }
.read-nav .newer { text-align: right; margin-left: auto; }

.colophon {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 28px;
}
.colophon .col { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.colophon a, .linkish { font-size: 12px; color: var(--ink); min-height: 28px; display: inline-flex; align-items: center; text-align: left; }
.fineprint { margin: 0; font-size: 11px; line-height: 1.7; color: var(--muted); max-width: 46em; }

@keyframes beat {
  0% { transform: scale(1); }
  40% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}
@keyframes appear {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes grow {
  from { width: 0; }
  to { width: 100%; }
}

@media (max-width: 640px) {
  .wall, .mapview, .overlay { padding: 16px 20px 24px; }
  .card { width: calc(100vw - 40px); min-height: 0; }
  .card-body p { font-size: 19px; }
  .read-body { font-size: 19px; }
  .stage { padding-top: 16px; }
  .work img { max-height: max(calc(100svh - 290px), 220px); }
  .when-date { font-size: 30px; }
  .where-place { font-size: 24px; }
  .where-block { margin-left: 0; width: 100%; justify-content: space-between; }
  .where-block .where { text-align: left; align-items: flex-start; }
  .minimap { width: 112px; height: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  :root { --fade-in: 1ms; --fade-out: 1ms; }
  body.slideshow { --fade-in: 1ms; --fade-out: 1ms; }
  .picker, .mapview, .overlay { animation: none; }
  .like[aria-pressed="true"] svg { animation: none; }
}
