:root {
  --bg: #f5f5f5;
  --fg: #222;
  --muted: #6b7280;
  --card: #ffffff;
  --card2: #ecf0f1;
  --brand: #2c3e50;
  --brand2: #34495e;
  --border: rgba(0, 0, 0, 0.12);
  --focus: #111827;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--fg);
}

a {
  color: inherit;
  text-decoration: none;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

header.site-header {
  background: var(--brand);
  color: #fff;
  padding: 18px 16px;
}

header.site-header .title {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
}

header.site-header .subtitle {
  margin-top: 6px;
  text-align: center;
  opacity: 0.9;
  font-size: 1rem;
}

/* TV-friendly focus */
:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

/* Smart-TV fallback: nogle browsere har dårlig/ingen :focus-visible */
.viewer .btn:focus,
.viewer a:focus,
.gviewer .btn:focus,
.gviewer a:focus,
.dviewer .btn:focus,
.dviewer a:focus {
  outline: 4px solid #fff;
  outline-offset: 4px;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.55);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 18px;
  border-radius: 10px;
  border: 2px solid transparent;
  background: var(--brand2);
  color: #fff;
  font-size: 1.05rem;
  cursor: pointer;
  min-height: 52px;
}

.btn.secondary {
  background: #fff;
  color: var(--brand);
  border-color: var(--border);
}

.btn:active {
  transform: translateY(1px);
}

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
}

.card .card-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.card .card-meta {
  margin-top: 8px;
  color: var(--muted);
}

.chapter-grid .card {
  padding: 18px;
}

.chapter-grid .card .card-title {
  font-size: 1.35rem;
}

/* Featured stories */
.featured {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 16px;
}

.featured .featured-item {
  background: var(--card2);
  border-radius: 14px;
  padding: 16px;
  border: 1px solid var(--border);
}

.featured .featured-item .featured-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 0;
}

.featured .featured-item .featured-text {
  margin: 10px 0 0;
  color: #111;
}

/* Timeline */
.timeline-wrap {
  margin-top: 18px;
}

.timeline {
  display: flex;
  overflow-x: auto;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  scroll-snap-type: x mandatory;
}

.year-block {
  flex: 0 0 auto;
  width: 260px;
  scroll-snap-align: start;
  background: var(--card2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.year-block .year {
  font-weight: 800;
  font-size: 1.25rem;
  margin: 0 0 8px;
}

.media {
  display: block;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #dfe6e9;
  overflow: hidden;
}

.media-btn {
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.media-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
}

.media-btn:focus-visible {
  outline-offset: 6px;
}

.media + .media {
  margin-top: 10px;
}

.media.placeholder {
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(0, 0, 0, 0.55);
  font-weight: 700;
}

.media video {
  width: 100%;
  height: 150px;
  object-fit: cover;
}

/* Sydamerika TV-wrapper */
.chapter-top-cards {
  margin-top: 16px;
}

.legacy-section {
  margin-top: 18px;
}

.section-title {
  margin: 0 0 10px;
  font-size: 1.3rem;
  font-weight: 800;
}

.legacy-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.legacy-menu {
  display: block;
  overflow: auto;
  max-height: 42vh;
}

.legacy-menu-group {
  margin-top: 14px;
}

.legacy-menu-heading {
  font-weight: 800;
  margin-bottom: 8px;
}

.legacy-link {
  width: 100%;
  justify-content: flex-start;
  margin-top: 10px;
}

.legacy-link.is-active {
  border-color: var(--brand);
}

.legacy-frame {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
  height: 72vh;
  display: flex;
  flex-direction: column;
}

.legacy-frame-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card2);
}

.legacy-frame-title {
  font-weight: 800;
}

.legacy-frame-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.legacy-frame iframe {
  width: 100%;
  flex: 1 1 auto;
  height: auto;
  min-height: 320px;
  border: 0;
  background: #fff;
}

.legacy-album-actions {
  margin: 6px 0 12px;
}

.thumb-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.thumb-grid > * {
  flex: 0 0 calc(50% - 6px);
}

@media (min-width: 720px) {
  .thumb-grid {
    gap: 12px;
  }

  .thumb-grid > * {
    flex-basis: calc(33.333% - 8px);
  }
}

@media (min-width: 1024px) {
  .thumb-grid > * {
    flex-basis: calc(20% - 9.6px);
  }
}

@supports (display: grid) {
  .thumb-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .thumb-grid > * {
    flex: initial;
  }

  @media (min-width: 720px) {
    .thumb-grid {
      grid-template-columns: repeat(3, 1fr);
    }
  }

  @media (min-width: 1024px) {
    .thumb-grid {
      grid-template-columns: repeat(5, 1fr);
    }
  }

  @supports (grid-template-columns: repeat(auto-fill, minmax(140px, 1fr))) {
    .thumb-grid {
      grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
  }
}

.thumb-grid .media {
  border-radius: 12px;
}

.thumb-grid img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
}

.legacy-card-spacer {
  margin-bottom: 12px;
}

.legacy-help-spacer {
  margin-top: 10px;
}

@media (min-width: 900px) {
  .legacy-layout {
    grid-template-columns: 380px 1fr;
    align-items: start;
  }

  .legacy-menu {
    max-height: 78vh;
  }

  .legacy-frame {
    height: 78vh;
  }
}

/* Fullscreen viewer (slideshow) */
.viewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  display: none;
  z-index: 9999;
}

.viewer[aria-hidden="false"] {
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
}

