:root {
  --bg: #f3efe7;
  --bg-deep: #e6dccb;
  --panel: rgba(255, 251, 244, 0.86);
  --ink: #1f1a17;
  --muted: #706358;
  --line: rgba(92, 74, 58, 0.18);
  --accent: #9d3c2b;
  --accent-soft: #f0c5a8;
  --accent-strong: #6f2012;
  --forest: #32463b;
  --shadow: 0 20px 60px rgba(85, 51, 28, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(157, 60, 43, 0.15), transparent 32%),
    radial-gradient(circle at bottom right, rgba(50, 70, 59, 0.16), transparent 26%),
    linear-gradient(135deg, var(--bg) 0%, #f7f2ea 45%, var(--bg-deep) 100%);
  min-height: 100vh;
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 100vh;
}

.sidebar,
.workspace {
  padding: 24px;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: rgba(255, 249, 240, 0.66);
  backdrop-filter: blur(18px);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand h1,
.hero h2,
.panel h2,
.panel h3 {
  margin: 0;
  font-family: Georgia, "Noto Serif TC", serif;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
}

.subtle {
  color: var(--muted);
  line-height: 1.6;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(92, 74, 58, 0.12);
  box-shadow: var(--shadow);
  border-radius: 24px;
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-head h2,
.panel-head h3 {
  font-size: 18px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  background: linear-gradient(135deg, rgba(255, 251, 244, 0.86), rgba(247, 234, 222, 0.9));
  border: 1px solid rgba(157, 60, 43, 0.18);
  border-radius: 28px;
  padding: 24px 28px;
  box-shadow: var(--shadow);
}

.hero-actions,
.choices-view,
.tree-view,
.form-stack,
.control-column,
.node-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.85fr);
  gap: 20px;
  min-height: 0;
}

.main-panel {
  display: flex;
  flex-direction: column;
}

.badge {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(50, 70, 59, 0.12);
  color: var(--forest);
  font-size: 13px;
}

.scene-view {
  min-height: 400px;
  line-height: 1.9;
  white-space: pre-wrap;
  background: rgba(255, 255, 255, 0.52);
  border-radius: 20px;
  padding: 24px;
  border: 1px solid rgba(92, 74, 58, 0.1);
  font-size: 16px;
  outline: none;
  resize: none;
}

.scene-view.empty {
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.node-meta {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
}

.image-container {
  margin-bottom: 20px;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  position: relative;
  background: #eee;
  min-height: 100px;
  max-height: 512px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-container.hidden {
  display: none;
}

.image-container img {
  width: 100%;
  height: auto;
  display: block;
}

.image-loader {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 251, 244, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  color: var(--accent);
}

.image-loader.hidden {
  display: none;
}

.accent-btn {
  background: linear-gradient(135deg, #2b5876 0%, #4e4376 100%);
  color: #fff;
  font-weight: bold;
}

.guidance-box {
  margin-top: 18px;
  background: linear-gradient(135deg, rgba(157, 60, 43, 0.08), rgba(240, 197, 168, 0.3));
  border-radius: 18px;
  padding: 16px;
  line-height: 1.7;
}

.node-actions {
  margin-top: 18px;
}

.choices-section {
  margin-top: 18px;
}

.choice-btn,
.tree-node,
button {
  border: none;
  border-radius: 18px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 24px rgba(157, 60, 43, 0.22);
}

button.secondary,
.ghost-btn {
  background: rgba(157, 60, 43, 0.1);
  color: var(--accent-strong);
  box-shadow: none;
}

button.danger {
  background: rgba(128, 31, 22, 0.12);
  color: #7a1f15;
}

button:hover,
.choice-btn:hover,
.tree-node:hover {
  transform: translateY(-1px);
}

.choice-btn {
  text-align: left;
  background: rgba(255, 244, 236, 0.92);
  color: var(--ink);
  border: 1px solid rgba(157, 60, 43, 0.18);
}

.choice-btn.active {
  background: linear-gradient(135deg, rgba(157, 60, 43, 0.92), rgba(111, 32, 18, 0.92));
  color: #fff;
}

.tree-node {
  text-align: left;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(92, 74, 58, 0.12);
  color: var(--ink);
}

.tree-node.selected {
  background: linear-gradient(135deg, rgba(50, 70, 59, 0.9), rgba(41, 58, 49, 0.92));
  color: #fff;
}

.tree-node small {
  display: block;
  opacity: 0.72;
  margin-top: 6px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

label span {
  font-size: 14px;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border-radius: 16px;
  border: 1px solid rgba(92, 74, 58, 0.15);
  background: rgba(255, 255, 255, 0.76);
  padding: 12px 14px;
  color: var(--ink);
  resize: vertical;
}

.health-box {
  border-radius: 18px;
  background: rgba(50, 70, 59, 0.1);
  color: var(--forest);
  padding: 14px;
  line-height: 1.7;
}

.health-box.error {
  background: rgba(157, 60, 43, 0.1);
  color: var(--accent-strong);
}

@media (max-width: 1080px) {
  .shell,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
  }
}

.modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  position: relative;
  max-width: 90%;
  max-height: 90%;
}

.modal-content img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

.close-btn {
  position: absolute;
  top: -40px;
  right: 0;
  color: white;
  font-size: 40px;
  font-weight: bold;
  cursor: pointer;
}

.image-container img {
  cursor: zoom-in;
}
