:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --text: #202124;
  --muted: #697071;
  --line: #ded8c8;
  --primary: #0f766e;
  --primary-dark: #0a5c56;
  --primary-soft: #d9f3ee;
  --accent: #b45309;
  --warning: #fff0c2;
  --warning-text: #6f4200;
  --danger: #b42318;
  --shadow: 0 16px 36px rgba(21, 28, 25, 0.12);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.1), transparent 210px),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 720px);
  min-height: 100vh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0 18px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.network-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: 999px;
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.network-pill.offline {
  border-color: rgba(180, 83, 9, 0.24);
  color: var(--warning-text);
  background: var(--warning);
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text);
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 8px 18px rgba(20, 30, 28, 0.08);
  cursor: pointer;
}

.language-panel {
  display: grid;
  grid-template-columns: 1fr 48px 1fr;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.language-select {
  min-width: 0;
}

.language-select label,
.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface-strong);
}

select,
input {
  min-height: 46px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 138px;
  padding: 14px;
  line-height: 1.55;
}

textarea:focus,
select:focus,
input:focus {
  border-color: var(--primary);
  outline: 3px solid rgba(15, 118, 110, 0.16);
}

.swap-button {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--primary-dark);
  background: var(--surface-strong);
  font-size: 22px;
  cursor: pointer;
}

.mode-tabs {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(72px, 1fr);
  gap: 4px;
  overflow-x: auto;
  padding: 4px;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.58);
  scrollbar-width: none;
}

.mode-tabs::-webkit-scrollbar {
  display: none;
}

.mode-tab {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.mode-tab.active {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 8px 16px rgba(15, 118, 110, 0.2);
}

.status-strip {
  min-height: 42px;
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: var(--radius);
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 13px;
  line-height: 1.35;
}

.mode-view {
  display: none;
}

.mode-view.active {
  display: grid;
  gap: 12px;
}

.translator-card,
.result-card,
.voice-panel,
.live-controls,
.conversation-controls,
.history-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 248, 0.94);
  box-shadow: var(--shadow);
}

.translator-card,
.result-card,
.voice-panel,
.live-controls,
.conversation-controls {
  padding: 14px;
}

.textarea-header,
.section-title,
.dialog-header,
.dialog-actions,
.inline-actions,
.action-row {
  display: flex;
  align-items: center;
}

.textarea-header,
.section-title,
.dialog-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  font-weight: 800;
}

.inline-actions,
.action-row,
.dialog-actions {
  gap: 8px;
}

.inline-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.action-row {
  margin-top: 10px;
}

.primary-button,
.secondary-button,
.text-button {
  min-height: 42px;
  border-radius: var(--radius);
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  border: 1px solid var(--primary);
  color: #ffffff;
  background: var(--primary);
}

.primary-button:active {
  background: var(--primary-dark);
}

.secondary-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--surface-strong);
}

.text-button {
  min-height: 34px;
  padding: 0 8px;
  border: 0;
  color: var(--primary-dark);
  background: transparent;
}

.wide {
  width: 100%;
}

.result-text {
  min-height: 110px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  white-space: pre-wrap;
  line-height: 1.6;
}

.quality-box,
.alternate-box {
  margin-top: 10px;
  border-radius: var(--radius);
  line-height: 1.45;
}

.quality-box {
  padding: 10px 12px;
  color: var(--warning-text);
  background: var(--warning);
}

.alternate-box {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fffaf0;
}

.hidden {
  display: none;
}

.voice-panel {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding-top: 18px;
}

.record-orb {
  display: grid;
  place-items: center;
  width: 132px;
  height: 132px;
  border: 2px solid rgba(15, 118, 110, 0.26);
  border-radius: 50%;
  color: var(--primary-dark);
  background:
    radial-gradient(circle at 50% 42%, #ffffff 0 35%, var(--primary-soft) 36% 100%);
  font-size: 18px;
  font-weight: 900;
}

.record-orb.recording {
  border-color: var(--danger);
  color: var(--danger);
  animation: pulse 1.1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(180, 35, 24, 0.25);
  }
  50% {
    transform: scale(1.035);
    box-shadow: 0 0 0 16px rgba(180, 35, 24, 0);
  }
}

.hint {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

.capability-box {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(180, 83, 9, 0.28);
  border-radius: var(--radius);
  color: var(--warning-text);
  background: var(--warning);
  font-size: 13px;
  line-height: 1.45;
  text-align: left;
}

.capability-box.ok {
  border-color: rgba(15, 118, 110, 0.24);
  color: var(--primary-dark);
  background: var(--primary-soft);
}

.live-controls {
  display: grid;
  gap: 12px;
}

.conversation-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.toggle-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--primary);
}

.live-feed,
.conversation-feed,
.phrase-list,
.history-list {
  display: grid;
  gap: 10px;
}

.live-feed,
.conversation-feed {
  min-height: 260px;
}

.live-item,
.conversation-item,
.phrase-item,
.history-item {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
}

.live-item .meta,
.conversation-item .meta,
.history-item .meta,
.phrase-item .meta {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.live-item .source,
.conversation-item .source,
.history-item .source,
.phrase-item .source {
  margin-bottom: 8px;
  line-height: 1.5;
}

.live-item .target,
.conversation-item .target,
.history-item .target,
.phrase-item .target {
  color: var(--primary-dark);
  font-weight: 800;
  line-height: 1.5;
}

.conversation-item.zh {
  border-left: 4px solid var(--primary);
}

.conversation-item.my {
  border-left: 4px solid var(--accent);
}

.offline-kit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(15, 118, 110, 0.24);
  border-radius: var(--radius);
  color: var(--primary-dark);
  background: var(--primary-soft);
  font-size: 13px;
}

.scenario-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 10px;
  scrollbar-width: none;
}

.scenario-chips::-webkit-scrollbar {
  display: none;
}

.scenario-chip {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-strong);
  font-weight: 800;
}

.scenario-chip.active {
  border-color: var(--primary);
  color: #ffffff;
  background: var(--primary);
}

.phrase-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.phrase-actions button {
  min-height: 34px;
}

.favorites-section {
  margin-top: 16px;
}

.phrase-tools {
  margin-bottom: 10px;
}

.history-section {
  margin-top: 16px;
  padding: 14px;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.54);
  text-align: center;
}

.settings-dialog {
  width: min(calc(100% - 28px), 520px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.settings-dialog::backdrop {
  background: rgba(32, 33, 36, 0.38);
}

.settings-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.field {
  display: grid;
}

.dialog-actions {
  justify-content: flex-end;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 10;
  transform: translateX(-50%) translateY(24px);
  max-width: calc(100% - 32px);
  padding: 10px 14px;
  border-radius: 999px;
  color: #ffffff;
  background: rgba(32, 33, 36, 0.92);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 640px) {
  .app-shell {
    padding-top: 24px;
  }

  h1 {
    font-size: 34px;
  }

  .mode-view.active#textView {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}
