:root {
  --bg: #f5f2eb;
  --surface: rgba(255,255,255,0.72);
  --surface-solid: #fffaf0;
  --surface-strong: #ffffff;
  --ink: #11100d;
  --muted: #746d62;
  --soft: #d8d0c2;
  --line: rgba(17,16,13,0.12);
  --line-strong: rgba(17,16,13,0.2);
  --accent: #f26a1b;
  --accent-deep: #b94713;
  --accent-soft: rgba(242,106,27,0.12);
  --danger: #b2402c;
  --paper: #fffdf7;
  --paper-ink: #111111;
  --shadow: 0 24px 70px rgba(48,38,25,0.16);
  --radius: 24px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, Helvetica, sans-serif;
}

body.vision-theme { overflow-x: hidden; }

button,
input,
select,
textarea { font: inherit; }

button { cursor: pointer; }

.vision-app {
  min-height: 100dvh;
  width: 100%;
  background:
    radial-gradient(circle at 18% 0%, rgba(242,106,27,0.16), transparent 34rem),
    radial-gradient(circle at 92% 8%, rgba(0,0,0,0.07), transparent 28rem),
    linear-gradient(180deg, #fbf6eb 0%, #efe6d7 100%);
  padding-bottom: 42px;
}

.vision-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 max(20px, env(safe-area-inset-left)) 0 max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(17,16,13,0.08);
  background: rgba(245,242,235,0.78);
  backdrop-filter: blur(22px) saturate(140%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid rgba(17,16,13,0.08);
  box-shadow: 0 14px 38px rgba(48,38,25,0.1);
}

.brand-eye {
  width: 28px;
  height: 28px;
  object-fit: contain;
}

.brand-copy {
  display: grid;
  gap: 4px;
}

.brand-word {
  width: 126px;
  height: auto;
  display: block;
}

.brand-copy span {
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.top-actions,
.format-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-actions { justify-content: flex-end; }

button,
select,
.tool-like {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.55);
  color: var(--ink);
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover,
select:hover {
  border-color: rgba(242,106,27,0.38);
  background: #ffffff;
}

button:active { transform: scale(0.985); }

button.primary {
  border-color: var(--accent);
  background: var(--ink);
  color: #fffaf0;
}

button.primary:hover { background: #000000; }

button.ghost { color: var(--ink); }

button.danger { color: var(--danger); }

.icon-button {
  min-width: 44px;
  padding: 0 12px;
}

.icon-only {
  min-width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
}

.format-bar {
  position: sticky;
  top: 72px;
  z-index: 45;
  justify-content: center;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(17,16,13,0.08);
  background: rgba(245,242,235,0.7);
  backdrop-filter: blur(18px) saturate(140%);
}

#elementType {
  min-width: 210px;
  height: 40px;
  border-color: rgba(17,16,13,0.16);
  outline: none;
}

.app-shell {
  max-width: 1420px;
  margin: 0 auto;
  padding: 26px 24px 70px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 348px;
  gap: 24px;
  align-items: start;
}

.app-shell.panel-closed {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1040px;
}

.editor-column {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.project-strip {
  width: min(8.5in, 100%);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 0 auto 14px;
  padding: 0 4px;
}

#projectTitle {
  min-width: 0;
  flex: 1;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  outline: none;
  padding: 8px 0;
  font-size: 21px;
  font-weight: 760;
  letter-spacing: -0.03em;
}

#projectTitle:focus { border-bottom-color: rgba(242,106,27,0.45); }

#stats {
  color: var(--muted);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.script-page {
  position: relative;
  width: 8.5in;
  min-height: 11in;
  margin: 0 auto;
  padding: 1in 1in 1.2in 1.5in;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 2px;
  box-shadow: var(--shadow);
  font: 12pt/1.2 "Courier New", Courier, monospace;
}

.page-mark {
  position: absolute;
  top: 22px;
  right: 24px;
  color: rgba(0,0,0,0.17);
  font: 8px Arial, Helvetica, sans-serif;
  letter-spacing: 0.18em;
}

.script-page:after {
  content: "Created with VISION by Effigy Entertainment · visionscreenwriting.com";
  position: absolute;
  right: 0.55in;
  bottom: 0.36in;
  color: rgba(0,0,0,0.20);
  font: 8px Arial, Helvetica, sans-serif;
  letter-spacing: 0.08em;
  pointer-events: none;
}

#editor {
  min-height: 8.8in;
}

#editor:empty:before {
  content: "Choose an element type and start writing.";
  color: rgba(0,0,0,0.28);
  font: 13px Arial, Helvetica, sans-serif;
}

.element {
  position: relative;
  min-height: 1.2em;
  margin-top: 1em;
}

