:root {
  --ink: #18211d;
  --muted: #66756e;
  --paper: #f5f7f2;
  --panel: #ffffff;
  --line: #dce3dd;
  --line-strong: #c4cec7;
  --green: #1f8f74;
  --green-dark: #166955;
  --orange: #df6a3f;
  --yellow: #e4b548;
  --red: #bc3f3a;
  --blue: #337aa3;
  --shadow: 0 14px 32px rgba(24, 33, 29, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(31, 143, 116, 0.12), transparent 28%),
    linear-gradient(315deg, rgba(223, 106, 63, 0.10), transparent 30%),
    var(--paper);
  color: var(--ink);
  font-family:
    Inter, "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

.auth-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 22px;
}

.auth-panel {
  display: grid;
  gap: 18px;
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.auth-brand {
  padding-bottom: 4px;
}

.auth-panel .btn {
  width: 100%;
}

.login-hint {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 800;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px;
  background: rgba(255, 255, 255, 0.74);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

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

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.modal h3 {
  margin: 0;
}

.brand h1 {
  font-size: 22px;
  line-height: 1.1;
}

.brand p,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border: 1px solid rgba(24, 33, 29, 0.18);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(24, 33, 29, 0.12) 1px, transparent 1px) 0 0 / 12px 12px,
    linear-gradient(0deg, rgba(24, 33, 29, 0.12) 1px, transparent 1px) 0 0 / 12px 12px,
    #f1f5ee;
  overflow: hidden;
}

.brand-mark span {
  position: absolute;
  display: block;
  border-radius: 50%;
}

.brand-mark span:nth-child(1) {
  width: 8px;
  height: 8px;
  left: 9px;
  top: 11px;
  background: var(--green);
}

.brand-mark span:nth-child(2) {
  width: 7px;
  height: 7px;
  right: 9px;
  bottom: 10px;
  background: var(--orange);
}

.brand-mark span:nth-child(3) {
  width: 26px;
  height: 2px;
  left: 13px;
  top: 27px;
  background: var(--yellow);
  border-radius: 2px;
  transform: rotate(-24deg);
}

.map-actions,
.topbar-actions,
.modal-actions,
.editor-actions,
.row-actions,
.chip-row,
.node-tools,
.note-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn,
.icon-btn {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.btn {
  padding: 0 13px;
}

.btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--green);
  color: #fff;
}

.btn.primary:hover {
  background: var(--green-dark);
}

.btn.ghost {
  border-color: var(--line);
}

.btn.danger {
  background: #fff0ee;
  border-color: #f0c3bf;
  color: var(--red);
}

.btn.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.map-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overflow: auto;
  padding-right: 2px;
}

.map-item {
  width: 100%;
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    radial-gradient(circle at 82% 22%, var(--map-accent, rgba(31, 143, 116, 0.26)), transparent 22%),
    var(--panel);
  text-align: left;
  box-shadow: 0 8px 20px rgba(24, 33, 29, 0.06);
}

.map-item.active {
  border-color: rgba(31, 143, 116, 0.62);
  box-shadow: 0 12px 24px rgba(31, 143, 116, 0.15);
}

.map-title-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.map-title {
  font-size: 18px;
  font-weight: 800;
}

.map-counts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
}

.map-counts span {
  min-width: 0;
  white-space: nowrap;
}

.workspace {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 24px;
  gap: 16px;
}

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

.topbar h2 {
  font-size: 34px;
  line-height: 1.05;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.68);
}

.tab {
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab.active {
  background: var(--panel);
  color: var(--ink);
  border-color: var(--line);
  box-shadow: 0 8px 16px rgba(24, 33, 29, 0.08);
}

.content {
  min-height: 0;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 360px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.64);
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.tactic-layout {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 24px rgba(24, 33, 29, 0.07);
}

.list-panel {
  position: sticky;
  top: 18px;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-head h3,
.section-title,
.tactic-card h4,
.note-index,
.decision-title {
  margin: 0;
}

.panel-head h3 {
  font-size: 16px;
}

.tactic-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 245px);
  overflow: auto;
  padding: 12px;
}

.tactic-card {
  width: 100%;
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  text-align: left;
}

.tactic-card.active {
  border-color: rgba(223, 106, 63, 0.62);
  box-shadow: 0 10px 18px rgba(223, 106, 63, 0.12);
}

.tactic-card h4 {
  font-size: 15px;
  line-height: 1.3;
}

