:root{
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

  --bg: #0b1220;
  --card: rgba(255,255,255,0.10);
  --card2: rgba(255,255,255,0.08);
  --stroke: rgba(255,255,255,0.14);

  --text: #eaf0ff;
  --muted: rgba(234,240,255,0.75);

  --accent: #ffcc00;
  --accent2: #6dd6ff;

  --danger: #b11622;
  --ok: #23c55e;
}

/* =========================
   BASE
========================= */
body{
  margin:0;
  background:
    radial-gradient(1200px 800px at 20% 0%, rgba(255,204,0,0.12), transparent 60%),
    radial-gradient(900px 700px at 90% 10%, rgba(109,214,255,0.12), transparent 55%),
    linear-gradient(180deg, #070b14 0%, #0b1220 60%, #070b14 100%);
  color: var(--text);
}

/* =========================
   TOP BAR
========================= */
.topbar{
  position: sticky;
  top: 0;
  z-index: 50;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 16px;
  backdrop-filter: blur(10px);
  background: rgba(8,12,20,0.75);
  border-bottom: 1px solid var(--stroke);
}

.brandTitle{
  font-weight: 900;
  letter-spacing: 0.2px;
}
.brandSub{
  font-size: 12px;
  color: var(--muted);
}

.topbarRight{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

/* =========================
   LAYOUT
========================= */
.wrap{
  max-width: 980px;
  margin: 16px auto;
  padding: 0 12px 28px;
  display:grid;
  gap: 12px;
}

.card{
  border: 1px solid var(--stroke);
  background: var(--card);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}

.hero{
  background:
    radial-gradient(900px 500px at 20% 20%, rgba(255,204,0,0.10), transparent 60%),
    radial-gradient(900px 500px at 80% 40%, rgba(109,214,255,0.10), transparent 60%),
    var(--card);
}

h1{
  margin: 0 0 10px 0;
  font-size: 18px;
}
h2{
  margin: 0 0 10px 0;
  font-size: 15px;
}

/* =========================
   FORMS
========================= */
.field label{
  display:block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 800;
}

input[type="text"],
input[type="number"],
textarea,
select{
  width: 100%;
  box-sizing: border-box;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.16);
  outline: none;
  background: rgba(0,0,0,0.25);
  color: var(--text);
}

textarea{ resize: vertical; }

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

.hint{
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

/* =========================
   BUTTONS
========================= */
.btn{
  appearance:none;
  border: 1px solid rgba(255,255,255,0.16);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 12px;
  cursor:pointer;
  font-weight: 900;
}

.btnPrimary{
  border-color: rgba(255,204,0,0.45);
  background: linear-gradient(180deg, rgba(255,204,0,0.25), rgba(0,0,0,0.15));
}

.btnGhost{
  background: rgba(0,0,0,0.15);
}

.btnDanger{
  background: rgba(177,22,34,0.25);
  border-color: rgba(177,22,34,0.5);
}

/* =========================
   STATUS
========================= */
.badge{
  display:inline-block;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 900;
  width: fit-content;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(0,0,0,0.18);
}

.statusLine{
  margin-top: 10px;
  display:flex;
  align-items:center;
  gap: 10px;
}

.spinner{
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.18);
  border-top-color: rgba(255,255,255,0.65);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin{ to { transform: rotate(360deg); } }

.error{
  margin-top: 10px;
  padding: 10px;
  border-radius: 12px;
  background: rgba(255, 70, 90, 0.14);
  border: 1px solid rgba(255, 70, 90, 0.35);
}

/* =========================
   STORY + IMAGE
========================= */
.metaLine{
  display:flex;
  gap: 14px;
  flex-wrap:wrap;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.pre{
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(0,0,0,0.40);
  border: 1px solid rgba(255,255,255,0.12);
  padding: 12px;
  border-radius: 14px;
  min-height: 56px;
}

.imgBox{ margin-top: 10px; }

#chapterImage{
  max-width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.12);
  display:none;
}

/* =========================
   🎧 TTS / LYSSNA
========================= */
.ttsRow{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
}

.ttsStatus{
  font-size: 13px;
  color: var(--muted);
}

/* =========================
   CHECKS
========================= */
.rowChecks{
  margin-top: 10px;
  display:flex;
  gap: 14px;
  flex-wrap:wrap;
}

.check{
  display:flex;
  gap: 8px;
  align-items:center;
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

/* =========================
   DRAWER (PARENT) – FIX: scroll i drawerCard, inte i overlay
========================= */

/* Overlay */
.drawer,
#parentDrawer{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 9998;

  /* Viktigt: overlay ska INTE scrolla (iOS-buggar med flex+overflow) */
  overflow: hidden;

  /* Safe area padding */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: 12px;
  padding-right: 12px;

  display: flex;
  justify-content: center;

  /* Viktigt: vi måste kunna se TOPPEN av kortet (stämning/längd) */
  align-items: flex-start;
}

/* Kortet som ska scrolla */
.drawerCard{
  width: 100%;
  max-width: 980px;

  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(10,14,24,0.92);
  box-shadow: 0 20px 80px rgba(0,0,0,0.5);

  padding: 14px;

  /* Nyckeln: kortet får en maxhöjd och scrollar själv */
  max-height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom) - 24px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Header ska alltid ligga kvar så Stäng syns */
#parentDrawer .drawerHeader{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap: 12px;

  position: sticky;
  top: 0;                 /* inne i kortet */
  z-index: 9999;
  background: rgba(10,14,24,0.98);
  padding: 10px 10px;

  /* matchar kortets padding så sticky ser snygg ut */
  margin: -14px -14px 10px -14px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  backdrop-filter: blur(6px);
}

.drawerTitle{ font-weight: 950; }
.drawerSub{ font-size: 12px; color: var(--muted); }

.drawerFooter{
  margin-top: 12px;
  display:flex;
  justify-content:flex-end;
}

/* Knappen synlig och klickbar */
#parentDrawer #parentCloseBtn{
  position: relative;
  z-index: 10000;
}

/* =========================
   UTILS
========================= */
.hidden{ display:none !important; }

@media (max-width: 900px){
  .row2{ grid-template-columns: 1fr; }
  .topbarRight{ width:100%; justify-content:flex-start; }
}
