:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #eef2f6;
  --ink: #1c2430;
  --muted: #687486;
  --line: #cfd7e2;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #dff4f1;
  --warn: #a15c12;
  --shadow: 0 18px 45px rgba(28, 36, 48, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Pretendard, "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 24px;
}

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

.workspace {
  padding: 26px;
}

.result-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 56px);
}

.topbar,
.result-header,
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.15;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.65rem, 2.5vw, 2.35rem);
}

h2 {
  font-size: 1.35rem;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 16px;
  margin-bottom: 18px;
}

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

.field > span,
.mode-field > span {
  color: #344152;
  font-size: 0.92rem;
  font-weight: 750;
}

.stack-wide {
  grid-column: 1 / -1;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--ink);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input {
  min-height: 44px;
  padding: 0 13px;
}

textarea {
  resize: vertical;
  padding: 13px;
  line-height: 1.62;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.segmented {
  min-height: 44px;
  padding: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.segmented input:checked + span {
  background: var(--accent);
  color: #ffffff;
}

.script-field {
  margin-top: 8px;
}

.action-row {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 18px;
}

button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button,
.ghost-button {
  background: #ffffff;
  color: var(--ink);
  border-color: var(--line);
}

.secondary-button:hover,
.ghost-button:hover {
  background: var(--surface-strong);
}

.count-badge {
  min-width: 54px;
  min-height: 30px;
  padding: 5px 10px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 850;
  font-size: 0.88rem;
}

.result-output {
  flex: 1;
  min-height: 460px;
  margin-top: 18px;
  background: #111827;
  border-color: #111827;
  color: #f8fafc;
  line-height: 1.72;
}

.result-output:focus {
  border-color: #374151;
  box-shadow: 0 0 0 3px rgba(17, 24, 39, 0.16);
}

.status-text {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.status-text.warning {
  color: var(--warn);
}

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

  .result-panel {
    min-height: 560px;
  }
}

@media (max-width: 620px) {
  .workspace,
  .result-panel {
    padding: 18px;
  }

  .topbar,
  .result-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .mode-field,
  .number-field {
    grid-column: 1 / -1;
  }

  button {
    width: 100%;
  }
}

.api-key-field {
  grid-column: span 1;
}

.model-field {
  grid-column: span 1;
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

@media (max-width: 620px) {
  .api-key-field,
  .model-field {
    grid-column: 1 / -1;
  }
}

.token-estimate {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.token-estimate.warning {
  border-color: rgba(161, 92, 18, 0.35);
  background: #fff7ed;
  color: var(--warn);
}

body.dark-mode {
  color-scheme: dark;
  --bg: #101418;
  --surface: #171d24;
  --surface-strong: #222b35;
  --ink: #edf2f7;
  --muted: #a8b3c2;
  --line: #344252;
  --accent: #2dd4bf;
  --accent-dark: #5eead4;
  --accent-soft: #123c39;
  --warn: #f8b45f;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.32);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

body.dark-mode input,
body.dark-mode textarea,
body.dark-mode .secondary-button,
body.dark-mode .ghost-button {
  background: #121821;
  color: var(--ink);
  border-color: var(--line);
}

body.dark-mode input:focus,
body.dark-mode textarea:focus {
  background: #10161f;
  box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.16);
}

body.dark-mode .field > span,
body.dark-mode .mode-field > span {
  color: #d4dde8;
}

body.dark-mode .segmented {
  background: #10161f;
}

body.dark-mode .segmented span {
  color: #b6c2d0;
}

body.dark-mode .segmented input:checked + span {
  background: #0f766e;
  color: #ffffff;
}

body.dark-mode .secondary-button:hover,
body.dark-mode .ghost-button:hover {
  background: #222b35;
}

.result-output,
.result-output:hover,
.result-output:active,
.result-output:focus {
  background: #111827;
  color: #f8fafc;
  caret-color: #f8fafc;
}

.result-output::selection {
  background: #2dd4bf;
  color: #082f2c;
}

body.dark-mode .result-output,
body.dark-mode .result-output:hover,
body.dark-mode .result-output:active,
body.dark-mode .result-output:focus {
  background: #05070a;
  border-color: #263241;
  color: #f8fafc;
}

body.dark-mode .token-estimate {
  background: #10161f;
  color: var(--muted);
}

body.dark-mode .token-estimate.warning {
  background: #2a1b0c;
  border-color: rgba(248, 180, 95, 0.35);
  color: var(--warn);
}

@media (max-width: 620px) {
  .top-actions {
    width: 100%;
  }
}

.result-output {
  overflow: auto;
  white-space: normal;
  outline: none;
}

.result-output:empty::before {
  content: attr(data-placeholder);
  color: #9ca3af;
}

.scenario-line {
  color: #ffffff;
  font-weight: 850;
}

.scenario-line strong {
  font-weight: 850;
}

.result-output {
  width: 100%;
  border: 1px solid #111827;
  border-radius: 8px;
  padding: 13px;
}

.result-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.scenario-bold-toggle,
.scenario-color-picker {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.scenario-bold-toggle input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.scenario-color-picker input {
  width: 34px;
  height: 28px;
  min-height: 28px;
  padding: 2px;
  border-radius: 6px;
  background: transparent;
}

.scenario-line {
  color: var(--scenario-color, #ffffff);
}

.result-output.scenario-bold-off .scenario-line {
  font-weight: 400;
}

@media (max-width: 620px) {
  .result-tools {
    width: 100%;
    justify-content: flex-start;
  }
}
