/* ============================================================
   Story Railway · Charlala DrawRoom Style Guide
   Namespace: .srv-  (safe inside Bubble Toolbox HTML)
   Shared source of truth: /shared/styleguide/tokens.css
   The .srv-app tokens below are duplicated locally so this
   markup still renders standalone (e.g. Bubble Toolbox export).
   ============================================================ */

html,
body {
  margin: 0 !important;
  padding: 0 !important;
  background: #f5f2fb;
  min-height: 100%;
}
[hidden] {
  display: none !important;
}

.srv-app {
  --p50: #f5f2fb;
  --p200: #ebe7f5;
  --p400: #b0a3d4;
  --p: #6651a1;
  --p600: #533f88;
  --p700: #3f2f6e;
  --surface: #ffffff;
  --bg: #f5f2fb;
  --border: #e4e4e7;
  --border2: #d4cce9;
  --text1: #333333;
  --text2: #52525b;
  --text3: #a1a1aa;
  --green: #16a34a;
  --red: #c93e3e;
  --amber: #d97706;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-card: 0 2px 12px #6651a114;
  --shadow-pop: 0 6px 24px #3f2f6e21;
  font-family: "Nunito Sans", system-ui, sans-serif;
  color: var(--text1);
  background: var(--bg);
  min-height: 100vh;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

.srv-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}
.srv-app *,
.srv-app *::before,
.srv-app *::after {
  box-sizing: border-box;
  font-family: inherit;
}
.srv-app button {
  cursor: pointer;
}
.srv-app button:disabled {
  cursor: not-allowed;
}
.srv-app :focus-visible {
  outline: 2px solid var(--p);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ---------- shared bits ---------- */
.srv-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 22px;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s, opacity 0.15s;
}
.srv-btn-primary {
  background: var(--p);
  color: #fff;
}
.srv-btn-primary:hover:not(:disabled) {
  background: var(--p600);
}
.srv-btn-primary:disabled {
  background: var(--p400);
  opacity: 0.55;
}
.srv-btn-secondary {
  background: var(--surface);
  color: var(--p700);
  border: 1.5px solid var(--border2);
}
.srv-btn-secondary:hover:not(:disabled) {
  background: var(--p50);
}
.srv-btn-danger {
  background: var(--surface);
  color: var(--red);
  border: 1.5px solid #e8c7c7;
}
.srv-btn-danger:hover {
  background: #fbf3f3;
}

.srv-eyebrow {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text3);
}

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

/* ============================================================
   HEADER
   ============================================================ */
.srv-header {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 16px 22px;
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 18px;
  row-gap: 0;
  margin-bottom: 20px;
}
.srv-header-titles {
  min-width: 140px;
}
.srv-header h1 {
  font-size: 17px;
  font-weight: 800;
  margin: 0;
}
.srv-details-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 3px;
  background: transparent;
  border: none;
  padding: 2px 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--p);
}
.srv-details-toggle:hover {
  color: var(--p600);
  text-decoration: underline;
}
.srv-details-toggle svg {
  transition: transform 0.18s ease;
}
.srv-details-toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}
.srv-header-details {
  grid-column: 1 / -1;
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.srv-header-details.srv-open {
  grid-template-rows: 1fr;
}
.srv-header-details > div {
  overflow: hidden;
  min-height: 0;
}
.srv-details-inner {
  border-top: 1.5px solid var(--border);
  margin-top: 0;
  padding: 14px 2px 0;
}
.srv-details-block .srv-eyebrow {
  display: block;
  margin-bottom: 6px;
}
.srv-details-block p {
  margin: 0;
  font-size: 13px;
  color: var(--text2);
  font-weight: 600;
  line-height: 1.55;
  white-space: pre-wrap;
}

.srv-progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}
.srv-progress-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
}
.srv-progress-track {
  height: 6px;
  border-radius: 999px;
  background: var(--p200);
  overflow: hidden;
}
.srv-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--p);
  width: 0%;
  transition: width 0.3s ease;
}

