:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dfe4ec;
  --text: #1c2430;
  --text-muted: #5f6b7c;
  --accent: #1f6feb;
  --accent-dark: #1659c4;
  --ok: #1a7f52;
  --warn: #9a5b00;
  --mark: #ffe7a8;
  --mark-weak: #f0f0f0;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
               "Malgun Gothic", "Noto Sans KR", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}

/* --------------------------------------------------------------- login --- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
}

.auth-card h1 { margin: 0; font-size: 19px; letter-spacing: -.01em; }
.auth-subtitle { margin: 4px 0 20px; color: var(--text-muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }

.tab {
  padding: 9px 14px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.tab-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.auth-form { display: flex; flex-direction: column; gap: 6px; }
.auth-form label { font-size: 13px; font-weight: 600; margin-top: 10px; }
.auth-form .hint { font-weight: 400; color: var(--text-muted); }

.auth-form input {
  padding: 11px 12px;
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fcfdff;
}

.auth-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.auth-form button { margin-top: 18px; }

.auth-help { margin: 16px 0 0; font-size: 12.5px; color: var(--text-muted); }

.alert { margin: 0 0 14px; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.alert-error { background: #fdeceb; color: #a3261c; }
.alert-ok { background: #e8f6ee; color: var(--ok); }

/* --------------------------------------------------------------- shell --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left { display: flex; align-items: baseline; gap: 8px; min-width: 0; overflow: hidden; }
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.reader-name { font-size: 13px; color: var(--text-muted); }
.logout-form { margin: 0; }

/* Narrow phones have no room for the subtitle next to the reader name. */
@media (max-width: 520px) {
  .brand { font-size: 14px; }
  .brand-sub { display: none; }
}

.progressbar { height: 3px; background: var(--border); }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .25s ease; }

.statusbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.status-left { display: flex; align-items: baseline; gap: 10px; }
.position-label { font-weight: 700; font-size: 15px; }
.progress-label { font-size: 12.5px; color: var(--text-muted); }
.status-right { display: flex; align-items: center; gap: 8px; }
.jump-label { font-size: 12.5px; color: var(--text-muted); }

.jump-input {
  width: 74px;
  padding: 5px 8px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.save-state { font-size: 12.5px; color: var(--text-muted); min-width: 88px; text-align: right; }
.save-state[data-state="saving"] { color: var(--accent); }
.save-state[data-state="saved"] { color: var(--ok); }
.save-state[data-state="error"] { color: #a3261c; font-weight: 600; }

/* ---------------------------------------------------------------- grid --- */
.study {
  display: grid;
  gap: 14px;
  padding: 14px 16px 96px;
  max-width: 1500px;
  margin: 0 auto;
}

@media (min-width: 1000px) {
  .study {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
  }
  .panel-answer { grid-column: 1 / -1; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  min-width: 0;
}

.panel-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}

.panel-note { font-size: 11.5px; font-weight: 400; text-transform: none; letter-spacing: 0; }

/* -------------------------------------------------------------- source --- */
.source-blocks { display: flex; flex-direction: column; gap: 12px; }
.source-label { font-size: 11.5px; font-weight: 700; color: var(--text-muted); margin-bottom: 4px; }

.source-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15px;
  line-height: 1.85;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #fbfcfe;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.source-text mark {
  background: var(--mark);
  border-radius: 3px;
  padding: 1px 2px;
  cursor: pointer;
  border-bottom: 2px solid #e0b64a;
}

.source-text mark[data-quality="fuzzy"] { background: var(--mark-weak); border-bottom-color: #c9ccd2; }
.source-text mark[data-active="1"] { background: #ffd166; outline: 2px solid #c98a00; }

.evidence-detail {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #fff8e6;
  border: 1px solid #f0dca8;
  border-radius: 8px;
  font-size: 13.5px;
}

.evidence-detail .evidence-tag { font-weight: 700; color: var(--warn); margin-right: 6px; }

/* ----------------------------------------------------------------- llm --- */
.llm-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 999px;
  background: #eef4ff;
  border: 1px solid #cfe0ff;
  font-size: 14px;
}

.chip-key { font-size: 11px; font-weight: 700; color: var(--accent-dark); text-transform: uppercase; }
.chip-value { font-weight: 700; }

.llm-field { margin-bottom: 12px; font-size: 14.5px; }
.llm-field:last-of-type { margin-bottom: 0; }
.llm-field-label { font-size: 11.5px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.llm-field-body { margin-top: 3px; }
.llm-empty { color: var(--text-muted); font-style: italic; }

.llm-events { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.llm-events summary { cursor: pointer; font-size: 13px; color: var(--accent-dark); }

.event-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.event-table th, .event-table td { text-align: left; padding: 5px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.event-table th { font-size: 11px; text-transform: uppercase; color: var(--text-muted); letter-spacing: .04em; }
.event-table tr[data-has-span="1"] { cursor: pointer; }
.event-table tr[data-active="1"] { background: #fff8e6; }

/* -------------------------------------------------------------- answer --- */
.answer-form { display: grid; gap: 16px; }

@media (min-width: 760px) {
  .answer-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.question-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 13px 14px;
  background: #fcfdff;
}

.question-group.is-excluded { background: #f6f7f9; color: var(--text-muted); }
.question-title { font-size: 13.5px; font-weight: 700; margin: 0 0 10px; }
.question-sub { font-size: 12.5px; font-weight: 400; color: var(--text-muted); }
.field { margin-top: 12px; }
.field:first-of-type { margin-top: 0; }
.field-label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.field-label .required { color: #c0392b; margin-left: 2px; }
.options { display: flex; flex-wrap: wrap; gap: 6px; }

.options input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.option-chip {
  display: inline-block;
  padding: 8px 12px;
  min-height: 40px;
  line-height: 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.option-chip:hover { border-color: #b9c4d6; }

.options input[type="radio"]:checked + .option-chip {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.options input[type="radio"]:focus-visible + .option-chip { outline: 2px solid var(--accent); outline-offset: 2px; }

.option-chip.option-narrow { min-width: 44px; text-align: center; }
.scale-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 5px; }

/* ----------------------------------------------------------------- nav --- */
.navbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.nav-hint { font-size: 12.5px; color: var(--text-muted); text-align: center; flex: 1; }

.btn {
  font: inherit;
  padding: 11px 18px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-quiet { background: transparent; border-color: var(--border); color: var(--text-muted); padding: 6px 11px; min-height: 0; font-size: 13px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%);
  z-index: 10;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: #22303f;
  color: #fff;
  font-size: 13.5px;
  box-shadow: var(--shadow);
}

.toast[data-tone="warn"] { background: #8a5300; }
.toast[data-tone="error"] { background: #a3261c; }
