:root {
  --bar: #1f2a37;
  --bar-text: #f3f4f6;
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --accent: #c2410c;
  --accent-tint: #fff1e6;
  --warn: #854d0e;
  --warn-tint: #fef9c3;
  --line: #e5e7eb;
  --top-h: 56px;
  --tab-h: 56px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* The app is one screen-high column, as in Nabble: the top bar, the page (the
   only thing that scrolls), then the tab bar. Nothing moves under the bars. */
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  display: flex; flex-direction: column; height: 100dvh;
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
code { font-size: .9em; background: #eef0f3; padding: 0 .25em; border-radius: 4px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Top navbar */
.topbar {
  position: relative; z-index: 30; flex: 0 0 auto;
  height: calc(var(--top-h) + var(--safe-top));
  padding: var(--safe-top) calc(8px + var(--safe-right)) 0 calc(4px + var(--safe-left));
  display: flex; align-items: center; gap: 4px;
  background: var(--bar); color: var(--bar-text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .2);
}
.hamburger {
  flex: none; width: 48px; height: 48px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px;
  background: none; border: 0; border-radius: 8px; cursor: pointer; color: inherit;
}
.hamburger span { display: block; width: 22px; height: 2px; background: currentColor; border-radius: 1px; }
.hamburger:active { background: rgba(255, 255, 255, .12); }
.picker { flex: 1; min-width: 0; display: flex; gap: 6px; }
.picker select {
  flex: 1; min-width: 0; height: 40px; padding: 0 32px 0 12px;
  font: inherit; font-weight: 600; color: var(--bar-text);
  background: rgba(255, 255, 255, .1) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f3f4f6' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 18px;
  border: 1px solid rgba(255, 255, 255, .2); border-radius: 8px;
  appearance: none; -webkit-appearance: none; text-overflow: ellipsis;
}
.picker select option { color: var(--text); }
.picker button { font: inherit; border-radius: 8px; border: 0; padding: 0 12px; }

/* Hamburger drawer */
.scrim {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .4);
  opacity: 0; transition: opacity .2s;
}
.drawer-open .scrim { opacity: 1; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  width: min(300px, 85vw);
  padding: calc(16px + var(--safe-top)) 0 calc(16px + var(--safe-bottom)) var(--safe-left);
  background: var(--card); box-shadow: 2px 0 12px rgba(0, 0, 0, .25);
  transform: translateX(-105%); transition: transform .22s ease-out;
  overflow-y: auto; visibility: hidden;
}
.drawer-open .drawer { transform: none; visibility: visible; }
.drawer-head { padding: 0 20px 16px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.drawer-title { font-size: 1.15rem; font-weight: 700; }
.drawer-sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }
.meter { height: 6px; background: var(--line); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.meter div { height: 100%; background: var(--accent); }
.drawer-link {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 52px; padding: 0 20px; color: var(--text); text-decoration: none; font-weight: 500;
}
button.drawer-link { width: 100%; font: inherit; font-weight: 500; background: none; border: 0; cursor: pointer; }
.drawer-link:active, .drawer-link.active { background: var(--accent-tint); color: var(--accent); }
.badge { min-width: 24px; padding: 0 8px; border-radius: 12px; background: var(--line); color: var(--text); font-size: .8rem; text-align: center; }

/* Bottom tab bar: icons only, as in Nabble. The label stays for a screen
   reader; the open tab is the ink one with a short orange bar under it. */
.tabbar {
  position: relative; z-index: 30; flex: 0 0 auto;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 4px calc(4px + var(--safe-right)) var(--safe-bottom) calc(4px + var(--safe-left));
  background: var(--card); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-width: 0; height: calc(var(--tab-h) - 4px); border-radius: 10px;
  color: var(--muted); text-decoration: none;
}
.tabbar a::after { content: ""; width: 18px; height: 3px; border-radius: 2px; background: transparent; }
.tabbar a.active { color: var(--text); }
.tabbar a.active::after { background: var(--accent); }
.tabbar a:active { background: #f3f4f6; }
.icon { width: 24px; height: 24px; flex: none; }

/* Content: the scrolling middle of the column. Full width so its scrollbar
   sits at the screen's edge; the side padding keeps the text 720px wide. */
.content {
  flex: 1 1 auto; min-height: 0; width: 100%;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 12px max(calc(12px + var(--safe-right)), calc(50% - 348px)) 16px max(calc(12px + var(--safe-left)), calc(50% - 348px));
}
/* With no top bar (login) or no tab bar (no script open), the page meets the
   screen's edge itself, so it keeps clear of the notch and the home indicator. */
.content:first-child { padding-top: calc(12px + var(--safe-top)); }
.content:last-child { padding-bottom: calc(16px + var(--safe-bottom)); }
.page-title { font-size: 1.35rem; margin: 8px 4px 12px; }
.section-title { font-size: 1rem; color: var(--muted); margin: 24px 4px 8px; }
.empty { color: var(--muted); margin: 8px 4px; }
.muted { color: var(--muted); }
.missing { color: var(--warn); }
.error { white-space: pre-wrap; background: var(--warn-tint); padding: 12px; border-radius: 8px; overflow-x: auto; }

.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card { display: flex; gap: 12px; background: var(--card); border-radius: 12px; padding: 12px 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.card .body { flex: 1; min-width: 0; }
.card .num {
  flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent-tint); color: var(--accent); font-weight: 700; font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
}
.row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.mins { flex: none; color: var(--muted); font-size: .9rem; }
.meta { color: var(--muted); font-size: .88rem; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.summary { margin: 6px 0 0; font-size: .95rem; }
.conflict-line { margin: 4px 0 0; font-size: .88rem; color: var(--muted); }
.conflict-line::before { content: "⚔ "; }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #eef0f3; color: var(--text); font-size: .8rem; }
.chip.missing { background: var(--warn-tint); color: var(--warn); }

/* Tappable cards and scene reordering */
a.tap { display: block; color: inherit; text-decoration: none; margin: -12px 0; padding: 12px 0; }
a.tap:active { opacity: .6; }
.card.scene { padding-right: 6px; }
.mover { flex: none; display: flex; flex-direction: column; justify-content: center; gap: 4px; }
.mover form { margin: 0; }
.mover button {
  width: 44px; height: 36px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: .8rem; cursor: pointer;
}
.mover button:active { background: var(--line); }
.mover button:disabled { opacity: .3; cursor: default; }
.card:target { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Forms */
.back { display: inline-block; margin: 4px 4px 0; padding: 6px 0; text-decoration: none; font-weight: 500; }
.form { display: grid; gap: 14px; }
.card-form { background: var(--card); border-radius: 12px; padding: 14px; box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.field { display: grid; gap: 6px; min-width: 0; margin: 0; border: 0; padding: 0; }
.field-row { display: flex; gap: 12px; }
.field-row > .field { flex: 1; }
.field-row > .field-narrow { flex: 0 0 7.5rem; }
.field label, .field legend { font-weight: 600; font-size: .9rem; padding: 0; }
.field input[type=text], .field input[type=number], .field input[type=password], .field select, .field textarea {
  width: 100%; font: inherit; font-size: 16px; /* 16px stops iOS zooming in on focus */
  color: var(--text); background: var(--card);
  border: 1px solid #cbd2d9; border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
.field textarea { resize: vertical; line-height: 1.4; }
.field .screenplay-input { font-family: "Courier Prime", "Courier New", Courier, monospace; font-size: 15px; min-height: 18rem; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
[aria-invalid="true"] { border-color: #dc2626 !important; }
.field-error { margin: 0; color: #dc2626; font-size: .88rem; }
.form-error { margin: 0; padding: 10px 12px; border-radius: 10px; background: #fee2e2; color: #991b1b; font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px 0 10px;
  background: var(--card); border: 1px solid #cbd2d9; border-radius: 22px; font-weight: 400 !important;
}
.conflicts .hint { margin: 0; font-size: .88rem; }
.conflict-row { display: grid; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.conflict-row .check { justify-self: start; }
.conflict-add { margin: 0; font-weight: 600; font-size: .88rem; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.check:has(input:checked) { border-color: var(--accent); background: var(--accent-tint); }
.hint, .lead { color: var(--muted); margin: 0; }
.lead { margin: 0 4px 12px; color: var(--text); }
.plain-list { margin: 0 4px 16px; padding-left: 20px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 20px;
  font: inherit; font-weight: 600; border-radius: 12px; border: 1px solid #cbd2d9;
  background: var(--card); color: var(--text); text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; flex: 1; }
.btn.danger { background: none; border-color: #dc2626; color: #dc2626; }
.btn:active { filter: brightness(.9); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: .9rem; }
.btn:disabled { opacity: .6; cursor: progress; }
.ask { margin: 8px 0 0; }
.ask-all { display: flex; margin: 0 0 12px; }
.notice { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; background: #dcfce7; color: #166534; font-weight: 500; }
.batch-note { margin: 0 4px 12px; }
.batch-gap { margin: 0 0 8px; }
label.batch-gap { border-radius: 12px; padding: 6px 14px 6px 10px; }
.danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); }
.sp-edit { float: right; font-size: .8rem; text-decoration: none; padding: 0 4px; }

/* Screenplay */
.screenplay {
  background: var(--card); border-radius: 12px; padding: 20px 18px 28px;
  font-family: "Courier Prime", "Courier New", Courier, monospace; font-size: 15px; line-height: 1.35;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
}
.sp-title { text-align: center; text-transform: uppercase; font-size: 1.1rem; margin: 0 0 24px; text-decoration: underline; }
.sp-scene + .sp-scene { margin-top: 28px; border-top: 1px dashed var(--line); padding-top: 16px; }
.sp-scene-head { font-size: .8rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--muted); font-weight: 600; margin: 0 0 12px; }
.sp-num { display: inline-block; min-width: 1.6em; padding: 0 4px; border-radius: 4px; background: var(--accent-tint); color: var(--accent); text-align: center; }
.screenplay p { margin: 0 0 1em; white-space: pre-wrap; }
.sp-heading { font-weight: 700; text-transform: uppercase; }
.sp-character { text-transform: uppercase; margin: 0 0 0 38% !important; }
.sp-parenthetical { margin: 0 0 0 30% !important; }
.sp-dialogue { margin: 0 12% 1em 22% !important; }
.sp-character + .sp-dialogue, .sp-parenthetical + .sp-dialogue { margin-top: 0 !important; }
.sp-transition { text-align: right; text-transform: uppercase; }
.sp-conflicts {
  list-style: none; margin: -6px 0 12px; padding: 6px 10px; border-left: 3px solid var(--line);
  color: var(--muted); font-size: .8rem; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.sp-conflicts li::before { content: "⚔ "; }
.sp-missing { color: var(--muted); font-style: italic; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

@media (max-width: 380px) {
  .sp-character { margin-left: 30% !important; }
  .sp-parenthetical { margin-left: 22% !important; }
  .sp-dialogue { margin-left: 12% !important; margin-right: 4% !important; }
}

@media (prefers-color-scheme: dark) {
  :root { --bg: #111827; --card: #1f2937; --text: #e5e7eb; --muted: #9ca3af; --line: #374151; --accent: #fb923c; --accent-tint: #431407; --warn: #facc15; --warn-tint: #3a2f04; }
  code, .chip { background: #374151; }
  .tabbar a:active { background: #374151; }
  .field input[type=text], .field input[type=number], .field input[type=password], .field select, .field textarea, .check, .btn, .mover button { border-color: #4b5563; }
  .form-error { background: #450a0a; color: #fecaca; }
  .notice { background: #052e16; color: #bbf7d0; }
  .btn.primary { color: #0b1220; }
}
