:root {
  --ink: #171a1e;
  --muted: #697077;
  --paper: #fffaf1;
  --veil: rgba(255, 250, 241, 0.84);
  --line: rgba(23, 26, 30, 0.13);
  --red: #b8494d;
  --teal: #1f7a76;
  --blue: #366c9f;
  --gold: #d29a35;
  --moss: #627a43;
  --plum: #76528f;
  --shadow: 0 26px 80px rgba(22, 19, 17, 0.2);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: #efe9dd;
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

canvas {
  display: block;
}

.app-shell {
  position: relative;
  display: grid;
  width: 100%;
  height: 100vh;
  grid-template-columns: minmax(270px, 330px) minmax(430px, 1fr) minmax(280px, 350px);
  grid-template-rows: 72px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  overflow: hidden;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 18% 18%, rgba(184, 73, 77, 0.18), transparent 25%),
    radial-gradient(circle at 80% 20%, rgba(31, 122, 118, 0.22), transparent 28%),
    linear-gradient(135deg, #f3eadb 0%, #e7e5dc 42%, #e2d8c8 100%);
}

.topbar,
.left-panel,
.stage-panel,
.right-panel {
  position: relative;
  z-index: 2;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(230px, 330px) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand,
.mode-tabs,
.top-actions,
.left-panel,
.stage-panel,
.card,
.ritual-card,
.prompt-card {
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 8px;
  background: var(--veil);
  box-shadow: 0 18px 55px rgba(35, 24, 18, 0.13);
  backdrop-filter: blur(18px);
}

.brand {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 8px 12px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--red);
  color: white;
  font-size: 1.45rem;
  font-weight: 950;
}

.brand strong,
.brand small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand small {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.mode-tabs {
  display: flex;
  min-width: 0;
  gap: 6px;
  padding: 8px;
  overflow-x: auto;
}

.mode-tab,
.icon-btn,
.primary,
.secondary,
.section-title button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 900;
  transition:
    transform 160ms ease,
    background 160ms ease,
    color 160ms ease;
}

.mode-tab {
  flex: 0 0 auto;
  padding: 0 13px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--ink);
}

.mode-tab.is-active {
  background: var(--ink);
  color: white;
}

.top-actions {
  display: flex;
  gap: 8px;
  padding: 8px;
}

.icon-btn {
  display: grid;
  width: 42px;
  place-items: center;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
}

.icon-btn.danger {
  color: var(--red);
}

button:hover {
  transform: translateY(-1px);
}

.left-panel,
.stage-panel,
.right-panel {
  min-height: 0;
  overflow: auto;
}

.left-panel,
.right-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.left-panel {
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
}

.guide,
.ritual-card,
.prompt-card,
.stage-panel,
.card {
  padding: 16px;
}

.guide {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 13px;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 8px;
  background: rgba(255, 250, 241, 0.9);
  box-shadow: var(--shadow);
}

