:root {
  --bg: #0b0e14;
  --card: #0f141d;
  --fg: #e9eef7;
  --muted: #9aa4b2;
  --accent: #42c6d9;
  --accent2: #2fe3c8;
  --border: rgba(255,255,255,.08);
}

.site-header .nav a[data-auth-only][hidden] {
  display: none !important;
}

html, body {
  height: 100%;
  margin: 0;
  background: radial-gradient(1200px 800px at 50% -200px, rgba(66,198,217,.15), transparent 60%), var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

body.modal-open,
body.legal-overlay-open {
  overflow: hidden;
  overscroll-behavior: none;
}

.wrap {
  max-width: 1100px;
  margin: 24px auto 64px;
  padding: 0 16px;
}

h1 {
  font-size: clamp(22px, 3vw, 32px);
  letter-spacing: .3px;
  margin: 8px 0 12px;
}

.sub {
  color: var(--muted);
  margin-bottom: 24px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 18px;
}

.card-btn {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .2s ease, border-color .2s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  overflow: hidden;
  isolation: isolate;
}

.card-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(66,198,217,.35);
  box-shadow: 0 12px 28px rgba(0,0,0,.35);
}

.card-btn:active {
  transform: translateY(0);
}

.card-btn img {
  width: 100%;
  height: 160px;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,.35));
  pointer-events: none;
}

.btn-title {
  position: absolute;
  left: 14px;
  bottom: 12px;
  right: 14px;
  font-size: 14px;
  color: var(--fg);
  text-shadow: 0 0 8px rgba(66,198,217,.5);
  opacity: .9;
}

.pulse::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 18px;
  border: 2px solid transparent;
  pointer-events: none;
  opacity: 0;
}

.card-btn.is-active::after {
  animation: pulse 900ms ease-out;
}

.card-btn.editor-selected {
  border-color: rgba(47,227,200,.62);
  box-shadow: 0 0 0 2px rgba(47,227,200,.16), 0 12px 28px rgba(0,0,0,.35);
}

.card-admin-controls {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  z-index: 3;
}

.card-admin-controls button {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(47,227,200,.38);
  border-radius: 999px;
  background: rgba(7,11,18,.86);
  color: var(--fg);
  cursor: pointer;
  font-weight: 700;
  line-height: 1;
}

.card-admin-controls button:disabled {
  opacity: .35;
  cursor: not-allowed;
}

@keyframes pulse {
  0% { opacity: .9; border-color: var(--accent); filter: drop-shadow(0 0 0px var(--accent)); }
  50% { opacity: .6; border-color: var(--accent2); filter: drop-shadow(0 0 12px var(--accent2)); }
  100% { opacity: 0; border-color: transparent; filter: none; }
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  z-index: 11000;
  padding: 20px;
  box-sizing: border-box;
  height: 100svh;
  min-height: 100svh;
  max-height: 100svh;
  overflow: hidden;
  overscroll-behavior: contain;
}

.overlay.is-open {
  display: flex;
}

.story-modal {
  width: min(980px, 96vw);
  height: min(calc(100svh - 40px), 1100px);
  max-height: min(calc(100svh - 40px), 1100px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(20,26,36,.96), rgba(12,16,24,.96));
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 30px 60px rgba(0,0,0,.45);
  position: relative;
  padding: 20px;
  box-sizing: border-box;
}

@supports (height: 100dvh) {
  .overlay {
    height: 100dvh;
    min-height: 100dvh;
    max-height: 100dvh;
  }

  .story-modal {
    height: min(calc(100dvh - 40px), 1100px);
    max-height: min(calc(100dvh - 40px), 1100px);
  }
}

.close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
  z-index: 5;
}

.story-topline {
  color: var(--accent);
  font-size: 13px;
  letter-spacing: .5px;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: .95;
  flex: 0 0 auto;
}

.story-title {
  margin: 0 40px 10px 0;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.15;
  flex: 0 0 auto;
}

.story-subtitle {
  color: var(--muted);
  margin-bottom: 18px;
  font-size: 14px;
  flex: 0 0 auto;
}

.story-main {
  display: flex;
  gap: 20px;
  min-height: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.story-main.layout-landscape {
  flex-direction: column;
}

.story-main.layout-portrait {
  flex-direction: row;
  align-items: flex-start;
  --story-pane-height: clamp(360px, calc(100svh - 320px), 620px);
  height: var(--story-pane-height);
  max-height: var(--story-pane-height);
  flex: 0 0 var(--story-pane-height);
  overflow: hidden;
}

@supports (height: 100dvh) {
  .story-main.layout-portrait {
    --story-pane-height: clamp(360px, calc(100dvh - 320px), 620px);
  }
}

.story-media {
  width: 100%;
  overflow: hidden;
  border-radius: 18px;
  clip-path: none;
  border: 1px solid var(--border);
  background: rgba(5, 11, 20, .86);
  box-shadow: 0 10px 30px rgba(0,0,0,.28);
  margin-bottom: 0;
  flex: 0 0 auto;
  box-sizing: border-box;
}

.story-main.layout-landscape .story-media {
  width: 100%;
  max-width: 100%;
}

.story-main.layout-portrait .story-media {
  width: clamp(246px, 32%, 384px);
  max-width: 384px;
  height: var(--story-pane-height);
  align-self: flex-start;
  flex: 0 0 clamp(246px, 32%, 384px);
  margin-bottom: 0;
}

.story-media.ratio-16-9 { aspect-ratio: 16 / 9; }
.story-media.ratio-3-2  { aspect-ratio: 3 / 2; }
.story-media.ratio-2-3  { aspect-ratio: 2 / 3; }
.story-media.ratio-9-16 { aspect-ratio: 9 / 16; }

.story-media img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: center center;
  border-radius: 18px;
  transform: translateZ(0);
}

