:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #20242a;
  --muted: #707782;
  --line: #d8d1c3;
  --accent: #23615b;
  --accent-2: #a9482f;
  --accent-soft: #dcebe6;
  --warn: #fff0c7;
  --warn-line: #e7b84e;
  --shadow: 0 18px 45px rgba(42, 35, 24, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(35, 97, 91, 0.12), transparent 32%),
    linear-gradient(315deg, rgba(169, 72, 47, 0.12), transparent 30%),
    var(--bg);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

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

button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-strong);
  color: var(--ink);
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 168px;
  padding: 12px;
  line-height: 1.45;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.app-shell {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.86);
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

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

.brand span {
  color: var(--muted);
  font-size: 13px;
}

.access-panel,
.project-panel,
.question-card,
.slide-card,
.problem-tree-panel,
.export-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.access-panel,
.project-panel {
  padding: 14px;
  box-shadow: none;
}

.inline-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
}

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

.project-item {
  text-align: left;
  min-height: auto;
  padding: 10px;
}

.project-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.workspace {
  padding: 24px;
  display: grid;
  align-content: start;
  gap: 18px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: clamp(26px, 3vw, 42px);
  letter-spacing: 0;
}

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

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

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stage-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.stage-tab {
  white-space: nowrap;
  min-height: 38px;
}

.stage-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.work-area {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(360px, 0.85fr);
  gap: 18px;
  align-items: start;
}

.question-card,
.slide-card,
.problem-tree-panel,
.export-panel {
  padding: 18px;
}

.question-head,
.slide-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
  margin-bottom: 14px;
}

.question-head h2,
.slide-head h3 {
  margin: 4px 0 0;
  line-height: 1.18;
}

.question-head select {
  max-width: 190px;
}

.tool-row,
.nav-row,
.tree-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 12px;
}

.nav-row {
  justify-content: flex-end;
}

.weakness-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--warn-line);
  background: var(--warn);
  border-radius: 8px;
  line-height: 1.42;
}

.weakness-panel pre {
  margin: 0 0 12px;
  white-space: pre-wrap;
  font-family: inherit;
}

.hidden {
  display: none !important;
}

.slide-frame {
  min-height: 330px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eee7db;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.slide-frame img {
  width: 100%;
  height: 100%;
  max-height: 520px;
  object-fit: contain;
  display: none;
}

.slide-frame.has-slide img {
  display: block;
}

.slide-frame.has-slide p {
  display: none;
}

.problem-tree-panel {
  display: grid;
  gap: 12px;
}

.tree-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.tree-grid textarea {
  min-height: 130px;
}

.wide-label textarea {
  min-height: 92px;
}

#treeState {
  color: var(--muted);
  font-size: 13px;
}

.export-panel textarea {
  min-height: 430px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
}

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

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

  .meta-grid,
  .tree-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .workspace,
  .sidebar {
    padding: 14px;
  }

  .topbar,
  .question-head,
  .slide-head {
    display: grid;
  }

  .meta-grid,
  .tree-grid {
    grid-template-columns: 1fr;
  }
}