.element:first-child { margin-top: 0; }

.element-label {
  position: absolute;
  right: calc(100% + 15px);
  top: 2px;
  color: transparent;
  font: 8px Arial, Helvetica, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
}

.element.selected {
  background: rgba(242,106,27,0.12);
}

.element.selected .element-label { color: rgba(0,0,0,0.36); }

.line {
  min-height: 1.2em;
  outline: 0;
  white-space: pre-wrap;
}

.line:empty:before {
  content: attr(data-placeholder);
  color: rgba(0,0,0,0.22);
}

.element.scene {
  font-weight: bold;
  text-transform: uppercase;
}

.element.action { margin-top: 1em; }

.element.character {
  width: 2.35in;
  margin-left: 2.45in;
  margin-top: 0.85em;
  text-transform: uppercase;
}

.element.dialogue {
  width: 3.7in;
  margin-left: 1in;
  margin-top: 0;
}

.element.character + .element.dialogue,
.element.parenthetical + .element.dialogue { margin-top: 0; }

.element.parenthetical {
  width: 2.7in;
  margin-left: 1.55in;
  margin-top: 0;
}

.element.transition {
  text-align: right;
  text-transform: uppercase;
}

.element.shot {
  font-weight: bold;
  text-transform: uppercase;
}

.element.note {
  color: #7b541f;
  font-style: italic;
  padding-left: 10px;
  border-left: 3px solid rgba(242,106,27,0.32);
}

.inspector {
  position: sticky;
  top: 136px;
  max-height: calc(100dvh - 160px);
  overflow: auto;
  border: 1px solid rgba(17,16,13,0.1);
  border-radius: var(--radius);
  background: rgba(255,250,240,0.66);
  backdrop-filter: blur(24px) saturate(150%);
  box-shadow: 0 22px 64px rgba(48,38,25,0.13);
  padding: 14px;
}

.inspector.closed {
  display: none;
}

.inspector-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 4px 12px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-deep);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 800;
}

.inspector h2 {
  margin: 4px 0 0;
  font-size: 26px;
  letter-spacing: -0.05em;
}

.panel-group {
  border-top: 1px solid rgba(17,16,13,0.09);
}

.panel-trigger {
  width: 100%;
  min-height: auto;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  text-align: left;
  padding: 14px 4px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
}

.panel-trigger span {
  font-size: 15px;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.panel-trigger small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.panel-trigger:after {
  content: "+";
  grid-column: 2;
  grid-row: 1 / span 2;
  align-self: center;
  color: var(--muted);
  font-size: 20px;
  font-weight: 300;
}

.panel-group.open .panel-trigger:after { content: "–"; }

.panel-content {
  display: none;
  padding: 0 4px 16px;
}

.panel-group.open .panel-content { display: block; }

.inspector label,
.app-dialog label {
  display: block;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 780;
}

.inspector input,
.inspector textarea,
.app-dialog input,
.app-dialog textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid rgba(17,16,13,0.1);
  border-radius: 13px;
  background: rgba(255,255,255,0.62);
  color: var(--ink);
  outline: 0;
  padding: 11px 12px;
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
}

.inspector textarea,
.app-dialog textarea { resize: vertical; }

.inspector input:focus,
.inspector textarea:focus,
.app-dialog input:focus,
.app-dialog textarea:focus {
  border-color: rgba(242,106,27,0.42);
  background: #ffffff;
}

button.full { width: 100%; }