.meta-line,
.updated-line {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.editor {
  padding: 16px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(180px, 0.75fr);
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field > span,
.mini-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea,
.inline-add input,
.command-row input,
.decision-node input,
.decision-node textarea,
.note-card textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input,
.field select,
.inline-add input,
.command-row input,
.decision-node input {
  min-height: 40px;
  padding: 0 11px;
}

.field textarea,
.decision-node textarea,
.note-card textarea {
  min-height: 86px;
  padding: 10px 11px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.inline-add input:focus,
.command-row input:focus,
.decision-node input:focus,
.decision-node textarea:focus,
.note-card textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(31, 143, 116, 0.14);
}

.hidden {
  display: none !important;
}

.section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
}

.section-title {
  font-size: 15px;
}

.chip-row {
  align-items: stretch;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  font-size: 13px;
  font-weight: 800;
}

.chip input {
  width: 15px;
  height: 15px;
  accent-color: var(--green);
}

.custom-tag {
  background: #eef7f4;
  border-color: rgba(31, 143, 116, 0.32);
  color: var(--green-dark);
}

.custom-tag button {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: rgba(31, 143, 116, 0.12);
  color: var(--green-dark);
  font-weight: 900;
}

.inline-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  width: min(460px, 100%);
}

.command-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.command-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: center;
}

.command-row .icon-btn {
  min-height: 40px;
}

.execution-preview {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f9fbf7;
}

.priority-group {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.priority-badge {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 30px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.priority-texts {
  display: grid;
  gap: 6px;
}

.priority-texts span {
  min-height: 30px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

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

.decision-stack {
  display: grid;
  gap: 12px;
}

.root-stack {
  counter-reset: decision-root;
}

.decision-node {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.decision-node.child {
  margin-left: clamp(12px, calc(var(--depth) * 14px), 56px);
  border-left: 4px solid var(--orange);
  background:
    linear-gradient(90deg, rgba(223, 106, 63, 0.08), transparent 42%),
    #fff;
}

.decision-node.child::before {
  content: "";
  position: absolute;
  left: -22px;
  top: 22px;
  width: 18px;
  height: 2px;
  background: var(--orange);
}

.decision-node.child::after {
  content: "";
  position: absolute;
  left: -22px;
  top: -14px;
  width: 2px;
  height: 37px;
  background: var(--orange);
}

.decision-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.node-fields {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 10px;
}

.decision-children {
  position: relative;
  display: grid;
  gap: 10px;
  margin-top: 2px;
  padding: 12px 0 0 16px;
  border-top: 1px dashed var(--line-strong);
}

.decision-children::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: rgba(223, 106, 63, 0.38);
}

.branch-label {
  width: fit-content;
  padding: 4px 8px;
  border-radius: 6px;
  background: #fff4ee;
  color: var(--orange);
  font-size: 12px;
  font-weight: 900;
}

.notes-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 16px;
  align-items: start;
}

.notes-list {
  display: grid;
  gap: 10px;
}

.note-card {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
}

.note-index {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 900;
}

.note-body {
  display: grid;
  gap: 10px;
}

.new-note {
  padding: 14px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 33, 29, 0.38);
}

.modal-panel {
  width: min(440px, 100%);
  padding: 16px;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 800;
}

.toast.error {
  background: var(--red);
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 240px minmax(0, 1fr);
  }

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

  .tactic-layout,
  .notes-layout,
  .editor-grid,
  .node-fields {
    grid-template-columns: 1fr;
  }

  .editor.no-selection {
    display: none;
  }

  .editor.has-selection {
    order: -1;
  }

  .list-panel {
    position: static;
  }

  .tactic-list {
    max-height: none;
  }
}

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

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

  .map-list {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(210px, 78vw);
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .workspace {
    padding: 16px;
  }

  .topbar {
    flex-direction: column;
  }

  .topbar h2 {
    font-size: 28px;
  }

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

  .panel-head,
  .editor-actions,
  .note-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-head .btn,
  .editor-actions .btn,
  .note-actions .btn,
  .topbar-actions .btn {
    width: 100%;
  }

  .command-row {
    grid-template-columns: 76px minmax(0, 1fr) 36px;
  }

  .priority-group {
    grid-template-columns: 1fr;
  }

  .note-card {
    grid-template-columns: 1fr;
  }

  .inline-add {
    grid-template-columns: 1fr;
  }
}
