:root {
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --surface-muted: #F2F4F6;
  --border: #D1D6DB;
  --text: #191F28;
  --text-muted: #4E5968;
  --accent: #1B64DA;
  --accent-soft: #E8F3FF;
  --on-accent: #FFFFFF;
  --warn: #B43403;

  --fs-2xl: 30px;
  --fs-xl: 22px;
  --fs-lg: 17px;
  --fs-md: 15px;
  --fs-sm: 13px;

  --sp-1: 8px;
  --sp-2: 12px;
  --sp-3: 16px;
  --sp-4: 24px;
  --sp-5: 32px;

  font-family: Inter, Pretendard, 'Noto Sans KR', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: var(--fs-md);
  line-height: 1.6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: var(--fs-md);
}

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

button,
a {
  touch-action: manipulation;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  padding: var(--sp-1) var(--sp-3);
  border-radius: 8px;
  font-weight: 600;
  font-size: var(--fs-md);
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
}

button:hover:not(:disabled),
a.secondary:hover {
  filter: brightness(0.96);
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

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

.ai-badge {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-1);
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1.4;
  background: var(--accent-soft);
  color: var(--accent);
}

button.primary .ai-badge {
  background: var(--surface);
  color: var(--accent);
}

button.secondary,
.secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: var(--sp-1) var(--sp-3);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
}

a {
  color: var(--accent);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

header {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  gap: var(--sp-4);
}

.brand {
  font-size: var(--fs-lg);
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.brand span {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-muted);
  margin-left: var(--sp-2);
}

#connection {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

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

aside {
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: var(--sp-4) var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.aside-title {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  font-weight: 600;
}

.project-link {
  display: block;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-radius: 8px;
  text-align: left;
  width: 100%;
  font-size: var(--fs-sm);
  line-height: 1.5;
  padding: var(--sp-2);
  margin: 0;
  font-weight: 500;
  min-height: 40px;
}

.project-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.aside-note {
  margin-top: auto;
  padding-top: var(--sp-5);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: 1.65;
}

main {
  min-width: 0;
  padding: var(--sp-5) var(--sp-5) var(--sp-5);
}

.eyebrow {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--accent);
}

h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.35;
  margin: var(--sp-2) 0 var(--sp-4);
}

h2 {
  font-size: var(--fs-lg);
  font-weight: 700;
  margin: 0 0 var(--sp-2);
  letter-spacing: -0.015em;
}

h3 {
  font-size: var(--fs-md);
  margin: var(--sp-3) 0 var(--sp-1);
  color: var(--text);
}

p {
  white-space: pre-line;
}

small {
  font-size: var(--fs-sm);
}

.intro {
  color: var(--text-muted);
  font-size: var(--fs-md);
  line-height: 1.75;
  margin-bottom: var(--sp-4);
}

#welcome {
  max-width: 760px;
  margin: var(--sp-4) auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--sp-5);
}

#welcome h1 {
  font-size: var(--fs-2xl);
}

label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
  margin-bottom: var(--sp-2);
}

textarea,
input,
select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: var(--sp-2);
  font-size: var(--fs-md);
  line-height: 1.6;
}

textarea {
  resize: vertical;
}

textarea::placeholder,
input::placeholder {
  color: var(--text-muted);
  font-weight: 400;
}

input,
select {
  margin-top: var(--sp-1);
}

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.form-footer span {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  max-width: 360px;
}

.form-footer button {
  flex-shrink: 0;
}

.work-heading {
  display: flex;
  justify-content: space-between;
  gap: var(--sp-4);
  align-items: center;
}

.work-heading h1 {
  margin-top: var(--sp-1);
}

.export {
  font-size: var(--fs-sm);
  white-space: nowrap;
}

