:root {
  --bg: #11161c;
  --panel: rgba(25, 31, 41, 0.92);
  --panel-2: rgba(19, 24, 32, 0.96);
  --editor: #0f141b;
  --line: rgba(210, 225, 244, 0.08);
  --line-strong: rgba(210, 225, 244, 0.16);
  --text: #edf4ff;
  --muted: #93a0b3;
  --accent: #56c0c6;
  --accent-2: #7de1ad;
  --accent-3: #f0b55a;
  --danger: #ee8e7d;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --transition: 180ms ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--text);
  background: #e7d9bd;
  overflow: hidden;
}

body::before {
  display: none;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: calc(100% - 28px);
  height: calc(100vh - 28px);
  height: calc(100dvh - 28px);
  margin: 14px auto;
  padding: 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background: rgba(11, 15, 21, 0.72);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar,
.bottom-bar,
.story-card,
.editor-window,
.story-modal-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.topbar {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.brand-block {
  display: flex;
  align-items: center;
  min-width: 0;
}

.scene-label,
.story-label,
.role-button-tag {
  margin: 0;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.05;
}

h1 {
  font-size: clamp(1.35rem, 2vw, 1.8rem);
}

h2 {
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
}

h3 {
  font-size: 1.1rem;
}

.topbar-center {
  min-width: 0;
  display: grid;
  gap: 10px;
  justify-items: center;
}

.scene-switcher,
.level-tabs {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.scene-switcher {
  align-items: center;
}

.scene-switch-button {
  min-height: 40px;
  padding: 8px 14px;
}

.current-scenario-pill {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: min(300px, 54vw);
  padding: 10px 16px;
  border-radius: 16px;
  border: 1px solid rgba(240, 181, 90, 0.22);
  background: rgba(255, 255, 255, 0.04);
}

.current-scenario-pill.complete {
  border-color: rgba(125, 225, 173, 0.24);
  background: rgba(125, 225, 173, 0.1);
}

.current-scenario-name {
  font-size: 0.98rem;
  line-height: 1.1;
}

.level-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  transition: border-color var(--transition), background var(--transition);
}

.level-tab.current {
  background: rgba(86, 192, 198, 0.14);
  border-color: rgba(86, 192, 198, 0.24);
}

.level-tab.complete {
  background: rgba(125, 225, 173, 0.12);
  border-color: rgba(125, 225, 173, 0.2);
}

.level-tab.skipped {
  background: rgba(240, 181, 90, 0.12);
  border-color: rgba(240, 181, 90, 0.2);
}

.level-tab.locked {
  color: var(--muted);
}

.level-tab-number {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.76rem;
}

.topbar-actions,
.bottom-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

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

.help-wrap {
  position: relative;
}

.help-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(320px, 76vw);
  padding: 12px 14px;
  border: 1px solid rgba(86, 192, 198, 0.2);
  border-radius: 16px;
  background: var(--panel-2);
  box-shadow: var(--shadow);
  z-index: 5;
}

.help-text,
.story-copy {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
}

.help-text {
  margin-bottom: 10px;
}

.button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  transition: border-color var(--transition), background var(--transition);
}

.button:hover,
.button:focus-visible,
.level-tab:hover,
.level-tab:focus-visible,
.token-button:hover,
.token-button:focus-visible,
.role-button:hover,
.role-button:focus-visible {
  border-color: rgba(86, 192, 198, 0.22);
}

.button-primary {
  color: #091116;
  background: linear-gradient(135deg, var(--accent), #6fdadf);
  font-weight: 700;
}

.button-secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--line);
}

.button-ghost {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(290px, 340px) minmax(0, 1fr);
  gap: 12px;
}

.story-rail {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.story-card {
  padding: 16px;
  overflow: auto;
}

.story-card-tall {
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr);
  gap: 12px;
}

.story-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(86, 192, 198, 0.12);
  border: 1px solid rgba(86, 192, 198, 0.16);
}

.role-heading {
  display: grid;
  gap: 8px;
}

.role-badge {
  width: fit-content;
}

.role-title {
  font-size: 1.15rem;
}

.role-buttons {
  display: grid;
  gap: 10px;
}

.role-button {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  text-align: left;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}

.role-button.active {
  background: rgba(86, 192, 198, 0.14);
  border-color: rgba(86, 192, 198, 0.24);
}

