:root {
  --bg: #0e0f11;
  --surface: #17191c;
  --surface-2: #1f2226;
  --border: #2a2e33;
  --border-soft: #23262b;
  --text: #e9eaec;
  --text-muted: #9aa0a8;
  --text-faint: #6b727b;
  --accent: #f4f4f5;
  --accent-ink: #0e0f11;
  --rec: #e5484d;
  --rec-dim: #3a2122;
  --ok: #46b17b;
  --warn: #d8a24a;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f6f5;
    --surface: #ffffff;
    --surface-2: #f0f0ef;
    --border: #e2e2e0;
    --border-soft: #ececea;
    --text: #18191b;
    --text-muted: #5c626b;
    --text-faint: #8a909a;
    --accent: #18191b;
    --accent-ink: #ffffff;
    --rec-dim: #fbe9ea;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.08);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 20px 48px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 18px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--text);
  position: relative;
  flex: none;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 0;
  margin: auto;
  width: 11px; height: 16px;
  border-radius: 6px;
  background: var(--bg);
}
.brand-text h1 { font-size: 19px; margin: 0; letter-spacing: -0.02em; }
.brand-text p { font-size: 12.5px; margin: 0; color: var(--text-muted); }
.topbar-actions { display: flex; gap: 6px; }

/* Buttons */
button { font-family: inherit; cursor: pointer; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  transition: border-color .15s, background .15s;
}
.btn-ghost:hover { border-color: var(--text-faint); background: var(--surface-2); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14.5px;
  font-weight: 600;
  width: 100%;
  transition: opacity .15s, transform .05s;
}
.btn-primary.btn-sm { width: auto; padding: 9px 16px; }
.btn-primary:hover { opacity: .9; }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }

/* Views / cards */
main { flex: 1; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -0.02em; }
.muted { color: var(--text-muted); font-size: 14px; margin: 0 0 22px; }

/* Fields */
.field { margin-bottom: 18px; }
.field > label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 7px;
  letter-spacing: .01em;
}
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 14.5px;
  font-family: inherit;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--text-faint);
}
textarea { resize: vertical; line-height: 1.5; }
select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' stroke='%239aa0a8' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px;
}

/* Segmented control */
.segmented { display: flex; gap: 6px; }
.segmented button {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  transition: all .15s;
}
.segmented button[aria-checked="true"] {
  background: var(--text);
  color: var(--accent-ink);
  border-color: var(--text);
  font-weight: 600;
}

.note { font-size: 13px; color: var(--text-muted); margin: 14px 0 0; min-height: 1em; }
.note.error { color: var(--rec); }
#startBtn { margin-top: 6px; }

