:root {
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f1;
  --ink: #1d2628;
  --muted: #667477;
  --line: #d8e0df;
  --accent: #28756a;
  --accent-dark: #15564e;
  --action: #1f6fb2;
  --action-dark: #15548a;
  --action-soft: #e8f2fb;
  --export: #b35f12;
  --export-dark: #8f4908;
  --export-soft: #fff0df;
  --warn: #a85b13;
  --danger: #a13d3d;
  --ok: #2f7650;
  --shadow: 0 18px 45px rgba(32, 49, 52, 0.12);
  color-scheme: light;
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 24px clamp(16px, 4vw, 44px);
  background: #153f3b;
  color: #fff;
}

.app-header h1 {
  margin: 4px 0 0;
  font-size: clamp(1.7rem, 3.5vw, 2.75rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: inherit;
  opacity: 0.72;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.save-state {
  min-width: 72px;
  font-size: 0.88rem;
  color: #d7ebe7;
}

.workspace {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: clamp(16px, 3vw, 32px);
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 22px;
  flex: 1;
}

.topic-panel,
.work-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.topic-panel {
  align-self: start;
  position: sticky;
  top: 16px;
  overflow: hidden;
}

.panel-head,
.section-head {
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2,
.section-head h2 {
  margin: 4px 0 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.panel-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.topic-list {
  display: grid;
  gap: 0;
}

.topic-button {
  width: 100%;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  padding: 16px 18px;
  color: var(--ink);
  text-align: left;
  display: grid;
  gap: 7px;
}

.topic-button:first-child {
  border-top: 0;
}

.topic-button:hover,
.topic-button.is-active {
  background: var(--surface-soft);
}

.topic-button strong {
  font-size: 0.98rem;
}

.topic-button span {
  color: var(--muted);
  font-size: 0.86rem;
}

.work-panel {
  min-width: 0;
  overflow: hidden;
}

.step-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.tab-button {
  border: 1px solid var(--line);
  background: #f7fbfa;
  color: var(--accent-dark);
  min-height: 40px;
  padding: 0 12px;
  border-radius: 8px;
  white-space: nowrap;
  font-weight: 700;
}

.tab-button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(21, 86, 78, 0.2);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.topic-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--accent-dark);
  font-weight: 700;
  font-size: 0.9rem;
}

.task-grid,
.form-grid,
.material-list,
.argument-list,
.check-list,
.writing-plan,
.export-panel {
  padding: 22px;
}

.task-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.info-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.info-block.wide,
.wide {
  grid-column: 1 / -1;
}

.info-block h3,
.material-card h3,
.argument-card h3,
.plan-section h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.info-block p,
.material-card p,
.plan-section p,
.plan-section li {
  margin: 0;
  line-height: 1.55;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.form-grid.compact {
  padding: 0;
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: var(--ink);
  font-weight: 700;
  font-size: 0.92rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d3d2;
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
  min-height: 42px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(40, 117, 106, 0.22);
  outline-offset: 2px;
}

.material-list {
  display: grid;
  gap: 14px;
}

.material-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.material-card .material-body {
  line-height: 1.55;
}

.material-card .material-body p {
  margin: 0;
}

.material-card figure {
  margin: 14px 0;
}

.material-card img,
.material-card svg {
  display: block;
  width: 100%;
  max-width: 760px;
  max-height: 520px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.material-card figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.material-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.86rem;
}

.material-excerpt {
  padding-left: 14px;
  border-left: 4px solid var(--accent);
}

.analysis-toolbar {
  padding: 18px 22px 0;
  display: grid;
  grid-template-columns: minmax(220px, 420px) minmax(0, 1fr);
  gap: 14px;
  align-items: end;
}

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

.material-export-preview {
  margin: 0 22px 22px;
  padding: 18px;
  display: grid;
  gap: 14px;
  border: 1px solid rgba(179, 95, 18, 0.24);
  border-radius: 8px;
  background: #fffaf4;
}

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

.material-export-head h3 {
  margin: 2px 0 0;
  font-size: 1.05rem;
}

.material-export-preview textarea {
  min-height: 210px;
  background: #fff;
  border-color: rgba(179, 95, 18, 0.28);
}

.argument-list {
  display: grid;
  gap: 16px;
}

.argument-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

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

.primary-button,
.ghost-button,
.ghost-light-button,
.icon-button {
  border-radius: 8px;
  min-height: 40px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.primary-button {
  background: var(--action);
  border-color: var(--action);
  color: #fff;
  box-shadow: 0 8px 18px rgba(31, 111, 178, 0.24);
}

.primary-button:hover {
  background: var(--action-dark);
  border-color: var(--action-dark);
  box-shadow: 0 10px 22px rgba(21, 84, 138, 0.3);
}

.ghost-button {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.34);
}

.ghost-button:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.68);
}

.ghost-light-button {
  background: var(--action-soft);
  color: var(--action-dark);
  border-color: rgba(31, 111, 178, 0.32);
  box-shadow: 0 6px 14px rgba(31, 111, 178, 0.12);
}

.ghost-light-button:hover {
  background: #d9ebfa;
  border-color: var(--action);
  box-shadow: 0 8px 18px rgba(31, 111, 178, 0.18);
}

.icon-button {
  width: 40px;
  padding: 0;
  border-color: rgba(161, 61, 61, 0.28);
  background: #fff4f4;
  color: var(--danger);
  font-size: 1.4rem;
  line-height: 1;
}

.icon-button:hover {
  background: #f9dfdf;
  border-color: var(--danger);
}

.primary-button:hover,
.ghost-light-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-button:active,
.ghost-light-button:active,
.icon-button:active {
  transform: translateY(0);
}

.analysis-export-actions .ghost-light-button,
.export-actions .ghost-light-button {
  background: var(--export-soft);
  color: var(--export-dark);
  border-color: rgba(179, 95, 18, 0.42);
  box-shadow: 0 6px 14px rgba(179, 95, 18, 0.13);
}

.analysis-export-actions .ghost-light-button:hover,
.export-actions .ghost-light-button:hover {
  background: #ffe0bf;
  border-color: var(--export);
  box-shadow: 0 8px 18px rgba(179, 95, 18, 0.2);
}

.check-list {
  display: grid;
  gap: 12px;
}

.check-item {
  border: 1px solid var(--line);
  border-left-width: 6px;
  border-radius: 8px;
  padding: 14px 16px;
  background: #fff;
}

.check-item.ok {
  border-left-color: var(--ok);
}

.check-item.warn {
  border-left-color: var(--warn);
}

.check-item.danger {
  border-left-color: var(--danger);
}

.check-item strong {
  display: block;
  margin-bottom: 4px;
}

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

.writing-plan {
  display: grid;
  gap: 14px;
}

.plan-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.plan-section ul {
  margin: 0;
  padding-left: 20px;
}

.empty-state {
  border: 1px dashed #b8c6c5;
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: #fbfcfc;
}

.export-panel {
  display: grid;
  gap: 16px;
}

.export-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.prompt-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.prompt-preview h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.prompt-preview textarea {
  min-height: 260px;
  background: #fbfcfc;
}

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

.load-error {
  padding: 22px;
  color: var(--danger);
}

@media (max-width: 900px) {
  .app-header,
  .section-head {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .analysis-toolbar {
    grid-template-columns: 1fr;
  }

  .analysis-export-actions {
    justify-content: flex-start;
  }

  .material-export-head {
    flex-direction: column;
  }

  .topic-panel {
    position: static;
  }

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

@media (max-width: 640px) {
  .workspace {
    padding: 10px;
  }

  .topic-list,
  .task-grid,
  .form-grid,
  .prompt-grid {
    grid-template-columns: 1fr;
  }

  .panel-head,
  .section-head,
  .task-grid,
  .form-grid,
    .material-list,
    .argument-list,
    .check-list,
    .writing-plan,
    .material-export-preview,
    .export-panel {
    padding: 16px;
  }

  .material-export-preview {
    margin: 0 16px 16px;
  }

  .header-actions {
    justify-content: flex-start;
  }
}