.role-button-title {
  font-weight: 700;
  font-size: 1rem;
}

.role-button-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.function-preview,
.challenge-preview {
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: #dce9f8;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
}

.syntax-code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code-name {
  color: #5ae8ff;
}

.code-keyword {
  color: #7de1ad;
  font-weight: 700;
}

.code-paren,
.code-punct {
  color: #ffd56a;
}

.code-arg-1 {
  color: #ff8f70;
}

.code-arg-2 {
  color: #8df089;
}

.code-arg-3 {
  color: #ff9ee8;
}

.code-arg-4 {
  color: #9db7ff;
}

.code-indent {
  color: rgba(255, 255, 255, 0.28);
}

.challenge-card {
  padding: 14px;
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(125, 225, 173, 0.14), rgba(86, 192, 198, 0.12));
  border: 1px solid rgba(125, 225, 173, 0.18);
  display: grid;
  gap: 10px;
  animation: glowCard 2.8s ease-in-out infinite;
}

.challenge-code {
  font-size: 1.35rem;
  letter-spacing: 0.08em;
}

.editor-stage {
  min-width: 0;
  min-height: 0;
}

.editor-window {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.editor-toolbar {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}

.editor-toolbar-main {
  min-width: 0;
  width: 100%;
  flex: 1 1 auto;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 8px;
}

.token-action-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.token-action-button {
  min-height: 38px;
  padding: 8px 14px;
  color: #edf4ff;
  background: linear-gradient(180deg, rgba(37, 49, 66, 0.96), rgba(23, 31, 42, 0.96));
  border-color: rgba(83, 214, 255, 0.24);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.token-action-button:hover,
.token-action-button:focus-visible {
  background: linear-gradient(180deg, rgba(48, 66, 88, 0.98), rgba(28, 40, 54, 0.98));
  border-color: rgba(83, 214, 255, 0.36);
}

.token-inline-tools {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  overflow-x: scroll;
  overflow-y: hidden;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.token-rail {
  min-width: max-content;
  flex: 0 0 auto;
  width: max-content;
  display: flex;
  align-items: center;
  gap: 3px;
  overflow: visible;
}

.token-inline-tools::-webkit-scrollbar {
  display: none;
}

.token-scrollbar {
  position: relative;
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: rgba(9, 15, 22, 0.95);
  border: 1px solid rgba(83, 214, 255, 0.2);
  overflow: hidden;
}

.token-scrollbar-thumb {
  position: absolute;
  top: 1px;
  left: 0;
  height: 10px;
  min-width: 56px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffb01f, #35e6ff);
  box-shadow: 0 0 12px rgba(53, 230, 255, 0.42);
  cursor: grab;
}

.token-scrollbar-thumb:active {
  cursor: grabbing;
}

.token-scrollbar:not(.is-active) .token-scrollbar-thumb {
  width: 100%;
  background: linear-gradient(90deg, rgba(255, 176, 31, 0.4), rgba(53, 230, 255, 0.4));
  box-shadow: none;
}

.token-inline-label {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 15px;
  padding: 0;
  color: #ffd56a;
  background: transparent;
  border: 0;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.token-inline-label::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: linear-gradient(135deg, #ffb01f, #35e6ff);
  box-shadow: 0 0 10px rgba(53, 230, 255, 0.28);
}

.token-inline-label::after {
  content: ":";
  color: rgba(255, 213, 106, 0.82);
}

.token-inline-label-start {
  margin-left: 0;
}

.token-inline-label-start::before {
  content: "👉";
  width: auto;
  height: auto;
  border-radius: 0;
  background: none;
  box-shadow: none;
  font-size: 1.1rem;
  line-height: 1;
  animation: pointRightLoop 1.1s ease-in-out infinite;
}

.token-inline-note {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-2);
  background: rgba(125, 225, 173, 0.12);
  border: 1px solid rgba(125, 225, 173, 0.18);
}

.token-inline-label-start::before {
  content: "👉";
}

.editor-surface {
  min-height: 0;
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  background: linear-gradient(180deg, #111720 0%, var(--editor) 100%);
  overflow: auto;
}

.line-numbers,
.code-view,
.code-input {
  margin: 0;
  padding: 18px 0;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 1.3rem;
  line-height: 1.8;
}

.line-numbers {
  color: #5d6c80;
  text-align: right;
  padding-right: 14px;
  border-right: 1px solid var(--line);
  user-select: none;
  overflow: hidden;
  white-space: pre;
}

.editor-code-wrap {
  min-width: 0;
  min-height: 0;
  position: relative;
}

.code-view,
.code-input {
  min-height: 100%;
  width: 100%;
  padding-left: 18px;
  padding-right: 18px;
  color: #dce9f8;
  background: transparent;
  white-space: pre-wrap;
  word-break: break-word;
}

.code-input {
  border: 0;
  outline: none;
  resize: none;
}

.token-button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-weight: 600;
  font-size: 0.88rem;
  transition: border-color var(--transition), background var(--transition);
}

.token-button:hover,
.token-button:focus-visible {
  background: rgba(86, 192, 198, 0.1);
}

.token-button.selected {
  background: rgba(86, 192, 198, 0.18);
  border-color: rgba(83, 214, 255, 0.34);
  box-shadow: inset 0 0 0 1px rgba(83, 214, 255, 0.16);
}

.bottom-bar {
  padding: 14px 18px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.tour-restart-inline {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  border-radius: 16px;
  background: #fff0b8;
  border: 1px solid rgba(255, 176, 31, 0.45);
  box-shadow: 0 8px 24px rgba(34, 23, 4, 0.16);
}

.tour-restart-inline .button {
  min-height: 0;
  padding: 4px 10px;
}

.tour-restart-text {
  color: #5d4b33;
  font-size: 0.95rem;
  font-weight: 700;
}

.bottom-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
}

.tour-bubble {
  position: fixed;
  top: 16px;
  left: 16px;
  width: min(340px, calc(100vw - 32px));
  padding: 16px;
  border-radius: 22px;
  background: #fff5e3;
  color: #2f2415;
  box-shadow: 0 24px 60px rgba(34, 23, 4, 0.28);
  z-index: 9;
  display: grid;
  gap: 10px;
}

.tour-bubble::after {
  content: "";
  position: absolute;
  width: 0;
  height: 0;
}

.tour-bubble[data-placement="right"]::after {
  top: 50%;
  left: -12px;
  transform: translateY(-50%);
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-right: 12px solid #fff5e3;
}

.tour-bubble[data-placement="left"]::after {
  top: 50%;
  right: -12px;
  transform: translateY(-50%);
  border-top: 12px solid transparent;
  border-bottom: 12px solid transparent;
  border-left: 12px solid #fff5e3;
}

.tour-bubble[data-placement="bottom"]::after {
  top: -12px;
  left: 28px;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 12px solid #fff5e3;
}

.tour-bubble[data-placement="top"]::after {
  bottom: -12px;
  left: 28px;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-top: 12px solid #fff5e3;
}

.tour-step-label {
  margin: 0;
  color: #9c5a00;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tour-step-title,
.tour-step-text {
  margin: 0;
}

.tour-step-title {
  font-size: 1.05rem;
  color: #20170c;
}

.tour-step-text,
.tour-counter {
  color: #5d4b33;
}

.tour-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tour-counter {
  flex: 1 1 auto;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.tour-bubble .button-ghost {
  color: #5d4b33;
  border-color: rgba(93, 75, 51, 0.24);
}

.tour-focus {
  position: relative;
  z-index: 2;
  border-radius: 20px;
  box-shadow: 0 0 0 4px rgba(255, 176, 31, 0.88), 0 0 0 12px rgba(255, 245, 227, 0.2);
}

.token-inline-tools.tour-focus {
  border-radius: 18px;
  box-shadow:
    inset 0 0 0 4px rgba(255, 176, 31, 0.96),
    inset 0 0 0 10px rgba(255, 245, 227, 0.2);
}

.story-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 12, 0.62);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.story-modal-card {
  width: min(560px, 100%);
  padding: 20px;
  display: grid;
  gap: 14px;
  animation: modalUp 220ms ease;
  transform-origin: center center;
  transition:
    transform 320ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 320ms ease,
    filter 320ms ease;
}

.story-modal.is-shrinking {
  background: rgba(4, 8, 12, 0.16);
}

.story-modal-card.is-shrinking {
  opacity: 0.18;
  filter: blur(1px);
  transform:
    translate(var(--story-shrink-x, 0), var(--story-shrink-y, 0))
    scale(var(--story-shrink-scale-x, 0.42), var(--story-shrink-scale-y, 0.32));
}

.story-image-strip {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(96px, 1fr);
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.story-image-card {
  margin: 0;
  display: grid;
  gap: 8px;
}

.story-image-frame {
  min-height: 92px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  place-items: center;
}

.story-image {
  display: block;
  width: 100%;
  max-width: 92px;
  height: 92px;
  object-fit: contain;
}

.story-image-caption {
  text-align: center;
  color: #d7e3f2;
  font-size: 0.84rem;
  font-weight: 700;
  line-height: 1.2;
}

.function-intro-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 12, 0.72);
  backdrop-filter: blur(6px);
  z-index: 11;
}

.function-intro-card {
  width: min(760px, 100%);
  padding: 28px;
  display: grid;
  gap: 16px;
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(20, 27, 37, 0.98), rgba(10, 15, 22, 0.98));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
  animation: modalUp 220ms ease;
}

.function-intro-card h2 {
  text-align: center;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

.function-intro-copy {
  margin: 0;
  text-align: center;
  color: #cfd9e8;
  font-size: 1.02rem;
}

.function-intro-code {
  margin: 0;
  padding: 22px 24px;
  border-radius: 22px;
  border: 1px solid rgba(90, 232, 255, 0.16);
  background: #05090f;
  color: #e9f5ff;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: clamp(1.1rem, 2.1vw, 1.5rem);
  line-height: 1.55;
  text-align: center;
  overflow-x: auto;
}

.function-intro-actions {
  display: flex;
  justify-content: center;
}

.function-intro-actions .button {
  min-width: 240px;
}

.now-story-focus {
  border-radius: 16px;
  background: rgba(86, 192, 198, 0.12);
  box-shadow: 0 0 0 4px rgba(86, 192, 198, 0.16);
}

.feedback-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 12, 0.68);
  backdrop-filter: blur(6px);
  z-index: 12;
}

.feedback-card {
  width: min(560px, 100%);
  padding: 24px;
  display: grid;
  gap: 14px;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(20, 27, 37, 0.98), rgba(10, 15, 22, 0.98));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
  animation: modalUp 220ms ease;
}