/* ============================================================
   STORYBOARD VIEW (default)
   Single-column masonry-ish list. Each row = one story part card:
   thumbnail, part number, play button (opt), story text (opt).
   ============================================================ */
.srv-storyboard {
  display: block;
}
#srvStoryboardList {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.srv-story-row {
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  box-shadow: none;
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 16px;
  min-width: 0;
  text-align: left;
  cursor: pointer;
}
.srv-story-row:hover {
  border-color: var(--p400);
  box-shadow: var(--shadow-card);
}
.srv-story-lead {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.srv-story-num {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--p200);
  color: var(--p700);
  font-size: 15px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.srv-story-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  justify-content: flex-start;
}
.srv-story-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text1);
  font-weight: 400;
  white-space: pre-wrap;
}
/* Give the read-along cursor a touch more breathing room inside the
   row chrome. The embed renders a single `.srl-cursor` that slides
   between words; the extra vertical padding keeps the bar from
   clipping the line above when `line-height` is tight. */
.srv-story-text,
.srv-current-part-text {
  padding: 2px 0;
}
.srv-audio-play-btn {
  flex: none;
  width: 28px;
  height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--p);
  color: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.12s;
}
.srv-audio-play-btn:hover:not(:disabled) {
  background: var(--p600);
}
.srv-audio-play-btn:focus-visible {
  outline: 3px solid #6651a155;
  outline-offset: 2px;
}
.srv-audio-play-btn[data-playing="true"] {
  background: var(--p600);
}
.srv-audio-play-btn svg {
  flex: none;
  pointer-events: none;
}

/* thumbnail button */
.srv-story-thumb {
  flex: none;
  width: 88px;
  height: 88px;
  background: #ffffff;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.srv-story-thumb svg,
.srv-story-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.srv-story-thumb-empty {
  border-style: dashed;
  border-color: var(--p400);
  background: var(--p50);
  color: var(--p700);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
}
.srv-story-thumb-empty:hover {
  background: var(--p200);
}
.srv-story-thumb-empty .srv-thumb-plus {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--p);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.srv-story-thumb-empty .srv-thumb-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--p700);
}

/* ============================================================
   DRAWING VIEW
   ============================================================ */
.srv-drawing-view {
  display: block;
}
.srv-drawing-layout {
  display: grid;
  grid-template-columns: auto minmax(0, 860px);
  justify-content: start;
  align-items: start;
  column-gap: 16px;
  row-gap: 12px;
}
.srv-btn-back {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  justify-self: start;
  padding: 8px 14px;
  font-size: 13px;
}

/* --- thumbnail rail (reference-only) --- */
.srv-mini-rail {
  grid-column: 1;
  grid-row: 2;
  width: 168px;
  flex: none;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 14px 12px;
  min-width: 168px;
  max-height: 680px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.srv-mini-rail-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text3);
  padding: 0 2px;
}
#srvMiniRailList {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.srv-mini-p {
  position: relative;
  display: block;
  flex: none;
  width: 144px;
  height: 144px;
  min-width: 144px;
  min-height: 144px;
  background: #ffffff;
  border: 1.5px solid var(--border2);
  border-radius: var(--radius-md);
  padding: 6px;
  overflow: hidden;
  cursor: default;
}
.srv-mini-p[data-current="true"] {
  border-color: var(--p);
  box-shadow: 0 0 0 2px var(--p200);
}
.srv-mini-p-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--p200);
  color: var(--p700);
  border-radius: var(--radius-sm);
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}
.srv-mini-p-thumb {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #ffffff;
  border-radius: 6px;
}
.srv-mini-p-thumb img,
.srv-mini-p-thumb svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.srv-mini-p-thumb-empty {
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;
  border: 1.5px dashed var(--border2);
  border-radius: 6px;
  background: var(--p50);
  display: block;
}

