:root {
  --bg: #FAF8F3;
  --surface: #FFFFFF;
  --surface-2: #F4F1EA;
  --border: #E6E1D7;
  --border-strong: #CFC8B9;
  --text: #1A1A1A;
  --text-sub: #5E5C56;
  --text-faint: #9A968C;
  --accent: #2E3140;
  --accent-soft: #EDECE6;
  --danger: #B23A48;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
}

.theme-dark {
  --bg: #1B1A17;
  --surface: #25231F;
  --surface-2: #2D2B26;
  --border: #3A372F;
  --border-strong: #4F4B42;
  --text: #E9E5DA;
  --text-sub: #B0AC9F;
  --text-faint: #75716A;
  --accent: #C9C1AC;
  --accent-soft: #2F2C26;
  --danger: #D98591;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 6px 18px rgba(0,0,0,0.25);
}

.theme-dark .brand-mark { background: var(--accent); }
.theme-dark .brand-mark::after { background: var(--bg); }
.theme-dark .lang-chip.on,
.theme-dark .preset-chip.on,
.theme-dark .copy-btn.copied,
.theme-dark .copy-all-btn.copied {
  color: var(--bg);
}
.theme-dark .primary { color: var(--bg); }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-feature-settings: "ss02", "ss03";
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.55;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--accent);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 2px;
  background: var(--bg);
}

.site-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 8px;
  font-family: inherit;
}
.link-btn:hover { color: var(--text); }

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 28px 24px 80px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

textarea#src {
  width: 100%;
  border: 1px solid transparent;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: inherit;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  resize: vertical;
  min-height: 96px;
  transition: background 120ms ease, border-color 120ms ease;
}
textarea#src:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--border-strong);
}

.lang-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.lang-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-sub);
  font-size: 13px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
  font-family: inherit;
}
.lang-chip:hover { border-color: var(--border-strong); color: var(--text); }
.lang-chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.lang-chip .native { font-size: 12px; opacity: 0.7; }
.lang-chip.on .native { opacity: 0.9; }

.lang-more {
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-sub);
}

.actions-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 22px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: -0.01em;
  transition: opacity 120ms ease, transform 120ms ease;
}
.primary:hover { opacity: 0.9; }
.primary:active { transform: translateY(1px); }
.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.hint {
  font-size: 13px;
  color: var(--text-faint);
}

.results {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  transition: border-color 120ms ease;
}
.result-card:hover { border-color: var(--border-strong); }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-lang {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.card-lang .native {
  font-weight: 400;
  color: var(--text-sub);
  margin-left: 6px;
  font-size: 13px;
}

.copy-btn {
  background: var(--surface-2);
  border: 1px solid transparent;
  color: var(--text-sub);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.copy-btn:hover { background: var(--accent-soft); color: var(--text); }
.copy-btn.copied { background: var(--accent); color: #fff; }

.card-body {
  font-size: 16px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  padding: 6px 0 10px;
}

.card-body[dir="rtl"] {
  text-align: right;
}

.card-variants {
  display: grid;
  gap: 8px;
  padding: 8px 0;
}
.variant-row {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.variant-label {
  font-size: 11px;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}
.variant-text {
  font-size: 15px;
  white-space: pre-wrap;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.action-chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-sub);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.action-chip:hover { background: var(--accent-soft); color: var(--text); border-color: var(--border-strong); }
.action-chip:disabled { opacity: 0.4; cursor: wait; }

.card-loading {
  font-size: 12px;
  color: var(--text-faint);
  padding: 4px 0;
}

.empty-state {
  text-align: center;
  color: var(--text-faint);
  font-size: 14px;
  padding: 32px 0;
}

.error-banner {
  background: #FBEEEF;
  color: var(--danger);
  border: 1px solid #F0D4D8;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-top: 14px;
  font-size: 13px;
}

.modal {
  border: none;
  border-radius: var(--radius);
  padding: 22px 24px;
  max-width: 560px;
  width: calc(100% - 32px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.18);
  background: var(--surface);
  color: var(--text);
}
.modal::backdrop { background: rgba(20, 20, 18, 0.4); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.modal h2 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}

.modal-wide {
  max-width: 680px;
  max-height: 80vh;
  overflow-y: auto;
}

.history-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface-2);
  transition: border-color 120ms ease;
}
.history-row:hover { border-color: var(--border-strong); }

.history-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--text-faint);
}

.history-preview {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}

.history-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}

/* ----- card chat (multi-turn refinement) ----- */