.workflow {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border);
  margin: var(--sp-1) 0 var(--sp-4);
  gap: var(--sp-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.workflow span,
.workflow button {
  padding: var(--sp-2) var(--sp-1);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
}

.workflow .current {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.workflow .complete {
  color: var(--text);
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(330px, 1fr);
  gap: var(--sp-5);
  align-items: start;
}

.planning section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: var(--sp-4);
  margin-bottom: var(--sp-4);
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}

.section-title > span {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.synopsis {
  font-size: var(--fs-md);
  line-height: 1.75;
}

.help {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: 1.6;
}

details {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-2);
  margin-top: var(--sp-3);
}

summary {
  cursor: pointer;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 600;
  min-height: 40px;
  display: flex;
  align-items: center;
}

details p {
  font-size: var(--fs-sm);
  line-height: 1.65;
}

form {
  margin-top: var(--sp-3);
}

form > button {
  margin-top: var(--sp-2);
}

.wide {
  width: 100%;
  margin-top: var(--sp-2);
}

#plan-json {
  font-family: ui-monospace, monospace;
  font-size: var(--fs-sm);
}

.identity-list {
  display: grid;
  gap: var(--sp-3);
  margin-top: var(--sp-3);
}

.identity-list img {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.reading {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: var(--sp-4);
  min-width: 0;
  border-radius: 12px;
}

.reader-panel {
  margin-top: var(--sp-4);
}

.panel-heading {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.panel-heading > span:first-child {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: nowrap;
}

.panel-heading > strong {
  font-size: var(--fs-md);
}

.revision-note {
  font-size: var(--fs-sm);
  color: var(--warn);
}

.panel-image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.unmade {
  background: var(--surface-muted);
  min-height: 200px;
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
}

.unmade > span {
  font-size: var(--fs-2xl);
  color: var(--text-muted);
}

.unmade p {
  font-size: var(--fs-md);
}

.unmade small {
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.dialogue {
  padding: var(--sp-2) 0;
}

.dialogue p {
  font-size: var(--fs-md);
  line-height: 1.75;
  margin: var(--sp-1) 0;
}

.dialogue b {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  margin-right: var(--sp-1);
}

.download {
  font-size: var(--fs-sm);
  display: inline-block;
  margin-top: var(--sp-1);
}

.candidates {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}

.candidates img {
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.candidates button {
  width: 100%;
  font-size: var(--fs-sm);
  padding: var(--sp-1);
}

.candidates a {
  display: block;
  font-size: var(--fs-sm);
  margin-top: var(--sp-1);
}

.correct-form {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
}

.correct-form small {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 400;
  color: var(--text-muted);
}

.correct-form input {
  font-size: var(--fs-md);
}

.correct-form button {
  font-size: var(--fs-sm);
}

.gap-label {
  font-size: var(--fs-sm);
  text-align: center;
  color: var(--text-muted);
  margin-top: var(--sp-3);
}

dl {
  font-size: var(--fs-sm);
}

dt {
  color: var(--text-muted);
  font-weight: 600;
  margin-top: var(--sp-2);
}

dd {
  margin: var(--sp-1) 0 0;
}

.job {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--text);
  padding: var(--sp-2) var(--sp-3);
  border-radius: 8px;
  font-size: var(--fs-sm);
  margin: 0 0 var(--sp-3);
}

.job.failed,
.job.interrupted {
  background: var(--surface);
  border-color: var(--warn);
  color: var(--warn);
}

.job strong {
  overflow-wrap: anywhere;
}

.dot {
  width: var(--sp-1);
  height: var(--sp-1);
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
}

.job.running .dot {
  animation: pulse 1.6s infinite;
}

.job.failed .dot,
.job.interrupted .dot {
  background: var(--warn);
}

#error {
  background: var(--surface);
  border: 1px solid var(--warn);
  color: var(--warn);
  padding: var(--sp-3);
  margin-bottom: var(--sp-4);
  border-radius: 8px;
  font-size: var(--fs-sm);
}

[hidden] {
  display: none !important;
}

@keyframes pulse {
  50% {
    opacity: 0.25;
  }
}

@media (prefers-reduced-motion: reduce) {
  .job.running .dot {
    animation: none;
  }
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-1);
}

.button-row button {
  font-size: var(--fs-sm);
  padding: var(--sp-1) var(--sp-2);
}

.panel-editor,
.reference-row {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: var(--sp-3);
  margin: var(--sp-3) 0;
  background: var(--bg);
}

.panel-editor legend,
.reference-row legend {
  padding: 0 var(--sp-1);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: 700;
}

.panel-editor > .button-row {
  margin-bottom: var(--sp-3);
}

.panel-editor > .button-row button {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

#edit-plan label {
  margin-top: var(--sp-2);
}

#edit-plan textarea {
  margin-top: var(--sp-1);
}