.srv-part-card {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  max-width: 860px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  box-sizing: border-box;
}
.srv-canvas-wrap {
  grid-column: 2;
  grid-row: 2;
  width: 100%;
  max-width: 860px;
  height: 680px;
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: none;
  overflow: hidden;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
}
.srv-canvas-object {
  width: 100%;
  height: 680px;
  border: 0;
  display: block;
  background: transparent;
}
.srv-current-part-text {
  flex: none;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text1);
  font-weight: 400;
  white-space: pre-wrap;
}
.srv-current-part-audio {
  display: flex;
  align-items: center;
  width: 100%;
}
.srv-current-part-audio audio {
  flex: 1;
  min-width: 0;
  height: 40px;
}

/* ============================================================
   MODALS
   ============================================================ */
.srv-overlay {
  position: fixed;
  inset: 0;
  background: #3f2f6e59;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 20px;
}
.srv-overlay.srv-show {
  display: flex;
}
.srv-modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  max-width: 420px;
  width: 100%;
  padding: 26px 26px 22px;
  animation: srv-pop 0.14s ease-out;
}
@keyframes srv-pop {
  0% {
    transform: scale(0.92);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}
.srv-modal h2 {
  font-size: 18px;
  font-weight: 800;
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.srv-modal p {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.55;
  margin: 0 0 14px;
  font-weight: 600;
}
.srv-missing-list {
  background: #fdf2e3;
  border: 1.5px solid #f3ddb8;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin: 0 0 16px;
  list-style: none;
}
.srv-missing-list li {
  font-size: 13px;
  font-weight: 700;
  color: #8a5104;
  padding: 3px 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.srv-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.srv-warn-icon,
.srv-ok-icon {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.srv-warn-icon {
  background: #fdf2e3;
  color: var(--amber);
}
.srv-ok-icon {
  background: #e8f6ed;
  color: var(--green);
}

/* ============================================================
   BOOT / ERROR SCREEN
   ============================================================ */
.srv-boot {
  max-width: 480px;
  margin: 80px auto 0;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 32px 28px;
  text-align: center;
}
.srv-boot h1 {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 8px;
}
.srv-boot p {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.55;
  margin: 0;
  font-weight: 600;
}
.srv-boot .srv-boot-error {
  color: var(--red);
}

/* ============================================================
   DONE SCREEN
   ============================================================ */
.srv-done-screen {
  max-width: 460px;
  margin: 60px auto 0;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 40px 32px;
  text-align: center;
  display: none;
}
.srv-done-screen.srv-show {
  display: block;
}
.srv-done-check {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #e8f6ed;
  color: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 18px;
}
.srv-done-screen h1 {
  font-size: 20px;
  font-weight: 800;
  margin: 0 0 8px;
}
.srv-done-screen p {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.55;
  margin: 0;
  font-weight: 600;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 900px) {
  .srv-story-thumb {
    width: 72px;
    height: 72px;
  }
}
@media (max-width: 820px) {
  .srv-header h1 {
    font-size: 15px;
  }
  .srv-canvas-wrap,
  .srv-canvas-object {
    height: 560px;
  }
}
@media (max-width: 640px) {
  .srv-drawing-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .srv-btn-back,
  .srv-part-card,
  .srv-mini-rail,
  .srv-canvas-wrap {
    grid-column: 1;
  }
  .srv-btn-back {
    grid-row: 1;
  }
  .srv-part-card {
    grid-row: 2;
  }
  .srv-mini-rail {
    grid-row: 3;
    width: 100%;
    min-width: 0;
    max-height: none;
  }
  .srv-canvas-wrap {
    grid-row: 4;
  }
  #srvMiniRailList {
    display: grid;
    grid-template-columns: repeat(auto-fill, 144px);
    justify-content: start;
    gap: 8px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .srv-app *,
  .srv-app *::before,
  .srv-app *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
}
