/**
 * SimpleStory Main Styles
 * Core layout and navigation styles
 */

* {
  box-sizing: border-box;
}

img {
  border: none;
}

:root {
  /* Core colors - override these for theming */
  --ds-bg: #0a0a0a;
  --ds-surface: #141414;
  --ds-surface-raised: #1a1a1a;
  --ds-text: #e5e5e5;
  --ds-text-muted: #a3a3a3;
  --ds-border: #2a2a2a;
  --ds-accent: #2563eb;
  --ds-accent-hover: #1d4ed8;

  /* Nav */
  --ds-nav-height: 48px;
  --ds-nav-bg: #0a0a0a;
  --ds-nav-border: #1a1a1a;

  /* Transitions */
  --ds-transition-fast: 150ms;
  --ds-transition-normal: 300ms;
}

/* Light Mode */
[data-theme="light"] {
  --ds-bg: #ffffff;
  --ds-surface: #f5f5f5;
  --ds-surface-raised: #ffffff;
  --ds-text: #1a1a1a;
  --ds-text-muted: #666666;
  --ds-border: #e0e0e0;
  --ds-accent: #2563eb;
  --ds-accent-hover: #1d4ed8;
  --ds-nav-bg: #ffffff;
  --ds-nav-border: #e0e0e0;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--ds-bg);
  color: var(--ds-text);
  min-height: 100vh;
}

/* Main App Layout */
.simplestory-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Navigation Bar */
.simplestory-nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--ds-nav-height);
  padding: 0 16px;
  background: var(--ds-nav-bg);
  border-bottom: 1px solid var(--ds-nav-border);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ds-text);
  cursor: pointer;
  transition: all var(--ds-transition-fast);
}

.nav-btn:hover:not(:disabled) {
  background: var(--ds-surface);
  border-color: var(--ds-border);
}

.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.nav-btn svg {
  flex-shrink: 0;
}

.nav-btn-text {
  font-size: 14px;
}

/* Theme Toggle Button */
.theme-toggle-btn {
  position: relative;
}

.theme-toggle-btn .theme-icon-light,
.theme-toggle-btn .theme-icon-dark {
  display: block;
  transition: opacity var(--ds-transition-fast);
}

.mute-toggle-btn {
  position: relative;
}

.mute-toggle-btn .audio-icon-on,
.mute-toggle-btn .audio-icon-off {
  transition: opacity var(--ds-transition-fast);
}

.nav-title {
  font-size: 14px;
  color: var(--ds-text-muted);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Main Content Area */
.simplestory-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Page Container */
.simplestory-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  margin: 0 auto;
  width: 100%;
}

/* Template Content */
.template-content {
  flex: 1;
  padding: 20px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Generic Elements */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 16px;
  line-height: 1.3;
}

h1 { font-size: 28px; }
h2 { font-size: 24px; }
h3 { font-size: 20px; }
h4 { font-size: 18px; }
h5 { font-size: 16px; }
h6 { font-size: 14px; }

p {
  margin: 0 0 16px;
  line-height: 1.6;
}

hr {
  border: none;
  height: 1px;
  background: var(--ds-border);
  margin: 24px 0;
}

/* Links and Buttons */
.page-link {
  color: var(--ds-accent);
  text-decoration: none;
  transition: color var(--ds-transition-fast);
}

.page-link:hover {
  color: var(--ds-accent-hover);
  text-decoration: underline;
}

.standalone-link {
  display: inline-block;
  margin: 8px 0;
}

.page-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  background: var(--ds-accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--ds-transition-fast);
  margin: 8px 0;
}

.page-button:hover {
  background: var(--ds-accent-hover);
  transform: translateY(-1px);
}

.page-button:active {
  transform: translateY(0);
}

/* Mentions and Hashtags */
.mention {
  color: var(--ds-accent);
  cursor: pointer;
}

.hashtag {
  color: var(--ds-accent);
  cursor: pointer;
}

/* Images */
.content-image {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 16px 0;
}

/* Cards */
.content-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: 12px;
  overflow: hidden;
  margin: 16px 0;
}

.card-image img {
  width: 100%;
  height: auto;
  display: block;
}