.feedback-card.is-success {
  border-color: rgba(125, 225, 173, 0.22);
}

.feedback-card.is-danger {
  border-color: rgba(238, 142, 125, 0.26);
}

.feedback-badge,
.feedback-message,
.feedback-detail-label,
.feedback-detail {
  margin: 0;
}

.feedback-badge {
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.feedback-card.is-success .feedback-badge {
  color: var(--accent-2);
}

.feedback-card.is-danger .feedback-badge {
  color: #ffb1a2;
}

.feedback-card h2 {
  font-size: clamp(1.45rem, 2.5vw, 1.95rem);
}

.feedback-message {
  color: #edf4ff;
  font-size: 1rem;
  line-height: 1.5;
}

.feedback-detail-wrap {
  display: grid;
  gap: 8px;
  padding: 14px 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.feedback-detail-label {
  color: #ffd56a;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.feedback-detail {
  color: #d7e3f2;
  line-height: 1.5;
}

.feedback-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.loop-demo-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 12, 0.74);
  backdrop-filter: blur(6px);
  z-index: 13;
}

.loop-demo-card {
  width: min(620px, 100%);
  padding: 24px;
  display: grid;
  gap: 14px;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(20, 27, 37, 0.98), rgba(10, 15, 22, 0.98));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
  animation: modalUp 220ms ease;
}