.guide-mask {
  position: relative;
  width: 68px;
  height: 86px;
  border-radius: 34px 34px 30px 30px;
  background:
    radial-gradient(circle at 35% 34%, #171a1e 0 4px, transparent 5px),
    radial-gradient(circle at 65% 34%, #171a1e 0 4px, transparent 5px),
    linear-gradient(160deg, #f9efe0, #d6b07b);
  box-shadow: inset 0 -18px 0 rgba(184, 73, 77, 0.14), 0 18px 34px rgba(23, 26, 30, 0.18);
}

.guide-mask span {
  position: absolute;
  left: 22px;
  bottom: 22px;
  width: 24px;
  height: 7px;
  border-bottom: 3px solid #171a1e;
  border-radius: 50%;
}

.kicker,
.section-title span {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 0.74rem;
  font-weight: 950;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(1.7rem, 3vw, 2.35rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: clamp(1.25rem, 2vw, 1.75rem);
  line-height: 1.08;
  letter-spacing: 0;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.microcopy {
  margin-bottom: 0;
  font-size: 0.9rem;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.section-title strong {
  color: var(--ink);
  font-size: 0.86rem;
}

.section-title button {
  min-height: 34px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
}

.arc-track {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.arc-step {
  min-height: 72px;
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.62);
  outline: 1px solid var(--line);
}

.arc-step strong,
.arc-step span {
  display: block;
}

.arc-step span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.8rem;
}

.arc-step.is-active {
  background: rgba(184, 73, 77, 0.13);
  outline-color: rgba(184, 73, 77, 0.34);
}

.chips,
.tool-row,
.role-cast,
.cast-list,
.entries {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip,
.role-pill,
.entry {
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
  outline: 1px solid var(--line);
}

.stage-panel {
  display: grid;
  grid-template-rows: auto minmax(270px, 1fr) auto auto;
  gap: 14px;
  min-width: 0;
}

.stage-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.scoreboard {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.scoreboard span {
  display: grid;
  min-width: 72px;
  min-height: 50px;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.scoreboard strong {
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
}

.theatre {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(190px, 1fr) auto;
  gap: 12px;
  min-height: 330px;
  overflow: hidden;
  border-radius: 8px;
  padding: 14px;
  background:
    linear-gradient(90deg, rgba(184, 73, 77, 0.24), transparent 17% 83%, rgba(184, 73, 77, 0.24)),
    radial-gradient(ellipse at 50% 18%, rgba(255, 255, 255, 0.86), transparent 46%),
    linear-gradient(180deg, #2b2020 0%, #59403b 58%, #2d221f 100%);
  color: white;
  box-shadow: inset 0 -36px 0 rgba(0, 0, 0, 0.14);
}

.role-cast {
  position: relative;
  z-index: 2;
}

.role-pill {
  background: rgba(255, 250, 241, 0.2);
  color: white;
  outline-color: rgba(255, 255, 255, 0.24);
}

.spotlight {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 92px 1fr;
  align-items: end;
  min-height: 190px;
}

.spotlight::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -30px;
  width: 58%;
  height: 120%;
  transform: translateX(-50%);
  clip-path: polygon(44% 0, 56% 0, 100% 100%, 0 100%);
  background: rgba(255, 229, 174, 0.18);
  pointer-events: none;
}

.puppet {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: end;
  min-height: 180px;
  transition:
    transform 240ms ease,
    filter 240ms ease;
}

.puppet.active {
  transform: translateY(-8px) scale(1.04);
  filter: drop-shadow(0 0 20px rgba(255, 219, 139, 0.42));
}

.head {
  display: block;
  width: 58px;
  height: 58px;
  border-radius: 50% 50% 46% 46%;
  background:
    radial-gradient(circle at 34% 38%, #171a1e 0 4px, transparent 5px),
    radial-gradient(circle at 64% 38%, #171a1e 0 4px, transparent 5px),
    linear-gradient(150deg, #f5c990, #c8795c);
}

.body {
  display: block;
  width: 82px;
  height: 100px;
  border-radius: 34px 34px 8px 8px;
  background: linear-gradient(150deg, var(--teal), var(--blue));
  box-shadow: inset 0 -18px 0 rgba(255, 255, 255, 0.13);
}

#puppet-b .body {
  background: linear-gradient(150deg, var(--plum), var(--red));
}

.empty-chair {
  position: relative;
  width: 78px;
  height: 120px;
  justify-self: center;
  border: 9px solid rgba(255, 250, 241, 0.84);
  border-bottom: 0;
  border-radius: 22px 22px 4px 4px;
}

.empty-chair::before,
.empty-chair::after {
  content: "";
  position: absolute;
  bottom: -54px;
  width: 9px;
  height: 58px;
  background: rgba(255, 250, 241, 0.84);
}

.empty-chair::before {
  left: 8px;
}

.empty-chair::after {
  right: 8px;
}

.cue-board {
  min-height: 76px;
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 250, 241, 0.14);
  color: white;
  line-height: 1.48;
  outline: 1px solid rgba(255, 255, 255, 0.22);
}

.technique {
  min-height: 52px;
  border-radius: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.66);
  color: var(--ink);
  text-align: left;
  outline: 1px solid var(--line);
}

.technique strong,
.technique span {
  display: block;
}

.technique span {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.technique.is-active {
  background: rgba(31, 122, 118, 0.14);
  outline-color: rgba(31, 122, 118, 0.34);
}

.script-box {
  display: grid;
  gap: 10px;
}

.script-box label,
.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

textarea,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  outline: 0;
}

textarea {
  min-height: 104px;
  resize: none;
  padding: 12px;
  line-height: 1.5;
}

input {
  min-height: 42px;
  padding: 0 11px;
}

textarea:focus,
input:focus {
  border-color: rgba(31, 122, 118, 0.54);
  box-shadow: 0 0 0 4px rgba(31, 122, 118, 0.1);
}

.script-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary,
.secondary {
  display: inline-grid;
  place-items: center;
  min-height: 42px;
  padding: 0 15px;
}

.primary {
  background: var(--red);
  color: white;
}

.secondary {
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  outline: 1px solid var(--line);
}

.wide {
  width: 100%;
}

.card {
  display: grid;
  gap: 12px;
}

.card.compact {
  gap: 8px;
}

.cast-list {
  display: grid;
}

.cast-token {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 48px;
  border-radius: 8px;
  padding: 7px;
  background: rgba(255, 255, 255, 0.62);
}

.cast-token span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 50%;
  background: var(--token);
  color: white;
  font-weight: 950;
}

.cast-token strong,
.cast-token small {
  display: block;
}

.cast-token small {
  color: var(--muted);
  font-weight: 760;
}

.entry {
  width: 100%;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  line-height: 1.35;
}

.modal {
  width: min(560px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  padding: 22px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(23, 26, 30, 0.45);
  backdrop-filter: blur(4px);
}

.close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: rgba(23, 26, 30, 0.08);
  color: var(--ink);
  font-size: 1.3rem;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 290px minmax(420px, 1fr);
  }

  .right-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, minmax(220px, 1fr));
    overflow-x: auto;
  }
}

@media (max-width: 820px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    overflow: visible;
  }

  .topbar {
    grid-template-columns: 1fr auto;
  }

  .mode-tabs {
    grid-column: 1 / -1;
    order: 3;
  }

  .left-panel,
  .stage-panel,
  .right-panel {
    overflow: visible;
  }

  .right-panel {
    grid-column: auto;
    grid-template-columns: 1fr;
  }

  .stage-head {
    display: grid;
  }

  .scoreboard {
    justify-content: start;
  }
}

@media (max-width: 540px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .brand {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .brand-mark,
  .icon-btn {
    width: 42px;
  }

  .guide {
    grid-template-columns: 1fr;
  }

  .arc-track,
  .spotlight {
    grid-template-columns: 1fr;
  }

  .empty-chair {
    display: none;
  }

  .theatre {
    min-height: 520px;
  }
}