.story-content-wrap {
  min-height: 0;
  min-width: 0;
  overflow: auto;
  border-radius: 16px;
  padding-right: 6px;
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  scrollbar-gutter: stable;
}

.story-main.layout-landscape .story-content-wrap,
.story-main.layout-portrait .story-content-wrap {
  flex: 1 1 auto;
}

.story-main.layout-portrait .story-content-wrap {
  height: var(--story-pane-height);
  max-height: var(--story-pane-height);
}

.story-content {
  font-size: 18px;
  line-height: 1.7;
  color: var(--fg);
}

.story-content.plain {
  white-space: pre-line;
}

.story-content.rich {
  white-space: normal;
}

.story-content.rich h3 {
  margin: 0 0 14px;
  font-size: 28px;
  line-height: 1.2;
  color: var(--fg);
}

.story-content.rich h4 {
  margin: 22px 0 8px;
  font-size: 20px;
  line-height: 1.3;
  color: var(--accent);
}

.story-content.rich p {
  margin: 0 0 12px;
}

.story-content.rich ul {
  margin: 4px 0 14px;
  padding-left: 22px;
}

.story-content.rich li {
  margin: 0 0 6px;
}

.story-content.rich strong {
  font-weight: 700;
}

.story-footer {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 14px;
  align-items: start;
  flex: 0 0 auto;
}

.nav-card {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 12px;
  align-items: center;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
  min-height: 84px;
  transition: transform .12s ease, border-color .2s ease, background .2s ease;
}

.nav-card:hover {
  transform: translateY(-2px);
  border-color: rgba(66,198,217,.35);
  background: rgba(255,255,255,.05);
}

.nav-card img {
  width: 84px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  display: block;
}

.nav-card small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.nav-card strong {
  display: block;
  font-size: 14px;
  line-height: 1.3;
}

.nav-card.right {
  grid-template-columns: 1fr 84px;
  text-align: right;
}

.nav-card.right img {
  order: 2;
}

.related {
  min-width: 240px;
  max-width: 320px;
  padding: 4px 8px;
}

.related h4 {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  letter-spacing: .4px;
  text-transform: uppercase;
}

.related-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.related-link {
  color: var(--fg);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.35;
  opacity: .9;
  cursor: pointer;
}

.related-link:hover {
  color: var(--accent2);
}

.story-counter {
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  text-align: right;
  flex: 0 0 auto;
}

.footer {
  margin-top: 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  opacity: .75;
}

