:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #17607d;
  --accent-weak: #e6f2f6;
  --danger: #b42318;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
}

html[data-theme='dark'] {
  --bg: #16181c;
  --surface: #1f2227;
  --text: #e8eaed;
  --muted: #a0a6b0;
  --line: #30343b;
  --accent: #7fd1e8;
  --accent-weak: #1b3a45;
  --danger: #ff8a7a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
}

.shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

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

.mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 700;
  flex: none;
}

.brand-text { min-width: 0; }
.brand-text h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: 0.01em; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  flex: none;
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: var(--accent);
  border: 1px solid transparent;
}

.content { flex: 1; padding: 14px 16px 24px; display: flex; flex-direction: column; gap: 12px; }

.state { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 40px 8px; text-align: center; }
.state h2 { font-size: 16px; margin: 0; }
.state.error h2 { color: var(--danger); }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--line); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

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

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 14px; font-weight: 650; }

.chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}

.field-group { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0 0 12px; }
.field-group legend { font-size: 12px; color: var(--muted); padding: 0 4px; }

.option { display: flex; gap: 10px; align-items: flex-start; padding: 7px 0; cursor: pointer; }
.option input { margin-top: 3px; accent-color: var(--accent); }
.option span { display: flex; flex-direction: column; gap: 1px; }
.option strong { font-weight: 600; font-size: 14px; }
.option small { color: var(--muted); font-size: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > label { font-size: 13px; font-weight: 600; }
.field .muted { font-weight: 400; }

select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.7; }
select:focus-visible, textarea:focus-visible, button:focus-visible, input:focus-visible, .history-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
select:disabled, textarea:disabled, input:disabled { opacity: 0.6; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

button {
  font: inherit;
  font-size: 13px;
  border-radius: 10px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
html[data-theme='dark'] button.primary { color: #08222b; }
button.ghost { background: transparent; }
button.small { padding: 4px 10px; min-height: 28px; font-size: 12px; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.status { min-height: 18px; margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.status[data-tone='error'] { color: var(--danger); }
.status[data-tone='ok'] { color: var(--accent); }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.history-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); cursor: pointer; font: inherit;
}
.history-item .phrase { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .when { color: var(--muted); font-size: 12px; flex: none; }

.record-phrase { margin: 0 0 4px; font-size: 18px; font-weight: 650; line-height: 1.4; word-break: break-word; }

.muted, .hint, .footnote { color: var(--muted); font-size: 12px; }
.hint { margin: 6px 0 0; }
.footnote { margin: 4px 0 0; text-align: center; }

@media (max-width: 520px) {
  .app-header { padding: 12px 12px; }
  .content { padding: 12px 12px 20px; }
  .card { padding: 12px; }
  .history { max-height: 220px; }
  .brand-text p { display: none; }
  .actions button { flex: 1 1 auto; }
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme='light']) {
    --bg: #16181c; --surface: #1f2227; --text: #e8eaed; --muted: #a0a6b0;
    --line: #30343b; --accent: #7fd1e8; --accent-weak: #1b3a45; --danger: #ff8a7a;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