#save-state {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  text-align: right;
}

.dialogue-row {
  border-left: 2px solid var(--border);
  padding: 0 0 var(--sp-2) var(--sp-2);
  margin: var(--sp-2) 0;
}

.dialogue-row button {
  font-size: var(--fs-sm);
  background: var(--surface);
  color: var(--warn);
  border-color: var(--border);
}

.references-form {
  border-top: 1px solid var(--border);
  padding-top: var(--sp-1);
  margin-bottom: var(--sp-4);
}

.reference-row {
  background: var(--bg);
  margin: var(--sp-2) 0;
}

.reference-thumb {
  display: block;
  width: auto;
  max-width: 100%;
  height: 120px;
  object-fit: contain;
  margin: var(--sp-2) 0;
}

.reference-row textarea {
  margin-top: var(--sp-1);
}

.work-heading > .button-row {
  justify-content: flex-end;
}

.reader-only aside,
.reader-only #connection,
.reader-only .editor-only {
  display: none !important;
}

.reader-only .shell {
  display: block;
}

.reader-only main {
  max-width: 850px;
  margin: auto;
  padding: var(--sp-4) var(--sp-4) var(--sp-5);
}

.reader-only .work-grid {
  display: block;
}

.reader-only .reading {
  border: 0;
  background: transparent;
  padding: 0;
}

.reader-only .panel-heading {
  display: none;
}

.reader-only .work-heading {
  align-items: start;
}

@media (min-width: 1400px) {
  .work-grid {
    grid-template-columns: 390px minmax(400px, 650px);
  }
  main {
    padding-left: var(--sp-5);
    padding-right: var(--sp-5);
  }
}

@media (max-width: 1050px) {
  .shell {
    grid-template-columns: 180px minmax(0, 1fr);
  }
  main {
    padding: var(--sp-4) var(--sp-3);
  }
  .work-grid {
    grid-template-columns: 1fr;
  }
  .planning {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
  }
  .brand span {
    display: none;
  }
}

@media (max-width: 640px) {
  header {
    height: auto;
    min-height: 64px;
    padding: var(--sp-2) var(--sp-3);
    flex-wrap: wrap;
    gap: var(--sp-1);
  }
  .brand {
    font-size: var(--fs-lg);
  }
  #connection {
    font-size: var(--fs-sm);
  }
  .shell {
    display: block;
  }
  aside {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: var(--sp-2) var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
  }
  .aside-title,
  .aside-note {
    display: none;
  }
  #projects {
    display: flex;
    flex-wrap: wrap;
    overflow: visible;
    gap: var(--sp-1);
  }
  .project-link {
    width: auto;
    max-width: 100%;
    padding: var(--sp-1) var(--sp-2);
    overflow-wrap: anywhere;
  }
  #new-project {
    font-size: var(--fs-sm);
    padding: var(--sp-1) var(--sp-2);
    align-self: flex-start;
  }
  main {
    padding: var(--sp-3) var(--sp-3);
  }
  #welcome {
    margin: var(--sp-3) 0;
    padding: var(--sp-3);
  }
  #welcome h1 {
    font-size: var(--fs-xl);
  }
  .form-footer {
    align-items: stretch;
    flex-direction: column;
    gap: var(--sp-2);
  }
  .work-heading {
    align-items: start;
    flex-direction: column;
    gap: var(--sp-2);
    margin-bottom: var(--sp-3);
  }
  h1 {
    font-size: var(--fs-xl);
  }
  .workflow {
    gap: var(--sp-2);
    font-size: var(--fs-sm);
  }
  .reading {
    padding: var(--sp-3);
  }
  .job {
    align-items: start;
  }
  .panel-heading {
    flex-wrap: wrap;
  }
  .intro {
    font-size: var(--fs-md);
  }
  .panel-editor,
  .reference-row {
    padding: var(--sp-2);
  }
  .work-heading > .button-row {
    justify-content: flex-start;
  }
  .reader-only main {
    padding: var(--sp-3) var(--sp-3) var(--sp-4);
  }
  .button-row button {
    min-height: 40px;
  }
  .dialogue-row {
    padding-left: var(--sp-1);
  }
  .job button {
    width: 100%;
  }
}