.card-body {
  padding: 16px;
}

.card-title {
  margin: 0 0 8px;
  font-size: 18px;
}

.card-subtitle {
  margin: 0 0 12px;
  color: var(--ds-text-muted);
  font-size: 14px;
}

.card-content {
  font-size: 14px;
  line-height: 1.5;
}

.card-action-bar {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--ds-border);
}

.card-action {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--ds-text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.card-action:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--ds-text);
}

.card-action.card-dismiss:hover {
  color: #ef4444;
}

.card-action svg {
  flex-shrink: 0;
}

/* Notifications */
.notification {
  padding: 12px 16px;
  border-radius: 8px;
  margin: 12px 0;
  font-size: 14px;
}

.notification-info {
  background: #1e3a5f;
  border-left: 4px solid #3b82f6;
}

.notification-success {
  background: #14532d;
  border-left: 4px solid #22c55e;
}

.notification-warning {
  background: #713f12;
  border-left: 4px solid #eab308;
}

.notification-error {
  background: #7f1d1d;
  border-left: 4px solid #ef4444;
}

/* Light mode notifications */
[data-theme="light"] .notification-info {
  background: #dbeafe;
  border-left-color: #3b82f6;
  color: #1e40af;
}

[data-theme="light"] .notification-success {
  background: #dcfce7;
  border-left-color: #22c55e;
  color: #166534;
}

[data-theme="light"] .notification-warning {
  background: #fef3c7;
  border-left-color: #eab308;
  color: #854d0e;
}

[data-theme="light"] .notification-error {
  background: #fee2e2;
  border-left-color: #ef4444;
  color: #b91c1c;
}

