:root {
  --bg: #15171A;
  --bg-panel: #1D2024;
  --bg-panel-raised: #24282D;
  --accent-brass: #B8863B;
  --accent-brass-bright: #D3A055;
  --accent-teal: #5FA8A0;
  --text-primary: #EDEAE3;
  --text-secondary: #93959B;
  --text-tertiary: #5C5F66;
  --border: #2C3036;
  --danger: #C1584A;

  --font-display: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif SC", "Songti SC", serif;
  --font-body: -apple-system, "Hiragino Sans", "Yu Gothic", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100dvh;
}

button, select, input {
  font-family: inherit;
  color: inherit;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: calc(var(--safe-bottom) + 12px);
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 8px;
  gap: 10px;
}

.wordmark { display: flex; align-items: baseline; gap: 8px; }
.wordmark-cjk {
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.08em;
  color: var(--text-primary);
}
.wordmark-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-tertiary);
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  flex: 1;
  justify-content: center;
  min-width: 0;
}
.status-pill span#statusText {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-tertiary);
  flex-shrink: 0;
}
.status-pill[data-state="ready"] .status-dot { background: var(--accent-teal); box-shadow: 0 0 6px var(--accent-teal); }
.status-pill[data-state="recording"] .status-dot { background: var(--danger); box-shadow: 0 0 6px var(--danger); animation: pulse 1s infinite; }
.status-pill[data-state="loading"] .status-dot,
.status-pill[data-state="processing"] .status-dot { background: var(--accent-brass-bright); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.35; } }

.icon-btn {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-secondary);
  flex-shrink: 0;
  touch-action: manipulation;
}
.icon-btn:active { background: var(--bg-panel-raised); }

/* ---------- Stage ---------- */
.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 18px 8px;
}

.recorder {
  position: relative;
  width: min(280px, 68vw);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.grooves {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    repeating-radial-gradient(
      circle at center,
      transparent 0,
      transparent 12px,
      rgba(184,134,59,0.12) 13px,
      transparent 14px
    );
}

#waveCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.mic-btn {
  position: relative;
  width: 92px; height: 92px;
  border-radius: 50%;
  background: var(--accent-brass);
  border: none;
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 24px rgba(184,134,59,0.35);
  touch-action: manipulation;
  transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
}
.mic-btn:active { transform: scale(0.96); }
.mic-btn:disabled { background: var(--bg-panel-raised); color: var(--text-tertiary); box-shadow: none; }
.mic-btn[data-recording="true"] {
  background: var(--danger);
  box-shadow: 0 8px 28px rgba(193,88,74,0.45);
}

.hint {
  margin: 18px 0 4px;
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
}
.timer {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-tertiary);
  min-height: 18px;
}

/* ---------- Result panel ---------- */
.result-panel {
  margin: 14px 18px 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px 14px;
}
.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent;
  border: none;
  font-size: 13px;
  color: var(--text-tertiary);
  padding: 6px 10px;
  border-radius: 8px;
  touch-action: manipulation;
}
.tab.active { color: var(--text-primary); background: var(--bg-panel-raised); }

.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 8px;
  touch-action: manipulation;
}
.ghost-btn:active { background: var(--bg-panel-raised); }

.result-body {
  min-height: 96px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.result-body:empty::before {
  content: attr(data-placeholder);
  color: var(--text-tertiary);
}
.result-body[hidden] { display: none; }

/* ---------- History ---------- */
.history-panel {
  margin: 16px 18px 0;
  padding-bottom: 8px;
  flex: 1;
}
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.history-header h2 {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  margin: 0;
}
.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.history-item {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  touch-action: manipulation;
}
.history-item:active { background: var(--bg-panel-raised); }
.history-item .row1 { display: flex; justify-content: space-between; gap: 8px; }
.history-item .snippet {
  font-size: 13.5px;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item .ts {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.empty-note { color: var(--text-tertiary); font-size: 13px; text-align: center; margin: 20px 0; }

/* ---------- Settings drawer (bottom sheet on mobile) ---------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}
.scrim.visible { opacity: 1; pointer-events: auto; }

.settings-drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(20px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.25s ease;
  z-index: 21;
  max-height: 82dvh;
  overflow-y: auto;
}
.settings-drawer.open { transform: translateY(0); }
.drawer-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--border);
  margin: 6px auto 14px;
}
.settings-drawer h2 {
  font-size: 15px;
  margin: 0 0 16px;
  color: var(--text-primary);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.field select {
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-primary);
}
.switch-field {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.switch-field input { width: 20px; height: 20px; }

.privacy-note {
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-tertiary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 16px;
}

.primary-btn {
  width: 100%;
  background: var(--accent-brass);
  color: var(--bg);
  border: none;
  border-radius: 12px;
  padding: 13px;
  font-size: 14px;
  font-weight: 600;
  touch-action: manipulation;
}
.primary-btn:active { background: var(--accent-brass-bright); }

/* Desktop: side drawer instead of bottom sheet */
@media (min-width: 720px) {
  .settings-drawer {
    left: auto;
    right: 0; top: 0; bottom: 0;
    max-width: 340px;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border-left: 1px solid var(--border);
    border-right: none;
    transform: translateX(100%);
    padding: 24px 22px;
  }
  .settings-drawer.open { transform: translateX(0); }
  .drawer-handle { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