.chat-toggle {
  background: transparent;
  border: 1px dashed var(--border-strong);
  color: var(--text-sub);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  margin-top: 6px;
}
.chat-toggle:hover { color: var(--text); border-color: var(--accent); }
.chat-toggle.on { color: var(--text); border-style: solid; border-color: var(--accent); }

.card-chat {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.chat-msg {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  line-height: 1.55;
  max-width: 90%;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
}
.theme-dark .chat-msg.user { color: var(--bg); }
.chat-msg.assistant {
  background: var(--surface-2);
  color: var(--text);
  align-self: flex-start;
}
.chat-msg.assistant .chat-revision {
  display: block;
  margin-top: 6px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-weight: 500;
}
.chat-msg.assistant .chat-apply {
  display: inline-block;
  margin-top: 6px;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  font-family: inherit;
  text-decoration: underline;
}
.theme-dark .chat-msg.assistant .chat-apply { color: var(--accent); }

.chat-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  min-height: 36px;
  max-height: 120px;
  color: var(--text);
}
.chat-input-row textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
}
.chat-send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.theme-dark .chat-send { color: var(--bg); }
.chat-send:disabled { opacity: 0.5; cursor: wait; }

.help-list {
  padding-left: 18px;
  margin: 8px 0 0;
  color: var(--text-sub);
  font-size: 13.5px;
  line-height: 1.65;
}
.help-list b { color: var(--text); }
.help-list.compact li { margin-bottom: 2px; }

.help-body h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 18px 0 4px;
  letter-spacing: -0.01em;
}
.help-body h3:first-child { margin-top: 6px; }
.help-body p {
  color: var(--text-sub);
  font-size: 13.5px;
  line-height: 1.65;
  margin: 6px 0;
}
.help-body p.hint {
  color: var(--text-faint);
  font-size: 12.5px;
  margin-top: 2px;
}
.help-body code {
  background: var(--surface-2);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
}
.help-code {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 6px 0;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-sub);
  white-space: pre-wrap;
}

@media (max-width: 600px) {
  .container { padding: 18px 14px 60px; }
  .panel { padding: 16px; }
  textarea#src { font-size: 15px; }
}

/* ----- login ----- */

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-wrap {
  width: 100%;
  max-width: 360px;
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.login-brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-sub {
  margin: 0 0 22px;
  color: var(--text-sub);
  font-size: 14px;
}

.login-field {
  display: block;
  margin-bottom: 14px;
}

.login-field span {
  display: block;
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 6px;
}

.login-field input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  transition: border-color 120ms ease, background 120ms ease;
}
.login-field input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
}

#login-btn {
  width: 100%;
  margin-top: 4px;
}

.login-error {
  margin-top: 12px;
  min-height: 18px;
  font-size: 13px;
  color: var(--danger);
}

/* ----- input panel additions (multi-cue, toggles, presets) ----- */

.options-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  align-items: center;
  margin-top: 14px;
}

.preset-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.preset-label {
  font-size: 12px;
  color: var(--text-faint);
}

.preset-chip {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-sub);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.preset-chip:hover { border-color: var(--border-strong); color: var(--text); }
.preset-chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-sub);
  cursor: pointer;
  user-select: none;
}
.toggle-inline input { accent-color: var(--accent); }

.subject-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px 8px;
  font-size: 13px;
  color: var(--text);
  font-family: inherit;
}

.cue-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--surface);
  margin-top: 12px;
  box-shadow: var(--shadow);
}

.cue-source {
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 8px;
  word-break: break-word;
}
.cue-source-label {
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 6px;
}

.cue-broadcast {
  display: flex;
  gap: 6px;
  align-items: stretch;
  margin: 4px 0 12px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.cue-broadcast input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  outline: none;
}
.cue-broadcast input::placeholder { color: var(--text-faint); }
.cue-broadcast button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.theme-dark .cue-broadcast button { color: var(--bg); }
.cue-broadcast button:disabled { opacity: 0.5; cursor: wait; }

.cue-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 16px 4px 8px;
}
.results-toolbar h2 {
  margin: 0;
  font-size: 13px;
  color: var(--text-sub);
  font-weight: 500;
}
.copy-all-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-sub);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.copy-all-btn:hover { border-color: var(--border-strong); color: var(--text); }
.copy-all-btn.copied { background: var(--accent); color: #fff; border-color: var(--accent); }

.char-count {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-faint);
  text-align: right;
}
.char-count.over {
  color: var(--danger);
  font-weight: 500;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 8px;
  font-family: inherit;
}
.logout-btn:hover { color: var(--text-sub); }

/* loading dots */
@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}
.dot {
  display: inline-block;
  width: 4px;
  height: 4px;
  margin: 0 1px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.2s infinite both;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