.loop-demo-card.is-watch {
  border-color: rgba(90, 232, 255, 0.22);
}

.loop-demo-card.is-success {
  border-color: rgba(125, 225, 173, 0.22);
}

.loop-demo-card.is-danger {
  border-color: rgba(238, 142, 125, 0.26);
}

.loop-demo-stage {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.loop-demo-counter {
  margin: 0;
  text-align: center;
  color: #ffd56a;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.loop-demo-track {
  min-height: 96px;
  padding: 18px 16px 28px;
  border-radius: 20px;
  background:
    radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.08), transparent 56%),
    rgba(5, 9, 15, 0.88);
  border: 1px solid rgba(90, 232, 255, 0.14);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  position: relative;
  overflow: hidden;
}

.loop-demo-track::before {
  content: "";
  position: absolute;
  left: 42px;
  right: 42px;
  top: 50%;
  height: 4px;
  border-radius: 999px;
  background: rgba(214, 231, 252, 0.24);
  transform: translateY(-50%);
}

.loop-demo-bead {
  position: relative;
  z-index: 1;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
  animation: beadPop 320ms ease both;
  animation-delay: var(--loop-demo-delay, 0ms);
}

.loop-demo-bead::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
}

.loop-demo-bead.is-pink {
  background: linear-gradient(135deg, #ff84b7, #ffb6d5);
}

.loop-demo-bead.is-teal {
  background: linear-gradient(135deg, #4fdad1, #9df1e3);
}

.loop-demo-bead.is-gold {
  background: linear-gradient(135deg, #f4c75c, #ffe49c);
}

.loop-demo-bead.is-mystery {
  background: linear-gradient(135deg, #8da1bb, #c4d0e0);
}

.loop-demo-bead.is-mystery::before {
  content: "?";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #213245;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-weight: 700;
  z-index: 2;
}

.event-demo-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(4, 8, 12, 0.76);
  backdrop-filter: blur(6px);
  z-index: 14;
}

.event-demo-card {
  width: min(680px, 100%);
  padding: 24px;
  display: grid;
  gap: 14px;
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, rgba(20, 27, 37, 0.98), rgba(10, 15, 22, 0.98));
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
  animation: modalUp 220ms ease;
}

.event-demo-card.is-watch {
  border-color: rgba(90, 232, 255, 0.22);
}

.event-demo-card.is-success {
  border-color: rgba(125, 225, 173, 0.22);
}

.event-demo-card.is-danger {
  border-color: rgba(238, 142, 125, 0.26);
}

.event-demo-stage {
  display: grid;
  gap: 12px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}

.event-demo-lane {
  position: relative;
  min-height: 180px;
  border-radius: 22px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(34, 52, 78, 0.9) 0%, rgba(14, 22, 34, 0.96) 64%),
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.08), transparent 40%);
}

