:root {
  --bg-top: #f4efe7;
  --bg-bottom: #dbe6ef;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-strong: #ffffff;
  --ink: #18212a;
  --muted: #4e5d6d;
  --accent: #1b7e65;
  --accent-strong: #0f5b48;
  --danger: #a93338;
  --border: rgba(24, 33, 42, 0.14);
  --shadow: 0 14px 28px rgba(19, 33, 47, 0.12);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at 20% 10%, #fef8e8 0%, transparent 35%),
    radial-gradient(circle at 82% 5%, #d6f3ee 0%, transparent 38%),
    linear-gradient(160deg, var(--bg-top), var(--bg-bottom));
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: "Palatino Linotype", "Book Antiqua", Palatino, serif;
  margin: 0;
}

code,
pre,
textarea,
code {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.3rem;
  background: rgba(255, 255, 255, 0.68);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  gap: 0.9rem;
  align-items: center;
}

.brand p {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.brand-logo {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--ink);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  transition: transform 0.12s ease, background-color 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: #f2f7f7;
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-small {
  padding: 0.28rem 0.6rem;
  border-radius: 10px;
}

.btn-danger {
  background: #ffe8e9;
  color: var(--danger);
}

.app-main {
  padding: 1rem;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: calc(100vh - 115px);
  overflow: hidden;
}

.hidden {
  display: none !important;
}

.hidden-input {
  display: none;
}

#player-view {
  padding: 1rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.8rem;
}

#state-preview {
  max-width: 45%;
  overflow-x: auto;
  font-size: 0.77rem;
  color: var(--muted);
}

.passage-content {
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  min-height: 280px;
  line-height: 1.45;
}

.passage-content img,
.preview-content img {
  max-width: min(100%, 480px);
  border-radius: 12px;
}

.passage-content audio,
.passage-content video {
  display: block;
  width: min(100%, 480px);
  margin: 0.7rem 0;
}

.choice-list {
  margin-top: 0.8rem;
  display: grid;
  gap: 0.55rem;
}

.choice-btn,
.goto-btn {
  border: 1px solid rgba(17, 66, 59, 0.24);
  background: #eaf7f3;
  color: #12352d;
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  text-align: left;
  cursor: pointer;
}

.choice-btn:hover,
.goto-btn:hover {
  background: #ddf0ea;
}

.goto-inline {
  display: inline-block;
  margin: 0.2rem 0;
}

.errors {
  margin-top: 0.7rem;
  border-radius: 10px;
  padding: 0.65rem;
  font-size: 0.87rem;
}

.errors.error {
  background: #ffe8e9;
  color: #71181d;
  border: 1px solid rgba(138, 24, 31, 0.22);
}

.errors.info {
  background: #edf6ff;
  color: #1a3650;
  border: 1px solid rgba(22, 59, 95, 0.2);
}

#editor-view {
  display: grid;
  grid-template-columns: 280px 1fr;
}

.editor-sidebar {
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.78);
  padding: 0.8rem;
}

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.passage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.3rem;
}

.passage-item {
  border: 1px solid transparent;
  background: #fff;
  padding: 0.45rem 0.55rem;
  border-radius: 9px;
  cursor: pointer;
}

.passage-item:hover {
  border-color: rgba(20, 63, 56, 0.2);
}

.passage-item.active {
  border-color: rgba(20, 63, 56, 0.4);
  background: #eaf7f3;
}

.editor-workbench {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.7);
}

.editor-toolbar input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.45rem;
  min-width: 180px;
}

.hint {
  color: var(--muted);
  font-size: 0.82rem;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.editor-pane,
.preview-pane {
  position: relative;
  min-height: 0;
  padding: 0.75rem;
}

.editor-pane {
  border-right: 1px solid var(--border);
}

#passage-editor {
  width: 100%;
  height: calc(100% - 46px);
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: 10px;
  resize: none;
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.85);
  font-size: 0.95rem;
  line-height: 1.4;
}

.preview-pane h3 {
  margin-bottom: 0.5rem;
}

.preview-content {
  height: calc(100% - 36px);
  overflow: auto;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
}

.autocomplete {
  position: absolute;
  left: 0.85rem;
  right: 0.85rem;
  bottom: 3.4rem;
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid rgba(19, 75, 66, 0.26);
  background: #f6fbfa;
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(17, 56, 49, 0.14);
  z-index: 8;
}

.autocomplete-item {
  padding: 0.46rem 0.6rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: #dff2ec;
}

.autocomplete small {
  color: #4f635f;
}

.inline-pill {
  display: inline-block;
  border-radius: 999px;
  border: 1px solid rgba(17, 66, 59, 0.26);
  padding: 0.2rem 0.5rem;
  background: #ebf7f3;
  margin: 0 0.2rem 0.2rem 0;
}

@media (max-width: 1050px) {
  #editor-view {
    grid-template-columns: 1fr;
  }

  .editor-sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

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

  .editor-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .panel {
    min-height: auto;
  }
}