.item-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.item-card {
  border: 1px solid rgba(17,16,13,0.09);
  border-radius: 16px;
  background: rgba(255,255,255,0.52);
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.item-card strong {
  display: block;
  color: var(--ink);
  margin-bottom: 4px;
  font-size: 14px;
}

.item-card button {
  min-height: 30px;
  padding: 0 10px;
  margin-top: 9px;
  font-size: 12px;
}

.scene-link {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: start;
  text-align: left;
  border: 1px solid rgba(17,16,13,0.08);
  background: rgba(255,255,255,0.48);
  border-radius: 16px;
  padding: 11px;
  color: var(--ink);
}

.scene-link b { color: var(--accent-deep); }
.scene-link span { color: var(--muted); font-size: 12px; }

.status-bar {
  position: fixed;
  z-index: 60;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 max(16px, env(safe-area-inset-left));
  border-top: 1px solid rgba(17,16,13,0.08);
  background: rgba(245,242,235,0.82);
  backdrop-filter: blur(20px) saturate(140%);
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(242,106,27,0.12);
}

.status-help { margin-left: auto; }

.app-dialog {
  width: min(560px, calc(100vw - 28px));
  border: 1px solid rgba(17,16,13,0.1);
  border-radius: 28px;
  background: rgba(255,250,240,0.94);
  color: var(--ink);
  box-shadow: 0 34px 100px rgba(48,38,25,0.28);
  padding: 28px;
  backdrop-filter: blur(18px) saturate(150%);
}

.app-dialog::backdrop {
  background: rgba(31,25,18,0.35);
  backdrop-filter: blur(7px);
}

.dialog-close {
  position: absolute;
  top: 14px;
  right: 14px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  font-size: 22px;
  border: 0;
  background: rgba(17,16,13,0.06);
}

.app-dialog h2 {
  margin: 4px 0 8px;
  font-size: 32px;
  letter-spacing: -0.06em;
}

.dialog-copy {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.dialog-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.dialog-grid button {
  min-height: 92px;
  display: block;
  text-align: left;
  border-radius: 18px;
  padding: 15px;
  background: rgba(255,255,255,0.58);
}

.dialog-grid b {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
}

.dialog-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  z-index: 100;
  transform: translate(-50%, 18px);
  border: 1px solid rgba(17,16,13,0.1);
  border-radius: 999px;
  background: rgba(17,16,13,0.88);
  color: #fffaf0;
  padding: 10px 14px;
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1160px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 324px;
    gap: 16px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .script-page { width: min(8.5in, 100%); }
}

@media (max-width: 960px) {
  .vision-header {
    height: 64px;
    padding: 0 13px;
  }

  .brand-mark { width: 38px; height: 38px; border-radius: 13px; }
  .brand-eye { width: 25px; height: 25px; }
  .brand-word { width: 104px; }
  .brand-copy span { display: none; }

  .optional-sm { display: none; }

  .format-bar {
    top: 64px;
    justify-content: stretch;
    padding: 8px;
  }

  #elementType { flex: 1; min-width: 0; }

  .app-shell {
    display: block;
    padding: 16px 0 62px;
  }

  .editor-column { width: 100%; }

  .project-strip {
    width: 100%;
    padding: 0 14px;
  }

  #projectTitle { font-size: 17px; }
  #stats { font-size: 11px; }

  .script-page {
    width: 100%;
    min-height: calc(100dvh - 180px);
    padding: 42px clamp(16px, 5vw, 28px) 80px;
    box-shadow: none;
    border-radius: 0;
    font-size: clamp(13px, 3.8vw, 16px);
    line-height: 1.34;
  }

  .page-mark { top: 15px; right: 16px; }

  .element {
    padding-left: 7px;
    border-left: 2px solid transparent;
  }

  .element.selected { border-left-color: var(--accent); }

  .element-label,
  .element.selected .element-label {
    position: static;
    display: block;
    margin-bottom: 4px;
    color: rgba(0,0,0,0.32);
    font-size: 7px;
  }

  .element.character { width: auto; margin-left: 36%; }
  .element.dialogue { width: auto; margin-left: 10%; margin-right: 5%; }
  .element.parenthetical { width: auto; margin-left: 20%; margin-right: 8%; }
  .element.transition { margin-left: 25%; }

  .inspector {
    position: fixed;
    z-index: 90;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(390px, 92vw);
    max-height: none;
    border-radius: 28px 0 0 28px;
    transform: translateX(105%);
    transition: transform 220ms ease;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .inspector.open { transform: translateX(0); }

  .status-help { display: none; }
}

@media (max-width: 520px) {
  .top-actions { gap: 6px; }
  button, select { font-size: 12px; padding-left: 11px; padding-right: 11px; }
  .ghost[data-action="apply-type"] { display: none; }
  .dialog-grid { grid-template-columns: 1fr; }
  .app-dialog { padding: 24px 20px; }
}

@media (max-width: 370px) {
  .brand-word { width: 88px; }
  .script-page { padding-left: 13px; padding-right: 13px; }
  .element.dialogue { margin-left: 7%; margin-right: 2%; }
  .element.parenthetical { margin-left: 14%; margin-right: 3%; }
}

@media print {
  @page { size: letter; margin: 0; }

  html,
  body,
  .vision-app { background: white !important; }

  .vision-header,
  .format-bar,
  .project-strip,
  .inspector,
  .status-bar,
  .page-mark,
  .toast { display: none !important; }

  .app-shell,
  .editor-column {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    max-width: none !important;
    width: auto !important;
  }

  .script-page {
    width: 8.5in !important;
    min-height: 11in !important;
    box-shadow: none !important;
    margin: 0 !important;
    border-radius: 0 !important;
    padding: 1in 1in 1.2in 1.5in !important;
  }

  .element.selected { background: transparent !important; }
  .element-label { display: none !important; }
  .element.note { display: none !important; }
}
