:root {
  --bg: #f4efe7;
  --panel: rgba(255, 250, 244, 0.94);
  --text: #221d18;
  --muted: #71655a;
  --border: #dbd0c3;
  --accent: #9a4c32;
  --me: #f1ddd2;
  --other: #dfe8d7;
  --shadow: 0 18px 45px rgba(68, 47, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: Georgia, "Iowan Old Style", serif;
  background:
    radial-gradient(circle at top, rgba(190, 127, 98, 0.12), transparent 28%),
    linear-gradient(180deg, #f9f6f1 0%, var(--bg) 100%);
}

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

.app-shell {
  width: min(100%, 52rem);
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

.app-footer {
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(219, 208, 195, 0.8);
}

.app-footer p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.menu-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.app-menu {
  position: relative;
}

.app-menu summary {
  list-style: none;
  cursor: pointer;
  width: 2.6rem;
  height: 2.6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
}

.app-menu summary::-webkit-details-marker {
  display: none;
}

.app-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  z-index: 30;
  width: min(24rem, calc(100vw - 2rem));
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid rgba(219, 208, 195, 0.9);
  background: rgba(255, 250, 244, 0.98);
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.9rem;
}

.app-menu__section {
  display: grid;
  gap: 0.6rem;
}

.help-panel {
  gap: 0.9rem;
  padding-top: 0.1rem;
  border-top: 1px solid rgba(219, 208, 195, 0.8);
}

.help-panel__title {
  margin: 0;
  font-size: 1rem;
}

.help-block {
  display: grid;
  gap: 0.35rem;
}

.help-block h3 {
  margin: 0;
  font-size: 0.92rem;
}

.help-block p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.help-block code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

.topbar__actions,
.setup,
.editor-actions,
.speaker-key {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.setup--menu {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.setup {
  margin-bottom: 0.75rem;
  padding: 1rem;
  border: 1px solid rgba(219, 208, 195, 0.8);
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  gap: 0.35rem;
  flex: 1 1 16rem;
}

label {
  color: var(--muted);
  font-size: 0.9rem;
}

input[type="text"],
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  padding: 0.8rem 0.95rem;
  background: rgba(255, 255, 255, 0.72);
}

textarea {
  resize: vertical;
  min-height: 6rem;
}

.button {
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.7rem 1rem;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.button--secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

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

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

.speaker-key--menu {
  margin: 0;
}

.speaker-key__hint {
  opacity: 0.9;
}

.menu-help {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.speaker-key__item {
  display: inline-flex;
  gap: 0.35rem;
  align-items: center;
}

.speaker-key__item::before {
  content: "";
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 999px;
  display: inline-block;
}

.speaker-key__item--me::before {
  background: #c97b61;
}

.speaker-key__item--other::before {
  background: #86a275;
}

.root-entry,
.node__editor,
.node__reply {
  margin-bottom: 1rem;
  padding: 1rem;
  border: 1px solid rgba(219, 208, 195, 0.8);
  border-radius: 1rem;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.node__quick-reply {
  margin-top: 0.55rem;
  padding-left: 1rem;
}

.node__quick-reply--hidden {
  display: none;
}

.root-entry h2,
.node__editor h3,
.node__reply h3 {
  margin: 0 0 0.35rem;
}

.root-entry p,
.node__reply p {
  margin: 0 0 0.75rem;
  color: var(--muted);
}

.tree,
.children {
  display: grid;
  gap: 0.65rem;
}

.choice-group {
  margin-top: 0.75rem;
}

.choice-group__label {
  margin: 0 0 0.45rem 0.95rem;
  color: var(--muted);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.children {
  margin-top: 0.5rem;
  margin-left: 0.7rem;
  padding-left: 1rem;
  border-left: 2px solid rgba(154, 76, 50, 0.18);
}

.children--choice {
  gap: 0.95rem;
  padding-left: 1.15rem;
  border-left-color: rgba(154, 76, 50, 0.35);
}

.children--choice > .node {
  position: relative;
}

.children--choice > .node::before {
  content: attr(data-branch-label);
  position: absolute;
  left: -1.85rem;
  top: 0.3rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  background: rgba(154, 76, 50, 0.1);
  border: 1px solid rgba(154, 76, 50, 0.2);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.73rem;
  font-weight: 600;
}

.node--collapsed > .choice-group {
  display: none;
}

.node__line {
  display: flex;
  width: 100%;
}

.node--me > .node__line {
  padding-left: 2rem;
  justify-content: flex-start;
}

.node--other > .node__line {
  padding-right: 2rem;
  justify-content: flex-start;
}

.bubble {
  width: min(100%, 28rem);
  padding: 0.45rem 0.72rem 0.58rem;
  border-radius: 1rem;
  border: 1px solid rgba(219, 208, 195, 0.8);
  box-shadow: 0 8px 24px rgba(78, 57, 42, 0.05);
}

.bubble--toggleable {
  cursor: pointer;
}

.node--me > .node__line .bubble {
  margin-left: auto;
}

.node--other > .node__line .bubble {
  margin-right: auto;
}

.node--me > .node__line .bubble {
  background: var(--me);
}

.node--other > .node__line .bubble {
  background: var(--other);
}

.bubble__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 1.25rem;
  gap: 0.5rem;
}

.bubble__meta {
  font-size: 0.78rem;
  color: var(--muted);
  display: flex;
  gap: 0.45rem;
  align-items: center;
  flex-wrap: wrap;
}

.bubble__role {
  font-weight: 600;
}

.bubble__branch-count {
  font-size: 0.72rem;
  opacity: 0.85;
}

.bubble__branch-count--choice {
  color: var(--accent);
  font-weight: 600;
}

.bubble__content {
  margin: 0.15rem 0 0;
  line-height: 1.45;
  white-space: pre-wrap;
}

.bubble__behavior {
  font-style: italic;
  color: var(--muted);
}

.bubble__menu {
  position: relative;
}

.bubble__menu summary {
  list-style: none;
  cursor: pointer;
  border: 0;
  background: transparent;
  color: var(--muted);
  min-width: 1.5rem;
  min-height: 1.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  line-height: 1;
}

.bubble__menu summary::-webkit-details-marker {
  display: none;
}

.bubble__menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.2rem);
  z-index: 20;
  display: grid;
  gap: 0.2rem;
  min-width: 9rem;
  padding: 0.35rem;
  border-radius: 0.8rem;
  border: 1px solid var(--border);
  background: rgba(255, 253, 250, 0.98);
  box-shadow: var(--shadow);
}

.bubble__menu-panel button,
.bubble__menu-panel a {
  padding: 0.55rem 0.7rem;
  border: 0;
  border-radius: 0.6rem;
  background: transparent;
  color: var(--text);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.bubble__menu-panel button:hover,
.bubble__menu-panel a:hover {
  background: rgba(154, 76, 50, 0.08);
}

.node__reply,
.node__editor {
  margin-left: 1rem;
}

.node--me .node__reply {
  border-left: 3px solid rgba(201, 123, 97, 0.45);
}

.node--other .node__reply {
  border-left: 3px solid rgba(134, 162, 117, 0.45);
}

.editor-note {
  margin: 0 0 0.75rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.quick-reply__actions {
  display: flex;
  gap: 0.65rem;
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 0.55rem;
}

.empty-state {
  color: var(--muted);
  padding: 0.6rem 0;
}

@media (max-width: 640px) {
  .app-shell {
    padding-inline: 0.8rem;
  }

  .topbar__actions {
    width: 100%;
  }

  .topbar__actions .button {
    flex: 1 1 auto;
  }

  .app-menu__panel {
    width: min(24rem, calc(100vw - 1.6rem));
  }

  .node--me > .node__line,
  .node--other > .node__line {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .bubble {
    width: min(100%, 100%);
  }

  .children {
    margin-left: 0.2rem;
    padding-left: 0.75rem;
  }

  .children--choice > .node::before {
    left: -1.55rem;
  }

  .node__quick-reply {
    padding-left: 0;
  }
}