.event-demo-lane::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 30px;
  height: 8px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.1), rgba(255, 213, 106, 0.18), rgba(255, 255, 255, 0.1));
}

.event-demo-runner {
  position: absolute;
  left: 8%;
  bottom: 38px;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #59d8ff, #8af2d0);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.24);
  transition:
    left 640ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 260ms ease,
    box-shadow 220ms ease,
    opacity 220ms ease;
  z-index: 2;
}

.event-demo-face,
.event-demo-face::before,
.event-demo-face::after {
  position: absolute;
  display: block;
}

.event-demo-face {
  inset: 0;
}

.event-demo-face::before,
.event-demo-face::after {
  content: "";
  top: 12px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #122035;
}

.event-demo-face::before {
  left: 11px;
}

.event-demo-face::after {
  right: 11px;
}

.event-demo-runner.is-jump {
  transform: translateY(-52px) rotate(-7deg);
}

.event-demo-runner.is-low-jump {
  transform: translateY(-24px) rotate(-3deg);
}

.event-demo-runner.is-duck {
  transform: translateY(9px) scaleY(0.66);
  transform-origin: bottom center;
}

.event-demo-runner.is-grab {
  transform: translateY(-4px) scale(1.07);
  box-shadow: 0 0 0 5px rgba(255, 213, 106, 0.18), 0 14px 28px rgba(0, 0, 0, 0.24);
}