.viewer-top {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.viewer-title {
  font-weight: 800;
  font-size: 1.1rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-stage {
  display: grid;
  place-items: center;
  padding: 8px 16px;
  min-height: 0;
}

.viewer-stage img,
.viewer-stage video {
  max-width: 100%;
  max-height: 70vh;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: #000;
}

.viewer-caption {
  padding: 0 16px 14px;
}

/* Fullscreen diary overlay (Sydamerika) */
.dviewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  display: none;
  z-index: 9999;
}

.dviewer[aria-hidden="false"] {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.dviewer-top {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dviewer-title {
  font-weight: 800;
  font-size: 1.1rem;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dviewer-stage {
  padding: 8px 16px;
  min-height: 0;
  overflow: auto;
}

.dviewer-stage iframe {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px;
  background: #fff;
}

.dviewer-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  justify-content: center;
}

.dviewer .btn {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
}

.dviewer .btn.secondary {
  color: #fff;
}

.viewer-help {
  padding: 0 16px 10px;
  opacity: 0.85;
  font-weight: 700;
  text-align: center;
}

.viewer-caption .muted {
  opacity: 0.85;
  font-weight: 700;
}

.viewer-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  justify-content: center;
}


.viewer .btn {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.18);
}

.viewer .btn.secondary {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
}

/* Greetings fullscreen reader */
.gviewer {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  color: #fff;
  display: none;
  z-index: 9998;
}

.gviewer[aria-hidden="false"] {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.gviewer-top {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.gviewer-title {
  font-weight: 800;
  font-size: 1.1rem;
}

.gviewer-stage {
  padding: 10px 16px 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.gviewer-meta {
  opacity: 0.88;
  font-weight: 700;
}

.gviewer-image {
  width: 100%;
  max-height: 38vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.18);
  background: #000;
}

.gviewer-text {
  font-size: 1.25rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.gviewer-page {
  opacity: 0.85;
  font-weight: 700;
  margin-top: 8px;
}

.gviewer-help {
  opacity: 0.85;
  font-weight: 700;
  margin-top: 10px;
  text-align: center;
}

.gviewer-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 16px;
  justify-content: center;
}


.gviewer .btn {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.18);
}

.gviewer .btn.secondary {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.18);
  color: #fff;
}

.media .caption {
  padding: 10px;
  font-size: 0.98rem;
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.9rem;
  margin-top: 8px;
}

/* Greetings */
.greetings {
  margin-top: 18px;
}

.greetings .greeting-item {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
}

.greetings .greeting-item + .greeting-item {
  margin-top: 12px;
}

.greetings .greeting-head {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}

.greetings .greeting-name {
  font-weight: 800;
}

.greetings .greeting-relation {
  color: var(--muted);
  font-weight: 700;
  margin-left: 10px;
}

.greetings .greeting-preview {
  margin-top: 8px;
  color: #111;
}

.greetings .greeting-preview-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 8px;
}

.greetings .greeting-thumb {
  width: 78px;
  height: 78px;
  flex: 0 0 auto;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #000;
}

.greetings .greeting-preview-row .greeting-preview {
  margin-top: 0;
}

.greetings .greeting-full {
  display: none;
  margin-top: 10px;
  max-height: 40vh;
  overflow-y: auto;
  padding-right: 6px;
}

.greetings .greeting-image {
  margin-bottom: 10px;
}

.greetings .greeting-image img {
  width: 100%;
  max-height: 320px;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #000;
}

.greetings .greeting-item[aria-expanded="true"] .greeting-full {
  display: block;
}

/* All greetings filter */
.filter-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
}

/* Footer nav */
.nav-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 20px 0;
}

/* Admin forms */
.form {
  display: grid;
  gap: 10px;
}

.admin-thumb {
  margin: 10px 0 6px;
}

.admin-thumb img,
.admin-thumb video {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #000;
}

.admin-thumb.admin-thumb--small img,
.admin-thumb.admin-thumb--small video {
  max-height: none;
  height: 110px;
  object-fit: contain;
}

.admin-list-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.admin-list-row .admin-thumb.admin-thumb--small {
  flex: 0 0 160px;
  width: 160px;
  margin: 0;
}

.admin-list-content {
  flex: 1 1 260px;
  min-width: 260px;
}

@media (max-width: 480px) {
  .admin-list-row .admin-thumb.admin-thumb--small {
    flex-basis: 120px;
    width: 120px;
  }

  .admin-thumb.admin-thumb--small img,
  .admin-thumb.admin-thumb--small video {
    height: 90px;
  }
}

.field label {
  display: block;
  font-weight: 700;
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
}

.field textarea {
  min-height: 120px;
}

.help {
  color: var(--muted);
  font-size: 0.95rem;
}

/* Upload indikator (admin + gæst) */
.upload-indicator {
  margin-top: 10px;
  padding: 12px;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--card2);
}

.upload-indicator-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.upload-indicator-status {
  font-weight: 700;
}

.upload-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--brand2);
  animation: upload-spin 0.8s linear infinite;
}

@keyframes upload-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.upload-progress {
  width: 100%;
  height: 16px;
  margin-top: 10px;
}

.upload-filelist {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.95rem;
}

.upload-filelist ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.upload-filemeta {
  opacity: 0.9;
}

@media (min-width: 720px) {
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Forside: hvis antal kort er ulige, så lad sidste kort fylde hele rækken */
  .chapter-grid .grid > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .featured {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* TV: bigger targets */
@media (min-width: 1024px) {
  header.site-header .title {
    font-size: 2.2rem;
  }

  .btn {
    font-size: 1.25rem;
    padding: 18px 22px;
    min-height: 62px;
  }

  .chapter-grid .card .card-title {
    font-size: 1.6rem;
  }

  .year-block {
    width: 320px;
  }

  .media video {
    height: 190px;
  }
}
