:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f2430;
  --border: #2a2f3a;
  --text: #e8eaf0;
  --muted: #8a92a6;
  --accent: #6c8cff;
  --accent-dim: #2c3a6b;
  --rec: #ff5a5a;
  --ok: #46c988;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: var(--safe-bottom);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15, 17, 21, 0.85);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.topbar h1 { font-size: 20px; font-weight: 650; margin: 0; letter-spacing: 0.2px; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 22px;
  padding: 6px;
  cursor: pointer;
  border-radius: 10px;
}
.icon-btn:active { background: var(--surface-2); }

main {
  flex: 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* Recorder */
.recorder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 20px 0 8px;
}
.record-btn {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: none;
  background: radial-gradient(circle at 50% 40%, #7d99ff, var(--accent));
  box-shadow: 0 10px 30px rgba(108, 140, 255, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.record-btn:active { transform: scale(0.96); }
.record-btn .mic {
  width: 34px;
  height: 50px;
  position: relative;
  display: block;
}
.record-btn .mic::before {
  content: "";
  position: absolute;
  left: 7px; top: 0;
  width: 20px; height: 30px;
  border-radius: 10px;
  background: #fff;
}
.record-btn .mic::after {
  content: "";
  position: absolute;
  left: 0; top: 22px;
  width: 34px; height: 18px;
  border: 3px solid #fff;
  border-top: none;
  border-radius: 0 0 18px 18px;
}
.record-btn.recording {
  background: radial-gradient(circle at 50% 40%, #ff7b7b, var(--rec));
  box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.5);
  animation: pulse 1.4s infinite;
}
.record-btn.recording .mic::before,
.record-btn.recording .mic::after { display: none; }
.record-btn.recording .mic {
  width: 34px; height: 34px;
}
.record-btn.recording .mic::before {
  content: "";
  display: block;
  position: absolute;
  left: 5px; top: 5px;
  width: 24px; height: 24px;
  border-radius: 6px;
  background: #fff;
}
.record-btn.busy { opacity: 0.6; pointer-events: none; }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0.45); }
  70%  { box-shadow: 0 0 0 22px rgba(255, 90, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 90, 90, 0); }
}

.status { margin: 0; color: var(--muted); font-size: 15px; min-height: 20px; }
.status.recording { color: var(--rec); }
.status.uploading { color: var(--accent); }
.status.done { color: var(--ok); }
.status.error { color: var(--rec); }
.timer { margin: 0; font-variant-numeric: tabular-nums; font-size: 15px; color: var(--muted); }

/* Latest transcript */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin-bottom: 6px; }
.card-text { font-size: 16px; white-space: pre-wrap; word-break: break-word; }
.card-text.pending { color: var(--muted); font-style: italic; }

/* History */
.history h2 { font-size: 14px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); margin: 0 0 10px; }
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.history-item .h-time { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.history-item .h-text { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.history-item .h-text.null { color: var(--rec); font-style: italic; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Settings panel */
.panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.panel-inner {
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 22px 20px calc(22px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel-inner h2 { margin: 0 0 4px; font-size: 18px; }
.panel-inner label { font-size: 13px; color: var(--muted); }
.panel-inner input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 16px;
}
.panel-inner input:focus { outline: none; border-color: var(--accent); }
.panel-actions { display: flex; gap: 10px; }

.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.full { flex: none; width: 100%; }
.btn:active { filter: brightness(1.15); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 30;
  max-width: 90vw;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

[hidden] { display: none !important; }