.event-demo-runner.is-bump {
  transform: translateY(10px) rotate(16deg);
  background: linear-gradient(135deg, #9aaac2, #d2dce8);
}

.event-demo-star,
.event-demo-wall {
  position: absolute;
  bottom: 44px;
  transition: transform 240ms ease, opacity 240ms ease, filter 240ms ease;
}

.event-demo-star {
  left: 42%;
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, #ffe47e, #f7bf38);
  clip-path: polygon(50% 0%, 61% 34%, 98% 36%, 68% 57%, 79% 93%, 50% 72%, 21% 93%, 32% 57%, 2% 36%, 39% 34%);
  box-shadow: 0 0 20px rgba(255, 213, 106, 0.3);
}

.event-demo-star.is-collected {
  opacity: 0;
  transform: translateY(-26px) scale(0.2);
}

.event-demo-star.is-missed {
  opacity: 0.34;
  filter: grayscale(0.9);
}

.event-demo-card[data-theme="cave"] .event-demo-lane {
  background:
    linear-gradient(180deg, rgba(52, 36, 20, 0.94) 0%, rgba(18, 12, 8, 0.98) 68%),
    radial-gradient(circle at 50% 16%, rgba(255, 219, 145, 0.08), transparent 42%);
}

.event-demo-card[data-theme="cave"] .event-demo-lane::before {
  background: linear-gradient(90deg, rgba(255, 208, 120, 0.14), rgba(140, 106, 62, 0.24), rgba(255, 208, 120, 0.14));
}

.event-demo-star.is-gem {
  width: 30px;
  height: 30px;
  bottom: 68px;
  border-radius: 8px;
  clip-path: polygon(50% 0%, 90% 30%, 74% 100%, 26% 100%, 10% 30%);
  background: linear-gradient(135deg, #77ffcf, #2fd3a7);
  box-shadow: 0 0 18px rgba(47, 211, 167, 0.32);
}

.event-demo-star.is-gem.is-collected {
  opacity: 0;
  transform: translateY(-30px) scale(0.18);
}

.event-demo-wall.is-pipe {
  bottom: 38px;
  width: 52px;
  height: 62px;
  border-radius: 12px 12px 0 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 22%),
    linear-gradient(135deg, #5fd26c, #2e8d46);
}

.event-demo-wall.is-pipe::before {
  inset: -8px 4px auto;
  height: 12px;
  border-radius: 999px;
  background: rgba(220, 255, 220, 0.28);
}

.event-demo-wall {
  left: 75%;
  width: 38px;
  height: 54px;
  border-radius: 10px 10px 6px 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 26%),
    linear-gradient(135deg, #ff7d73, #d8534f);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
}

.event-demo-wall::before {
  content: "";
  position: absolute;
  inset: 8px 8px auto;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.event-demo-wall.is-cleared {
  opacity: 0.46;
  transform: scaleY(0.84);
}

.event-demo-wall.is-hit {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 26%),
    linear-gradient(135deg, #ff9f93, #ff6d61);
  box-shadow: 0 0 0 5px rgba(238, 142, 125, 0.16);
}

.event-demo-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.event-demo-chip {
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  color: #d7e3f2;
  font-size: 0.86rem;
  font-weight: 700;
}

.role-buttons-modal {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

button:focus-visible,
textarea:focus-visible,
.level-tab:focus-visible,
.token-button:focus-visible,
.role-button:focus-visible {
  outline: 3px solid rgba(86, 192, 198, 0.18);
  outline-offset: 2px;
}

@keyframes modalUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes glowCard {
  0%,
  100% {
    box-shadow: 0 0 0 rgba(125, 225, 173, 0);
  }

  50% {
    box-shadow: 0 0 24px rgba(125, 225, 173, 0.12);
  }
}

@keyframes pointRightLoop {
  0%,
  100% {
    transform: translateX(-2px);
  }

  50% {
    transform: translateX(4px);
  }
}

@keyframes beadPop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.72);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .role-buttons-modal {
    grid-template-columns: 1fr;
  }

  .feedback-actions {
    justify-content: stretch;
  }

  .feedback-actions .button {
    flex: 1 1 180px;
  }
}

@media (max-width: 980px) {
  .app-shell {
    width: calc(100% - 20px);
    height: calc(100vh - 20px);
    height: calc(100dvh - 20px);
    margin: 10px auto;
    padding: 12px;
  }

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

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

  .story-rail {
    grid-template-rows: auto auto;
  }

  .topbar-center,
  .scene-switcher,
  .level-tabs {
    justify-content: flex-start;
  }
}

@media (max-width: 760px) {
  .editor-toolbar,
  .editor-toolbar-main {
    flex-direction: column;
    align-items: stretch;
  }

  .editor-surface {
    grid-template-columns: 52px minmax(0, 1fr);
  }

  .line-numbers,
  .code-view,
  .code-input {
    font-size: 1.14rem;
  }

  .role-buttons-modal {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}