/* Interview head */
.interview-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px; gap: 12px;
}
.chip {
  display: inline-block;
  background: var(--text);
  color: var(--accent-ink);
  padding: 4px 10px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
}
.chip-soft { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.progress { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Transcript */
.transcript {
  display: flex; flex-direction: column; gap: 14px;
  max-height: 320px; overflow-y: auto;
  padding: 4px 2px 8px;
  margin-bottom: 18px;
}
.bubble { max-width: 88%; padding: 12px 14px; border-radius: 13px; font-size: 14.5px; }
.bubble.q {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-bottom-left-radius: 4px;
}
.bubble.a {
  align-self: flex-end;
  background: var(--text);
  color: var(--accent-ink);
  border-bottom-right-radius: 4px;
}
.bubble .who { font-size: 11px; opacity: .65; font-weight: 600; margin-bottom: 3px; text-transform: uppercase; letter-spacing: .04em; }
.bubble.thinking { color: var(--text-faint); font-style: italic; }
.dots::after { content: ""; animation: dots 1.4s steps(4, end) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

/* Mic area */
.mic-area {
  border-top: 1px solid var(--border-soft);
  padding-top: 18px;
}
.status-row { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); flex: none; transition: background .2s; }
.status-dot.speaking { background: var(--warn); animation: pulse 1.2s infinite; }
.status-dot.listening { background: var(--rec); animation: pulse 1s infinite; }
.status-dot.thinking { background: var(--text-muted); animation: pulse 1.4s infinite; }
.status-dot.ready { background: var(--ok); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.status-text { font-size: 13.5px; color: var(--text-muted); flex: 1; }
#replayBtn { flex: none; }

.answer-box { margin-bottom: 14px; }

.controls { display: flex; gap: 10px; align-items: stretch; }
.btn-record {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 13px;
  font-size: 14.5px;
  font-weight: 600;
  transition: all .12s;
  user-select: none;
}
.btn-record:hover { border-color: var(--text-faint); }
.btn-record.recording {
  background: var(--rec-dim);
  border-color: var(--rec);
  color: var(--rec);
}
.rec-icon { width: 12px; height: 12px; border-radius: 50%; background: var(--rec); flex: none; }
.btn-record.recording .rec-icon { border-radius: 3px; animation: pulse 1s infinite; }

.btn-end { display: block; margin: 18px auto 0; }

/* Feedback */
.score-summary {
  display: flex; align-items: baseline; gap: 14px;
  padding: 18px 0 20px; margin-bottom: 6px;
  border-bottom: 1px solid var(--border-soft);
}
.score-big { font-size: 48px; font-weight: 700; letter-spacing: -0.03em; line-height: 1; }
.score-out { font-size: 20px; color: var(--text-faint); }
.score-verdict { font-size: 14px; color: var(--text-muted); margin-left: auto; text-align: right; max-width: 50%; }

.rubric { display: flex; flex-direction: column; gap: 14px; padding: 20px 0; }
.rubric-item .rubric-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.rubric-item .r-name { font-size: 14px; font-weight: 600; }
.rubric-item .r-score { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--surface-2); border-radius: 100px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ok); border-radius: 100px; transition: width .5s ease; }
.rubric-item .r-note { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

.feedback-body { padding-top: 8px; border-top: 1px solid var(--border-soft); }
.feedback-body h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin: 18px 0 8px; }
.feedback-body ul { margin: 0; padding-left: 20px; }
.feedback-body li { font-size: 14px; margin-bottom: 6px; }
.feedback-actions { display: flex; gap: 10px; margin-top: 24px; }
.feedback-actions .btn-primary { width: auto; flex: 1; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 460px;
  box-shadow: var(--shadow);
  max-height: 88vh; overflow-y: auto;
  animation: fade .2s ease;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-head h3 { margin: 0; font-size: 17px; }
.hint { font-size: 12.5px; color: var(--text-faint); margin: 7px 0 0; }
.hint code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }
.privacy { line-height: 1.55; }
.settings-foot { margin-top: 8px; border-top: 1px solid var(--border-soft); padding-top: 16px; }
.settings-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

/* History */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-empty { color: var(--text-muted); font-size: 14px; text-align: center; padding: 24px 0; }
.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  cursor: pointer;
  transition: border-color .15s;
}
.history-item:hover { border-color: var(--text-faint); }
.history-item .h-main { min-width: 0; }
.history-item .h-role { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.history-item .h-score { font-size: 18px; font-weight: 700; flex: none; }
.history-del { background: none; border: none; color: var(--text-faint); font-size: 18px; padding: 2px 6px; line-height: 1; }
.history-del:hover { color: var(--rec); }

/* Footer */
.footer {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 28px; padding-top: 18px;
  font-size: 12.5px; color: var(--text-faint);
}
.footer a { color: var(--text-muted); text-decoration: none; }
.footer a:hover { color: var(--text); }
.footer .dot { opacity: .5; }

@media (max-width: 540px) {
  .card { padding: 20px; }
  .score-verdict { max-width: 100%; text-align: left; margin: 8px 0 0; }
  .score-summary { flex-wrap: wrap; }
}