.footer-legal-btn{background:transparent;border:none;padding:0;margin:0;color:inherit;font:inherit;cursor:pointer;text-decoration:underline;text-underline-offset:2px}
.legal-overlay{position:fixed;inset:0;display:none;align-items:center;justify-content:center;padding:20px;background:rgba(4,8,14,.86);backdrop-filter:blur(7px);z-index:12000}
.legal-overlay.is-open{display:flex}
.legal-overlay-card{width:min(1060px,100%);height:min(90vh,920px);background:#0a1420;border:1px solid rgba(47,227,200,.45);border-radius:14px;overflow:hidden;display:grid;grid-template-rows:auto minmax(0,1fr);box-shadow:0 24px 70px rgba(0,0,0,.55)}
.legal-overlay-head{display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px 12px;border-bottom:1px solid rgba(47,227,200,.25);background:rgba(47,227,200,.08)}
.legal-overlay-head h3{margin:0;font-size:1rem;color:#dffaf5}
.legal-overlay-close{border:1px solid rgba(47,227,200,.5);background:rgba(7,30,44,.75);color:#dffaf5;width:36px;height:36px;border-radius:999px;cursor:pointer;font-size:1.1rem;line-height:1}
.legal-overlay-frame{width:100%;height:100%;border:0;background:#fff}

.editor-panel {
  margin: 0 0 18px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(22,28,40,.82), rgba(10,14,22,.9));
  box-shadow: 0 10px 26px rgba(0,0,0,.28);
}

.editor-panel[hidden] {
  display: none !important;
}

.editor-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.editor-head strong {
  font-size: 14px;
  letter-spacing: .2px;
  color: var(--accent2);
}

.editor-head-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.editor-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px 12px;
}

.editor-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.editor-field.span-2 {
  grid-column: 1 / -1;
}

.editor-field label {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .2px;
}

.editor-field input,
.editor-field textarea,
.editor-field select {
  width: 100%;
  box-sizing: border-box;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(7,11,18,.85);
  color: var(--fg);
  padding: 9px 10px;
  font: inherit;
  font-size: 13px;
  outline: none;
}

.editor-field input:focus,
.editor-field textarea:focus,
.editor-field select:focus {
  border-color: rgba(66,198,217,.55);
  box-shadow: 0 0 0 2px rgba(66,198,217,.16);
}

.editor-field textarea {
  min-height: 74px;
  resize: vertical;
  line-height: 1.45;
}

.editor-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.editor-btn {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
  color: var(--fg);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}

.editor-btn:hover {
  border-color: rgba(66,198,217,.4);
  background: rgba(66,198,217,.12);
}

.editor-btn.primary {
  background: rgba(47,227,200,.2);
  border-color: rgba(47,227,200,.48);
}

.editor-status {
  font-size: 12px;
  color: var(--muted);
  margin-left: 4px;
}

@media (max-width: 860px) {
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .editor-field.span-2 {
    grid-column: auto;
  }

  .story-main.layout-portrait {
    flex-direction: column;
    --story-pane-height: auto;
    height: auto;
    max-height: none;
    flex: 0 0 auto;
    overflow: visible;
  }

  .story-main.layout-portrait .story-media {
    width: 100%;
    max-width: 100%;
    height: auto;
  }

  .story-main.layout-portrait .story-content-wrap {
    height: auto;
    max-height: none;
  }

  .story-footer {
    grid-template-columns: 1fr;
  }

  .related {
    min-width: 0;
    max-width: none;
    padding: 0;
  }

  .nav-card.right {
    text-align: left;
    grid-template-columns: 84px 1fr;
  }

  .nav-card.right img {
    order: 0;
  }
}

@media (max-width: 680px) {
  .overlay {
    align-items: stretch;
    padding: calc(12px + env(safe-area-inset-top)) 10px calc(12px + env(safe-area-inset-bottom));
    height: 100svh;
    min-height: 100svh;
    max-height: 100svh;
    overflow: hidden;
    overscroll-behavior: contain;
    touch-action: none;
  }

  .story-modal {
    width: 100%;
    height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
    min-height: calc(100svh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
    border-radius: 18px;
    padding: 14px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  @supports (height: 100dvh) {
    .overlay {
      height: 100dvh;
      min-height: 100dvh;
      max-height: 100dvh;
    }

    .story-modal {
      height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
      min-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
    }
  }

  .story-title {
    margin-right: 32px;
  }

  .story-main {
    gap: 12px;
    overflow: visible;
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
  }

  .story-main.layout-landscape,
  .story-main.layout-portrait {
    flex-direction: column;
  }

  .story-main.layout-portrait .story-media,
  .story-main.layout-landscape .story-media {
    width: 100%;
    max-width: 100%;
    height: auto;
    flex: 0 0 auto;
  }

  .story-media {
    aspect-ratio: auto !important;
    max-height: none;
    background: rgba(5, 11, 20, .85);
  }

  .story-media img {
    width: 100%;
    height: auto;
    max-height: 48dvh;
    object-fit: contain;
  }

  .story-content-wrap {
    min-height: 24dvh;
    max-height: none;
    overflow: visible;
    padding-right: 2px;
    padding-bottom: 6px;
  }

  .story-content {
    font-size: 17px;
    line-height: 1.62;
  }

  .story-footer {
    margin-top: 14px;
    padding-top: 14px;
    gap: 10px;
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "prev next"
      "related related";
  }

  #prev-nav {
    grid-area: prev;
  }

  #next-nav {
    grid-area: next;
  }

  .related {
    grid-area: related;
  }

  .nav-card {
    grid-template-columns: 60px 1fr;
    min-height: 60px;
    padding: 7px;
  }

  .nav-card.right {
    grid-template-columns: 60px 1fr;
  }

  .nav-card img {
    width: 60px;
    height: 44px;
    border-radius: 8px;
    object-fit: cover;
    background: transparent;
  }

  .nav-card strong {
    font-size: 13px;
  }

  .nav-card small {
    font-size: 10px;
  }
}

@media (max-width: 960px) and (max-height: 520px) and (orientation: landscape) {
  .overlay {
    align-items: stretch;
    padding: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom));
    overflow: hidden;
    touch-action: none;
  }

  .story-modal {
    width: 100%;
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px);
    min-height: 0;
    max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 20px);
    padding: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
  }

  .story-main,
  .story-main.layout-landscape,
  .story-main.layout-portrait {
    flex: 0 0 auto;
    flex-direction: column;
    gap: 12px;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .story-main.layout-landscape .story-media,
  .story-main.layout-portrait .story-media {
    width: 100%;
    max-width: 100%;
    height: auto;
    flex: 0 0 auto;
  }

  .story-media {
    aspect-ratio: auto !important;
    max-height: none;
  }

  .story-media img {
    width: 100%;
    height: auto;
    max-height: 42dvh;
    object-fit: contain;
  }

  .story-content-wrap,
  .story-main.layout-portrait .story-content-wrap {
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding-right: 2px;
  }

  .story-footer {
    margin-top: 14px;
    padding-top: 14px;
  }
}