[data-theme="light"] .notification-action-btn {
  color: rgba(0, 0, 0, 0.7);
  background: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .notification-action-btn:hover {
  background: rgba(0, 0, 0, 0.15);
  color: #000;
}

[data-theme="light"] .card-action:hover {
  background: rgba(0, 0, 0, 0.08);
}

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

.notification-content {
  flex: 1;
}

.notification-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.notification-action-btn {
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.notification-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
}

.notification-action-btn.notification-dismiss {
  padding: 6px 10px;
}

.notification-action-btn.notification-dismiss:hover {
  background: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* Choices Block */
.choices-block {
  margin: 24px 0;
  width: 100%;
}

.choices-prompt {
  margin: 0 0 16px;
  font-size: 16px;
  color: var(--ds-text);
  text-align: center;
}

.choices-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.choices-buttons .choice-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
}

/* Transitions */
.glitch-transition {
  animation: glitch 0.3s steps(5, end);
}

@keyframes glitch {
  0%, 100% {
    transform: translate(0);
    opacity: 1;
  }
  20% {
    transform: translate(-3px, 2px);
    opacity: 0.8;
  }
  40% {
    transform: translate(3px, -2px);
    opacity: 0.9;
  }
  60% {
    transform: translate(-2px, -3px);
    opacity: 0.7;
  }
  80% {
    transform: translate(2px, 3px);
    opacity: 0.85;
  }
}

/* Responsive */

/* Mobile (< 480px) */
@media (max-width: 480px) {
  .nav-btn-text {
    display: none;
  }

  .template-content {
    padding: 16px;
  }
}

/* Tablet (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  .template-content {
    max-width: 90%;
    padding: 18px;
  }
}

/* Desktop (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .template-content {
    max-width: 700px;
  }
}

/* Large Desktop (> 1200px) */
@media (min-width: 1200px) {
  .template-content {
    max-width: 800px;
  }
}

/* CUL-293: Mobile/touch play support.
   Instant taps (no 300ms delay, no double-tap zoom) on player controls. These
   classes only exist in player-rendered content, so the editor chrome is
   unaffected. Harmless on desktop. */
.nav-btn,
.page-button,
.page-link,
.standalone-link,
.card-action,
.social-action,
.social-more-btn,
.template-content button,
.template-content a[href],
.template-content [role="button"] {
  touch-action: manipulation;
}

/* Comfortable ≥44px touch targets on phones / small tablets. The bare inline
   .page-link (links inside prose) is intentionally excluded from min-height so
   text flow isn't broken — only block-level standalone links are sized. */
@media (max-width: 768px) {
  .nav-btn { min-width: 44px; min-height: 44px; justify-content: center; }
  .page-button { min-height: 44px; }
  .standalone-link { display: inline-flex; align-items: center; min-height: 44px; }
  .card-action,
  .social-action,
  .social-more-btn { min-width: 44px; min-height: 44px; }
}

/* Empty-state / render-error message panel */
.story-message {
  max-width: 480px;
  margin: 15vh auto;
  padding: 32px;
  text-align: center;
  color: var(--ds-text);
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: 12px;
}

.story-message h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.story-message p {
  margin: 0;
  color: var(--ds-text-muted);
}

.story-message.story-error {
  border-color: #ef4444;
}

.story-message.story-error h2 {
  color: #ef4444;
}

/* Visible keyboard focus indicator (accessibility) */
:focus-visible {
  outline: 2px solid var(--ds-accent, #3b82f6);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Backup reminder banner */
.backup-reminder {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(90vw, 560px);
  padding: 12px 16px;
  background: var(--ds-surface, #fff);
  color: var(--ds-text, #111);
  border: 1px solid var(--ds-border, #ddd);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  z-index: 10000;
  font-size: 14px;
}

.backup-reminder__text {
  flex: 1;
}

.backup-reminder__btn,
.backup-reminder__dismiss {
  flex-shrink: 0;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--ds-border, #ddd);
  background: transparent;
  color: inherit;
}

.backup-reminder__btn {
  background: var(--ds-accent, #3b82f6);
  border-color: var(--ds-accent, #3b82f6);
  color: #fff;
  font-weight: 600;
}

/* In-app modal dialogs (confirm / alert) */
.ss-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10001;
  padding: 20px;
}

.ss-modal {
  width: 100%;
  max-width: 420px;
  padding: 20px 22px;
  background: var(--ds-surface, #fff);
  color: var(--ds-text, #111);
  border: 1px solid var(--ds-border, #ddd);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.ss-modal__title {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.ss-modal__message {
  margin: 0 0 18px;
  line-height: 1.5;
}

.ss-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ss-modal__btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid var(--ds-border, #ddd);
  background: transparent;
  color: inherit;
}

.ss-modal__btn--confirm {
  background: var(--ds-accent, #3b82f6);
  border-color: var(--ds-accent, #3b82f6);
  color: #fff;
  font-weight: 600;
}

.ss-modal__btn--danger {
  background: #ef4444;
  border-color: #ef4444;
}

/* CUL-296: Saves panel (reuses .ss-modal overlay/box) */
.ss-modal--saves {
  max-width: 480px;
}

.ss-saves__new {
  display: flex;
  gap: 10px;
  margin: 0 0 16px;
}

.ss-saves__new-label {
  flex: 1;
}

.ss-saves__input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--ds-border, #ddd);
  background: var(--ds-surface, #fff);
  color: inherit;
  font-size: 14px;
}

.ss-saves__save-btn {
  flex: 0 0 auto;
}

.ss-saves {
  list-style: none;
  margin: 0 0 18px;
  padding: 0;
  max-height: 320px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ss-saves__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ds-border, #ddd);
  border-radius: 8px;
}

.ss-saves__info {
  min-width: 0;
  flex: 1;
}

.ss-saves__name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ss-saves__meta {
  margin-top: 2px;
  font-size: 12px;
  opacity: 0.7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ss-saves__actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.ss-saves__empty {
  margin: 0 0 18px;
  opacity: 0.7;
}

/* CUL-299: authoring-time validation surfaces ------------------------------ */

/* Per-page warning badge in the Studio page list. */
.page-item__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  color: #1a1a1a;
  background: #f59e0b; /* warning amber */
}

.page-item__badge--error {
  color: #fff;
  background: #ef4444; /* danger red */
}

/* Header "Problems" indicator button (extends .action-btn from studio.css). */
.problems-indicator {
  font-weight: 600;
  white-space: nowrap;
}

.problems-indicator--ok {
  color: #22c55e;
}

.problems-indicator--has {
  color: #f59e0b;
}

.problems-indicator--error {
  color: #ef4444;
}

/* Problems panel (reuses .ss-modal overlay/box). */
.ss-modal--problems {
  max-width: 560px;
}

.ss-problems__body {
  margin: 4px 0 18px;
}

.ss-problems__empty {
  margin: 0;
  opacity: 0.7;
}

.ss-problems__list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 360px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ss-problems__row {
  border: 1px solid var(--ds-border, #ddd);
  border-left-width: 4px;
  border-radius: 8px;
}

.ss-problems__row--error {
  border-left-color: #ef4444;
}

.ss-problems__row--warning {
  border-left-color: #f59e0b;
}

.ss-problems__rowbtn {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ss-problems__rowbtn:hover,
.ss-problems__rowbtn:focus-visible {
  background: var(--ds-surface-raised, rgba(0, 0, 0, 0.04));
}

.ss-problems__sev {
  flex: 0 0 auto;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.ss-problems__row--error .ss-problems__sev {
  color: #ef4444;
}

.ss-problems__row--warning .ss-problems__sev {
  color: #f59e0b;
}

.ss-problems__msg {
  flex: 1 1 60%;
  min-width: 0;
}

.ss-problems__page {
  flex: 0 0 auto;
  font-size: 12px;
  opacity: 0.7;
  font-family: var(--ds-font-mono, ui-monospace, monospace);
}

/* In-app help panel */
.ss-help-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10001;
  padding: 20px;
}

.ss-help {
  width: 100%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--ds-surface, #fff);
  color: var(--ds-text, #111);
  border: 1px solid var(--ds-border, #ddd);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.ss-help__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--ds-border, #ddd);
}

.ss-help__head h2 {
  margin: 0;
  font-size: 1.15rem;
}

.ss-help__close {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}

.ss-help__body {
  padding: 8px 20px 20px;
  overflow-y: auto;
}

.ss-help__body h3 {
  margin: 16px 0 4px;
  font-size: 0.95rem;
}

.ss-help__body p {
  margin: 0;
  line-height: 1.5;
  color: var(--ds-text-muted, #555);
}

.ss-help__body code {
  background: var(--ds-bg, #f0f0f0);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

/* Visually hidden, but available to screen readers (e.g. ARIA live region) */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* CUL-291: typewriter reveal — blinking caret while a block is typing. */
.typewriter-typing::after {
  content: '';
  display: inline-block;
  width: 0.08em;
  height: 1em;
  margin-left: 0.04em;
  background: currentColor;
  vertical-align: text-bottom;
  animation: typewriter-caret 1s step-end infinite;
}
@keyframes typewriter-caret {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .typewriter-typing::after { animation: none; }
}

/* ==========================================================================
   CUL-292: Device-frame "chrome"
   Decorative, CSS-only device shells applied to a wrapper element. The same
   markup (an .ss-frame wrapper + an .ss-frame__screen child, or a container
   that carries the classes directly in the Studio preview) is used everywhere
   — player, Studio preview, and exports — so the chrome looks identical. All
   chrome is drawn with ::before/::after pseudo-elements; no bespoke DOM.
   ========================================================================== */
.ss-frame {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  background: var(--ds-surface, #fff);
  border: 1px solid var(--ds-border, #ccc);
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}

.ss-frame__screen {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

/* The Studio preview applies ss-frame directly to #preview-container, which
   holds the rendered content rather than an explicit screen child. Let it
   scroll its own content in that case. */
.ss-frame:not(:has(> .ss-frame__screen)) {
  overflow: auto;
}

/* --- Phone ------------------------------------------------------------- */
.ss-frame--phone {
  max-width: 390px;
  border-width: 10px;
  border-color: #111;
  border-radius: 40px;
}

/* Status bar / notch */
.ss-frame--phone::before {
  content: "9:41" / "";
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ds-text, #111);
  background: var(--ds-surface-raised, var(--ds-surface, #fff));
  border-bottom: 1px solid var(--ds-border, #ddd);
  position: relative;
}

/* Notch pill, centered over the status bar */
.ss-frame--phone::after {
  content: "";
  flex: 0 0 auto;
  align-self: center;
  width: 120px;
  height: 5px;
  margin: 8px 0;
  border-radius: 3px;
  background: var(--ds-text-muted, #888);
  opacity: 0.6;
}

/* --- Browser ----------------------------------------------------------- */
.ss-frame--browser {
  max-width: 900px;
  border-radius: 12px;
}

/* Browser top bar: traffic-light dots + an address bar showing the title. */
.ss-frame--browser::before {
  content: "● ● ●  " attr(data-frame-title) / "";
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 16px;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--ds-accent, #4a90d9);
  background: var(--ds-surface-raised, var(--ds-surface, #f3f3f3));
  border-bottom: 1px solid var(--ds-border, #ddd);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Responsive: collapse to full-bleed on narrow / touch viewports ----- */
@media (max-width: 600px) {
  .ss-frame,
  .ss-frame--phone,
  .ss-frame--browser {
    max-width: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .ss-frame::before,
  .ss-frame::after {
    display: none;
    content: none;
  }
}

/* ====================================================================== */
/* Story Map graph (CUL-298) — GraphView SVG canvas, nodes, edges          */
/* ---------------------------------------------------------------------- */
/* Design choice: the graph canvas is intentionally DARK in BOTH light and */
/* dark themes. A consistent dark backdrop maximises contrast for the      */
/* coloured node/edge accents (start blue, orphan amber, missing red) and  */
/* matches the Story Map mockup, which is always dark.                     */
/* ====================================================================== */

.ss-graph {
  display: block;
  width: 100%;
  height: 100%;
  background: #0d1117; /* fixed dark canvas (both themes) */
  touch-action: none; /* we own pan/zoom gestures */
  cursor: grab;
  user-select: none;
}
.ss-graph:active { cursor: grabbing; }

.ss-graph__grid-dot { fill: #21262d; }
.ss-graph__grid { pointer-events: none; }

/* --- Edges ------------------------------------------------------------- */
.ss-graph__edge {
  fill: none;
  stroke: #4b525c;
  stroke-width: 1.6;
}
.ss-graph__arrowhead { fill: #4b525c; }
.ss-graph__edge--choice,
.ss-graph__edge--selected {
  stroke: var(--studio-accent, #2563eb);
  stroke-width: 2.2;
}
.ss-graph__edge--missing {
  stroke: #ef4444;
  stroke-dasharray: 5 4;
}
.ss-graph__connector {
  stroke: var(--studio-accent, #2563eb);
}

.ss-graph__edge-pill {
  fill: #161b22;
  stroke: #30363d;
  stroke-width: 1;
}
.ss-graph__edge-label {
  fill: #c9d1d9;
  font-size: 11px;
  font-family: var(--ds-font-mono, ui-monospace, monospace);
  pointer-events: none;
}

/* --- Nodes ------------------------------------------------------------- */
.ss-graph__node { cursor: pointer; }
.ss-graph__card {
  fill: #161b22;
  stroke: #30363d;
  stroke-width: 1.5;
  transition: stroke 150ms, filter 150ms;
}
.ss-graph__node:hover .ss-graph__card { stroke: #6e7681; }

.ss-graph__glyph {
  fill: #8b949e;
  font-size: 15px;
  font-weight: 700;
}
.ss-graph__node-id {
  fill: #c9d1d9;
  font-size: 12px;
  font-family: var(--ds-font-mono, ui-monospace, monospace);
}
.ss-graph__node-title {
  fill: #e6edf3;
  font-size: 14px;
  font-weight: 600;
}
.ss-graph__node-count {
  fill: #8b949e;
  font-size: 11px;
}

/* Kind accents */
.ss-graph__node--start .ss-graph__card {
  stroke: var(--studio-accent, #2563eb);
  stroke-width: 2;
}
.ss-graph__node--start .ss-graph__glyph { fill: var(--studio-accent, #2563eb); }
.ss-graph__node--ending .ss-graph__card { fill: #1c1626; stroke: #6f42c1; }
.ss-graph__node--ending .ss-graph__glyph { fill: #d2a8ff; }

/* Status accents */
.ss-graph__node--orphan .ss-graph__card {
  stroke: #f59e0b; /* amber */
  stroke-dasharray: 6 4;
}
.ss-graph__node--orphan .ss-graph__node-count { fill: #f59e0b; }
.ss-graph__node--missing .ss-graph__card {
  fill: #2a1416;
  stroke: #ef4444; /* red */
  stroke-dasharray: 6 4;
}
.ss-graph__node--missing .ss-graph__node-id,
.ss-graph__node--missing .ss-graph__node-count { fill: #ff7b72; }

/* Selection — blue border + glow (drawn last so it wins) */
.ss-graph__node--selected .ss-graph__card {
  stroke: var(--studio-accent, #2563eb);
  stroke-width: 2.5;
  filter: drop-shadow(0 0 6px rgba(37, 99, 235, 0.7));
}

/* --- Floating overlays: legend (bottom-left), zoom (bottom-right) ------ */
.ss-graph__legend,
.ss-graph__zoom {
  position: absolute;
  bottom: 16px;
  z-index: 5;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  color: #c9d1d9;
}
.ss-graph__legend { left: 16px; display: flex; flex-direction: column; gap: 6px; }
.ss-graph__legend-row { display: flex; align-items: center; gap: 8px; }
.ss-graph__legend-swatch {
  width: 14px; height: 14px; border-radius: 4px; flex: 0 0 auto;
  border: 1.5px solid #30363d; background: #161b22;
}
.ss-graph__legend-swatch--start { border-color: var(--studio-accent, #2563eb); }
.ss-graph__legend-swatch--selected {
  border-color: var(--studio-accent, #2563eb);
  box-shadow: 0 0 5px rgba(37, 99, 235, 0.7);
}
.ss-graph__legend-swatch--orphan { border-color: #f59e0b; border-style: dashed; }
.ss-graph__legend-swatch--choice { border-color: var(--studio-accent, #2563eb); background: var(--studio-accent, #2563eb); }

.ss-graph__zoom { right: 16px; display: flex; flex-direction: column; gap: 4px; padding: 6px; }
.ss-graph__zoom-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; line-height: 1;
  color: #c9d1d9;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  cursor: pointer;
  transition: background 150ms;
}
.ss-graph__zoom-btn:hover { background: #30363d; }
.ss-graph__zoom-btn:focus-visible { outline: 2px solid var(--studio-accent, #2563eb); }

/* ---------------------------------------------------------------------- */
/* Story Map selection inspector (CUL-298, Task 4)                         */
/* Floating top-right panel: header, leads-to, backlinks, problem status.  */
/* Uses --ds-* tokens so it adapts to light/dark theme over the dark canvas.*/
/* ---------------------------------------------------------------------- */
.ss-graph__inspector {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 6;
  width: 280px;
  max-height: calc(100% - 32px);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--ds-surface-raised, var(--ds-surface, #161b22));
  color: var(--ds-text, #e6edf3);
  border: 1px solid var(--ds-border, #30363d);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 13px;
}
.ss-graph__inspector[hidden] { display: none; }

/* CUL-327: on mobile the graph inspector becomes a bottom sheet (full width,
   pinned to the bottom) instead of a top-right side panel. */
@media (max-width: 860px) {
  .ss-graph__inspector {
    top: auto;
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: 45vh;
    border-radius: 12px 12px 0 0;
  }
}

.ss-graph__insp-header { display: flex; align-items: center; gap: 10px; }
.ss-graph__insp-icon {
  width: 30px; height: 30px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  border-radius: 8px;
  background: var(--ds-surface, #21262d);
  border: 1px solid var(--ds-border, #30363d);
  color: var(--ds-text-muted, #8b949e);
}
.ss-graph__insp-icon--start { color: var(--studio-accent, #2563eb); border-color: var(--studio-accent, #2563eb); }
.ss-graph__insp-icon--ending { color: #d2a8ff; border-color: #6f42c1; }
.ss-graph__insp-titles { min-width: 0; }
.ss-graph__insp-id {
  font-family: var(--ds-font-mono, ui-monospace, monospace);
  font-size: 12px;
  color: var(--ds-text-muted, #8b949e);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ss-graph__insp-title { font-size: 14px; font-weight: 600; }

.ss-graph__insp-section { display: flex; flex-direction: column; gap: 5px; }
.ss-graph__insp-heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ds-text-muted, #8b949e);
}
.ss-graph__insp-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  background: var(--ds-surface, rgba(255, 255, 255, 0.03));
}
.ss-graph__insp-target {
  font-family: var(--ds-font-mono, ui-monospace, monospace);
  font-size: 12px;
}
.ss-graph__insp-label { color: var(--ds-text-muted, #8b949e); font-size: 12px; }
.ss-graph__insp-row--missing .ss-graph__insp-target { color: #ff7b72; }
.ss-graph__insp-empty { font-size: 12px; color: var(--ds-text-muted, #8b949e); font-style: italic; }

.ss-graph__insp-ok {
  font-size: 12px;
  color: #3fb950; /* green ok-state */
  font-weight: 500;
}
.ss-graph__insp-problem {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 12px;
  background: var(--ds-surface, rgba(255, 255, 255, 0.03));
}
.ss-graph__insp-sev {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 5px;
  border-radius: 4px;
}
.ss-graph__insp-problem--error .ss-graph__insp-sev { background: #ef4444; color: #fff; }
.ss-graph__insp-problem--warning .ss-graph__insp-sev { background: #f59e0b; color: #1a1a1a; }
.ss-graph__insp-msg { color: var(--ds-text, #e6edf3); }

/* ---------------------------------------------------------------------- */
/* Studio integration (CUL-298, Task 5)                                   */
/* Header Editor/Map segmented toggle, live stat strip, full-canvas graph */
/* container that fills the workspace where .studio-main normally sits.    */
/* ---------------------------------------------------------------------- */

/* Header stat strip — muted, sits between the toggle and other actions. */
.studio-stats {
  font-size: 12px;
  color: var(--studio-text-muted, #8b949e);
  white-space: nowrap;
}

/* Segmented Editor/Map toggle. */
.studio-viewtoggle {
  display: inline-flex;
  border: 1px solid var(--studio-border, #30363d);
  border-radius: 6px;
  overflow: hidden;
}
.studio-viewtoggle__btn {
  font: inherit;
  font-size: 12px;
  line-height: 1;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--studio-text-muted, #8b949e);
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.studio-viewtoggle__btn + .studio-viewtoggle__btn {
  border-left: 1px solid var(--studio-border, #30363d);
}
.studio-viewtoggle__btn:hover { color: var(--studio-text, #e6edf3); }
.studio-viewtoggle__btn.is-active {
  background: var(--studio-accent-strong, #2563eb);
  color: #fff;
}
.studio-viewtoggle__btn:focus-visible {
  outline: 2px solid var(--studio-accent, #2563eb);
  outline-offset: -2px;
}

/* Full-canvas Story Map container — fills the workspace region (sibling of
   .studio-main inside the column-flex .simplestory-studio). */
.studio-graph {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background: #0d1117;
}

/* CUL-295: inventory/stats HUD (player layer — --ds-* only). */
.ss-hud-toggle {
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  touch-action: manipulation;
}
/* Floating variant for the studio preview pane (no nav bar there). */
.ss-hud-toggle--floating {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 30;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--ds-nav-border, var(--ds-border));
  background: var(--ds-nav-bg, var(--ds-surface));
  color: var(--ds-text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}
.ss-hud-panel {
  position: absolute;
  top: 56px;
  right: 12px;
  z-index: 31;
  min-width: 200px;
  max-width: min(280px, 80vw);
  max-height: 60vh;
  overflow: auto;
  padding: 12px 14px;
  background: var(--ds-surface-raised, var(--ds-surface));
  color: var(--ds-text);
  border: 1px solid var(--ds-border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}
.ss-hud-panel[hidden] { display: none; }
.ss-hud-list { list-style: none; margin: 0; padding: 0; }
.ss-hud-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--ds-border);
}
.ss-hud-row:last-child { border-bottom: 0; }
.ss-hud-row.is-empty { color: var(--ds-text-muted); }
.ss-hud-row--item { font-family: var(--ds-font-mono, inherit); }

/* Locked (condition-gated, shown-disabled) choices. */
.choice-button--locked {
  opacity: 0.55;
  cursor: not-allowed;
}
.choice-locked-hint {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  color: var(--ds-text-muted);
}
