:root {
  --bg: #e9f3ff;
  --bg-strong: #dcecff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-strong: rgba(247, 251, 255, 0.96);
  --panel-edge: #c3d8f0;
  --text: #173553;
  --muted: #6c84a1;
  --accent: #4f8fd8;
  --accent-strong: #2f72c8;
  --accent-dim: rgba(79, 143, 216, 0.14);
  --accent-dim-strong: rgba(79, 143, 216, 0.22);
  --shadow: 0 18px 44px rgba(55, 96, 146, 0.12);
  --warn-bg: rgba(255, 206, 107, 0.22);
  --warn-border: rgba(214, 157, 34, 0.38);
  --warn-text: #7a4d00;
  --danger: #b42318;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background:
    radial-gradient(circle at top left, rgba(113, 171, 238, 0.26), transparent 32%),
    radial-gradient(circle at bottom right, rgba(119, 196, 224, 0.22), transparent 28%),
    linear-gradient(180deg, #eef6ff 0%, #dfeeff 100%);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 28px 16px 36px;
}

body::before,
body::after {
  content: "";
  position: fixed;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  filter: blur(28px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
}

body::before {
  top: -80px;
  left: -60px;
  background: rgba(132, 185, 244, 0.42);
}

body::after {
  right: -90px;
  bottom: -70px;
  background: rgba(124, 203, 225, 0.35);
}

header,
main {
  width: 100%;
  max-width: 760px;
  position: relative;
  z-index: 1;
}

header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 6px;
}

h1 span { color: var(--accent-strong); }

.hero-copy {
  color: var(--muted);
  font-size: 0.95rem;
  max-width: 480px;
  line-height: 1.45;
}

.status {
  min-width: 150px;
  text-align: right;
  font-size: 0.84rem;
  color: var(--accent-strong);
  min-height: 1.2em;
  padding-top: 8px;
}

.auth-panel {
  width: min(100%, 520px);
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  margin: 4vh auto 0;
  padding: 24px;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--panel-edge);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.auth-panel[hidden] { display: none; }

.auth-panel h2 {
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.auth-panel p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.auth-form {
  display: grid;
  gap: 8px;
}

.auth-form[hidden] { display: none; }

.auth-form label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text);
}

.auth-form input {
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

#authCode {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.3em;
  text-align: center;
}

.auth-form button:not(.secondary-btn) {
  min-height: 42px;
  border: 1px solid var(--accent-strong);
  border-radius: 999px;
  color: #fff;
  background: var(--accent-strong);
  font: 700 0.86rem/1 inherit;
  cursor: pointer;
}

.auth-form button:disabled { opacity: 0.58; cursor: wait; }

.auth-status { min-height: 1.35em; color: var(--accent-strong) !important; }

.auth-status.error { color: var(--danger) !important; }

.status-inline {
  min-width: 0;
  text-align: left;
  padding-top: 0;
}

main {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

main[hidden] { display: none; }

.view-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(195, 216, 240, 0.92);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.view-strip-meta {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  min-width: 0;
}

.compact-language-toggle {
  display: none;
  align-items: center;
  overflow: hidden;
  border: 1px solid rgba(79, 143, 216, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
}

.compact-select {
  display: none;
  box-sizing: border-box;
  max-width: 220px;
  min-height: 40px;
  padding: 7px 34px 7px 12px;
  border: 1px solid rgba(79, 143, 216, 0.28);
  border-radius: 999px;
  color: var(--accent-strong);
  background-color: rgba(255, 255, 255, 0.72);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='m1 1.5 5 5 5-5' stroke='%234f8fd8' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 12px 8px;
  font: 700 0.78rem/1.2 inherit;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.agent-mode-select {
  display: inline-block;
}

.compact-language-btn {
  min-width: 42px;
  padding: 7px 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 700 0.78rem/1 inherit;
  cursor: pointer;
}

.compact-language-btn.active {
  background: var(--accent-dim);
  color: var(--accent-strong);
}

.compact-language-btn:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: -2px;
}

.compact-dialect-select {
  min-width: 112px;
  max-width: 145px;
}

.compact-tone-select {
  min-width: 180px;
}

.compact-engine-select {
  min-width: 164px;
}

.compact-agent-mode-select {
  min-width: 170px;
}

.compact-select:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.conversation-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.conversation-bar.clipboard-pending {
  background: rgba(244, 250, 255, 0.96);
  border-color: rgba(47, 114, 200, 0.58);
  box-shadow: 0 18px 44px rgba(47, 114, 200, 0.2);
}

.conversation-bar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.conversation-bar-head > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation-note {
  color: var(--muted);
  font-size: 0.72rem;
}

.conversation-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}

.conversation-tab {
  overflow: hidden;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  font: 600 0.86rem/1.2 inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.conversation-tab:hover {
  transform: translateY(-1px);
  color: var(--text);
  border-color: rgba(79, 143, 216, 0.26);
}

.conversation-tab.active {
  color: var(--accent-strong);
  background: var(--accent-dim);
  border-color: rgba(79, 143, 216, 0.34);
}

.conversation-bar.clipboard-pending .conversation-tab {
  color: var(--accent-strong);
  border-color: rgba(79, 143, 216, 0.3);
  background: rgba(255, 255, 255, 0.88);
}

.conversation-bar.clipboard-pending .conversation-tab:hover {
  background: var(--accent-dim-strong);
  border-color: rgba(47, 114, 200, 0.58);
}

#cancelClipboardBtn[hidden] { display: none; }

.controls {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(230px, 0.82fr) minmax(0, 1.18fr);
  align-items: start;
}

.controls .control-card:last-child {
  grid-column: 1 / -1;
}

.control-card,
.pane {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.control-card { padding: 14px 16px; }

.control-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.control-head-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
}

.control-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.auto-tone-status {
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
}

.context-status {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
}

.control-title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.control-note {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  text-align: right;
}

.engine,
.tone-grid,
.language-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dialect-selector {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.dialect-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.eng-btn,
.tone-btn,
.language-btn {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.eng-btn:hover,
.tone-btn:hover,
.language-btn:hover {
  transform: translateY(-1px);
  color: var(--text);
  border-color: rgba(79, 143, 216, 0.26);
  background: rgba(255, 255, 255, 0.8);
}

.eng-btn.active,
.tone-btn.active,
.language-btn.active {
  color: var(--accent-strong);
  background: var(--accent-dim);
  border-color: rgba(79, 143, 216, 0.34);
  box-shadow: inset 0 0 0 1px rgba(79, 143, 216, 0.08);
}

.tone-btn {
  flex: 1 1 200px;
  text-align: left;
  border-radius: 18px;
  padding: 10px 14px;
  min-height: 48px;
}

.language-btn {
  flex: 1 1 170px;
}

.dialect-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.dialect-btn:hover {
  transform: translateY(-1px);
  color: var(--text);
  border-color: rgba(79, 143, 216, 0.26);
  background: rgba(255, 255, 255, 0.8);
}

.dialect-btn.active {
  color: var(--accent-strong);
  background: var(--accent-dim);
  border-color: rgba(79, 143, 216, 0.34);
  box-shadow: inset 0 0 0 1px rgba(79, 143, 216, 0.08);
}

.pane {
  padding: 18px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.pane:focus-within {
  border-color: rgba(79, 143, 216, 0.46);
  box-shadow: 0 18px 44px rgba(55, 96, 146, 0.18);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.char-counter {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.char-counter.over {
  color: var(--danger);
}

textarea {
  width: 100%;
  min-height: 180px;
  background: transparent;
  border: none;
  outline: none;
  resize: vertical;
  color: var(--text);
  font-family: inherit;
  font-size: 1.05rem;
  line-height: 1.62;
  caret-color: var(--accent-strong);
}

textarea::placeholder { color: var(--muted); }

.spellcheck-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.altgr-suggestion {
  margin: 8px 0 0;
  padding: 8px 10px;
  color: #78561c;
  background: rgba(222, 170, 61, 0.12);
  border: 1px solid rgba(185, 132, 18, 0.28);
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.altgr-suggestion[hidden] { display: none; }

.altgr-suggestion button {
  margin-left: 4px;
  padding: 3px 7px;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 6px;
  cursor: pointer;
}

.altgr-suggestion button:hover { background: rgba(185, 132, 18, 0.12); }

.speech-correction-suggestion {
  margin: 10px 0 0;
  padding: 9px 11px;
  color: #59418d;
  background: rgba(138, 103, 203, 0.1);
  border: 1px solid rgba(138, 103, 203, 0.3);
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.speech-correction-suggestion[hidden] { display: none; }

.speech-correction-suggestion button {
  margin: 4px 0 0 4px;
  padding: 3px 7px;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 6px;
  cursor: pointer;
}

.speech-correction-suggestion button:hover { background: rgba(138, 103, 203, 0.14); }

.punctuation-preview {
  margin: 10px 0 0;
  padding: 9px 11px;
  color: #634a9f;
  background: rgba(138, 103, 203, 0.1);
  border: 1px solid rgba(138, 103, 203, 0.24);
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.punctuation-preview[hidden] { display: none; }

.ambiguity-notice {
  margin: 10px 0 0;
  padding: 9px 11px;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.ambiguity-notice[hidden] { display: none; }

.web-check-suggestion {
  margin: 10px 0 0;
  padding: 9px 11px;
  color: #165b4d;
  background: rgba(35, 147, 119, 0.1);
  border: 1px solid rgba(35, 147, 119, 0.27);
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
}

.web-check-suggestion[hidden],
.web-check-result[hidden] { display: none; }

.web-check-suggestion button {
  margin: 4px 0 0 4px;
  padding: 3px 7px;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 6px;
  cursor: pointer;
}

.web-check-suggestion button:hover { background: rgba(35, 147, 119, 0.12); }

textarea:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.divider {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
}

.direction {
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-strong);
  background: var(--accent-dim);
  border: 1px solid rgba(79, 143, 216, 0.24);
  border-radius: 999px;
  padding: 9px 20px;
  transition: transform 0.25s ease;
}

.direction.flip { transform: rotateX(360deg); }

.swap-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-strong);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(79, 143, 216, 0.24);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
}

.swap-btn:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(79, 143, 216, 0.36);
}

.output-pane { position: relative; }

#output {
  min-height: 180px;
  font-size: 1.05rem;
  line-height: 1.62;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text);
}

#output.empty { color: var(--muted); }

.cloud-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
  padding: 6px 12px;
}

.cloud-badge {
  color: #0f5132;
  background: rgba(117, 183, 152, 0.16);
  border: 1px solid rgba(71, 140, 104, 0.28);
}

.preference-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #5b3a99;
  background: rgba(151, 111, 207, 0.14);
  border: 1px solid rgba(120, 77, 181, 0.28);
  border-radius: 999px;
  padding: 6px 12px;
}

.cloud-badge::before,
.language-badge::before,
.preference-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.cloud-badge::before { background: #47986a; }
.preference-badge::before { background: #7b4db3; }

.cloud-badge[hidden],
.language-badge[hidden],
.preference-badge[hidden] { display: none; }

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.language-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #7a4d00;
  background: rgba(255, 206, 107, 0.18);
  border: 1px solid rgba(214, 157, 34, 0.32);
  border-radius: 999px;
  padding: 6px 12px;
}

.language-badge::before { background: #d69d22; }

.toolbar {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

#copyClearBtn {
  width: 100%;
}

.toolbar-groups {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 10px;
}

.toolbar-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(79, 143, 216, 0.16);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.34);
}

.toolbar-group button {
  min-width: 0;
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

#copyClearBtn {
  text-align: center;
}

.toolbar-group-actions #compactBackTranslateBtn {
  display: none;
}

.toolbar-group-actions {
  grid-template-areas:
    "retry copy"
    "clear new";
}

.toolbar-group-actions #retryBtn {
  grid-area: retry;
}

.toolbar-group-actions #copyBtn {
  grid-area: copy;
}

.toolbar-group-actions #clearBtn {
  grid-area: clear;
}

.toolbar-group-actions #newConversationBtn {
  grid-area: new;
}

.toolbar-group-library #correctRememberBtn,
.toolbar-group-actions #alternativeEngineBtn {
  grid-column: 1 / -1;
}

.toolbar button,
.speech-panel-actions button,
.secondary-btn,
.swap-btn {
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.toolbar button,
.speech-panel-actions button {
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  padding: 11px 18px;
  cursor: pointer;
}

.toolbar button:hover,
.speech-panel-actions button:hover {
  transform: translateY(-1px);
  border-color: rgba(79, 143, 216, 0.36);
  background: rgba(255, 255, 255, 0.98);
}

.toolbar button:disabled,
.speech-panel-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toolbar button:disabled:hover,
.speech-panel-actions button:disabled:hover {
  transform: none;
}

.secondary-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent-strong);
  background: rgba(79, 143, 216, 0.1);
  border: 1px solid rgba(79, 143, 216, 0.24);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
}

.secondary-btn:hover {
  transform: translateY(-1px);
  background: rgba(79, 143, 216, 0.16);
  border-color: rgba(79, 143, 216, 0.34);
}

.phrasebook-template-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.phrasebook-import-label {
  display: inline-flex;
  align-items: center;
}

.file-input-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.input-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.clipboard-auto-btn {
  padding: 7px 12px;
  font-size: 0.8rem;
}

.clipboard-auto-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: help;
}

.microphone-btn {
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent-strong);
  background: var(--accent-dim);
  border: 1px solid rgba(79, 143, 216, 0.28);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.microphone-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--accent-dim-strong);
}

.microphone-btn.listening {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
  animation: microphone-pulse 1.4s ease-in-out infinite;
}

.speech-correction-btn {
  color: #634a9f;
  background: rgba(138, 103, 203, 0.12);
  border-color: rgba(138, 103, 203, 0.32);
}

.speech-correction-btn:hover:not(:disabled) {
  background: rgba(138, 103, 203, 0.2);
}

.speech-consensus-btn {
  color: #0f5f73;
  background: rgba(28, 133, 157, 0.11);
  border-color: rgba(28, 133, 157, 0.3);
}

.speech-consensus-btn:hover:not(:disabled) {
  background: rgba(28, 133, 157, 0.19);
}

.speech-correction-memory-btn {
  color: #0f6b40;
  background: rgba(30, 142, 90, 0.1);
  border-color: rgba(30, 142, 90, 0.28);
}

.speech-correction-memory-btn:hover:not(:disabled) {
  background: rgba(30, 142, 90, 0.18);
}

.speech-calibration-btn {
  color: #7a4b0f;
  background: rgba(226, 157, 42, 0.13);
  border-color: rgba(189, 126, 28, 0.34);
}

.speech-calibration-btn:hover:not(:disabled) {
  background: rgba(226, 157, 42, 0.22);
}

.speech-correction-state {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.speech-correction-state[data-state="recording"],
.speech-correction-state[data-state="processing"],
.speech-correction-state[data-state="proposal"] {
  color: #634a9f;
}

.speech-correction-state[data-state="applied"] {
  color: #0f6b40;
}

.speech-correction-state[data-state="error"] {
  color: var(--danger);
}

.microphone-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: help;
}

.microphone-btn:focus-visible {
  outline: 3px solid rgba(79, 143, 216, 0.3);
  outline-offset: 2px;
}

@keyframes microphone-pulse {
  50% { box-shadow: 0 0 0 5px rgba(180, 35, 24, 0.14); }
}

.secondary-btn[aria-pressed="true"] {
  background: rgba(79, 143, 216, 0.18);
  border-color: rgba(79, 143, 216, 0.34);
  color: var(--accent-strong);
}

.toolbar button:focus-visible,
.eng-btn:focus-visible,
.tone-btn:focus-visible,
.secondary-btn:focus-visible,
.swap-btn:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

button.copied {
  background: var(--accent-dim-strong);
  border-color: rgba(79, 143, 216, 0.42);
  color: var(--accent-strong);
}

.history-panel {
  margin-top: 4px;
}

.translation-cost {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 9px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.78rem;
}

.translation-cost-label {
  font-weight: 700;
}

.translation-cost strong {
  color: var(--accent-strong);
  font-size: 0.88rem;
}

.translation-cost-note {
  font-size: 0.74rem;
}

.translation-cost-actions {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.translation-cost-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 5px 10px;
  font-size: 1rem;
  line-height: 1;
}

.translation-cost-reset {
  margin-left: 0;
  padding: 6px 10px;
  font-size: 0.72rem;
}

.web-check-result {
  display: grid;
  gap: 8px;
  margin-top: 14px;
  padding: 13px;
  color: #165b4d;
  background: rgba(35, 147, 119, 0.07);
  border: 1px solid rgba(35, 147, 119, 0.22);
  border-radius: 14px;
}

.web-check-result h2 {
  margin: 0;
  font-size: 0.92rem;
}

.web-check-result-phrase,
.web-check-result-answer {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
}

.web-check-result-phrase { font-weight: 700; }

.web-check-sources {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 18px;
  font-size: 0.8rem;
}

.web-check-sources a { color: var(--accent-strong); }

.dialog-note {
  text-align: left;
}

.phrasebook-panel {
  margin-top: 4px;
}

.phrasebook-panel[hidden] { display: none; }

.app-update-notice {
  margin: 0 0 12px;
  padding: 10px 12px;
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 700;
  text-align: center;
  background: rgba(79, 143, 216, 0.12);
  border: 1px solid rgba(79, 143, 216, 0.28);
  border-radius: 12px;
}

.phrasebook-import-note {
  margin: 0 0 10px;
}

.phrasebook-reverse-option {
  margin: 0 0 10px;
}

.phrasebook-import-note code {
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.phrasebook-list {
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.phrasebook-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--panel-edge);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
}

.phrasebook-entry {
  min-width: 0;
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.phrasebook-entry strong {
  color: var(--accent-strong);
}

.phrasebook-remove {
  font: 700 0.74rem/1 inherit;
  color: var(--danger);
  border: 1px solid rgba(180, 35, 24, 0.24);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(180, 35, 24, 0.06);
  cursor: pointer;
}

.speech-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.speech-panel-actions {
  display: contents;
}

.speech-panel-actions button {
  min-height: 42px;
  min-width: 0;
  width: 100%;
}

.speech-panel .speech-select {
  box-sizing: border-box;
  min-height: 42px;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font: 600 0.82rem/1 inherit;
  padding: 0 34px 0 12px;
}

.speech-panel .speech-select:disabled {
  opacity: 0.58;
}

.speech-volume-control {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr);
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.speech-volume-control output {
  color: var(--accent-strong);
}

.speech-volume-control input {
  accent-color: var(--accent-strong);
  cursor: pointer;
  min-width: 0;
  width: 100%;
}

.speech-option-control,
.speech-toggle-control {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.speech-option-control {
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr);
  align-items: center;
  gap: 12px;
}

.speech-option-control select {
  min-height: 38px;
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.68);
  color: var(--ink);
  font: 600 0.82rem/1 inherit;
  padding: 0 34px 0 12px;
}

.speech-toggle-control {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  cursor: pointer;
}

.speech-toggle-control input {
  accent-color: var(--accent-strong);
  margin-top: 2px;
}

.speech-toggle-control small {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 500;
}

.phrasebook-remove:hover { background: rgba(180, 35, 24, 0.12); }

.phrasebook-use {
  font: 700 0.74rem/1 inherit;
  color: var(--accent-strong);
  border: 1px solid rgba(79, 143, 216, 0.28);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgba(79, 143, 216, 0.1);
  cursor: pointer;
}

.phrasebook-use:hover { background: rgba(79, 143, 216, 0.18); }

.translator-editor-dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--panel-edge);
  border-radius: 18px;
  color: var(--text);
  background: var(--panel-strong);
  box-shadow: 0 24px 60px rgba(32, 67, 106, 0.28);
}

.translator-editor-dialog::backdrop { background: rgba(16, 45, 74, 0.3); }

.translator-editor-form {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.translator-editor-form h2 { font-size: 1.15rem; }

.editor-field {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-weight: 700;
  font-size: 0.84rem;
}

.editor-field textarea {
  width: 100%;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  color: var(--text);
  background: #fff;
  font: 400 0.92rem/1.4 inherit;
}

.editor-option {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
}

.editor-option input {
  margin: 3px 0 0;
  accent-color: var(--accent-strong);
}

.editor-option span {
  display: grid;
  gap: 3px;
  font-size: 0.84rem;
}

.editor-option small {
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.editor-actions button:not(.secondary-btn) {
  font: 700 0.84rem/1 inherit;
  color: #fff;
  background: var(--accent-strong);
  border: 1px solid var(--accent-strong);
  border-radius: 999px;
  padding: 9px 14px;
  cursor: pointer;
}

.speech-calibration-form { gap: 14px; }

.speech-calibration-traits {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.speech-calibration-traits legend {
  margin-bottom: 6px;
  color: var(--ink);
  font-weight: 700;
}

.speech-calibration-progress {
  margin: 0;
  color: var(--accent-strong);
  font-weight: 700;
  font-size: 0.84rem;
}

.speech-calibration-phrase {
  margin: 0;
  padding: 13px 14px;
  border: 1px solid rgba(189, 126, 28, 0.28);
  border-radius: 12px;
  background: rgba(226, 157, 42, 0.08);
  color: var(--text);
  font-weight: 700;
  line-height: 1.45;
}

.speech-calibration-transcript {
  min-height: 1.35em;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

.speech-calibration-transcript[data-result="match"] { color: #0f6b40; }
.speech-calibration-transcript[data-result="different"] { color: #7a4b0f; }

.speech-comparison-form { gap: 14px; }

.speech-comparison-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}

.speech-comparison-results {
  display: grid;
  gap: 10px;
  max-height: min(48vh, 460px);
  overflow: auto;
  padding: 12px;
  border: 1px solid rgba(79, 143, 216, 0.3);
  border-radius: 12px;
  background: rgba(79, 143, 216, 0.07);
}

.speech-comparison-summary,
.speech-comparison-result p {
  margin: 0;
  font-size: 0.81rem;
  line-height: 1.45;
}

.speech-comparison-summary {
  color: var(--accent-strong);
  font-weight: 700;
}

.speech-comparison-result {
  display: grid;
  gap: 7px;
  padding: 11px;
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.66);
}

.speech-comparison-result h3 {
  margin: 0;
  color: var(--text);
  font-size: 0.88rem;
}

.speech-calibration-review {
  display: grid;
  gap: 10px;
  padding: 13px;
  border: 1px solid rgba(79, 143, 216, 0.3);
  border-radius: 12px;
  background: rgba(79, 143, 216, 0.07);
}

.speech-calibration-review h3,
.speech-calibration-review p {
  margin: 0;
}

.speech-calibration-review h3 { font-size: 0.96rem; }

.speech-calibration-review p {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.42;
}

.speech-calibration-review-list {
  display: grid;
  gap: 10px;
  max-height: min(42vh, 380px);
  overflow: auto;
  padding-right: 3px;
}

.speech-calibration-review-group {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid var(--panel-edge);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.66);
}

.speech-calibration-review-expected {
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1.4;
}

.speech-calibration-review .editor-option {
  padding: 8px 9px;
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.8rem;
}

.speech-calibration-review-count {
  color: var(--accent-strong) !important;
  font-weight: 700;
}

.speech-calibration-review-save {
  justify-self: start;
  padding: 8px 12px;
  color: #fff;
  background: var(--accent-strong);
  border: 1px solid var(--accent-strong);
  border-radius: 999px;
  font: 700 0.8rem/1 inherit;
  cursor: pointer;
}

.speech-calibration-review-save:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#historyBtn {
  display: none;
}

.history-list {
  list-style: none;
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.history-item {
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 0.84rem;
  line-height: 1.35;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--panel-edge);
  background: rgba(255, 255, 255, 0.55);
  color: var(--text);
  cursor: pointer;
}

.history-item:hover {
  border-color: rgba(79, 143, 216, 0.34);
  background: rgba(255, 255, 255, 0.88);
}

.history-filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, auto);
  gap: 8px;
  margin: 12px 0;
}

.history-filters input,
.history-filters select {
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--panel-strong);
  border: 1px solid var(--panel-edge);
  border-radius: 12px;
  padding: 9px 11px;
}

.history-result-summary,
.history-filter-hint {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.history-filter-hint { margin: -4px 0 10px; }

.private-sync-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.private-sync-status .secondary-btn { flex: 0 0 auto; }

.history-load-more {
  display: block;
  margin: 12px auto 0;
}

.direction-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.history-meta {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.45;
  text-align: center;
  padding: 2px 8px 0;
}

#turnstileContainer {
  display: flex;
  justify-content: center;
  min-height: 0;
}

#turnstileContainer:not(:empty) {
  min-height: 65px;
  margin-top: 8px;
}

body.compact-view {
  padding-top: 12px;
}

body.compact-view header,
body.compact-view .controls,
body.compact-view .divider,
body.compact-view .history-panel,
body.compact-view .hint {
  display: none;
}

body.compact-view main {
  gap: 8px;
}

body.compact-view .view-strip {
  padding: 8px 12px;
  border-radius: 16px;
}

body.compact-view .compact-language-toggle {
  display: inline-flex;
}

body.compact-view .compact-select:not([hidden]) {
  display: inline-block;
}

body.compact-view .compact-tone-select {
  max-width: 220px;
}

body.compact-view .conversation-bar {
  gap: 8px;
  padding: 9px 12px;
  border-radius: 16px;
}

body.compact-view .conversation-tab {
  padding: 7px 10px;
}

body.compact-view .pane-head {
  margin-bottom: 6px;
}

body.compact-view .pane {
  padding: 12px 14px;
  border-radius: 18px;
}

body.compact-view #speechConsensusBtn,
body.compact-view #speechCorrectionMemoryBtn,
body.compact-view #speechCalibrationBtn,
body.compact-view #speechComparisonBtn {
  display: none;
}

body.compact-view textarea,
body.compact-view #output {
  min-height: 120px;
  font-size: 1rem;
  line-height: 1.48;
}

body.compact-view .badge-row {
  margin-bottom: 8px;
}

body.compact-view .toolbar {
  gap: 8px;
  margin-top: 10px;
}

body.compact-view .toolbar button {
  padding: 9px 14px;
}

body.compact-view .toolbar-group-actions #alternativeEngineBtn {
  display: none !important;
}

body.compact-view #localBtn {
  display: none;
}

body.compact-view #historyBtn {
  display: inline-flex;
}

body.compact-view .translation-cost {
  margin-top: 10px;
}

body.compact-view .speech-panel.speech-settings-collapsed .speech-settings-control {
  display: none !important;
}

body.compact-view .history-panel.history-open {
  display: block;
}

@media (prefers-reduced-motion: reduce) {
  .direction,
  .direction.flip,
  .eng-btn,
  .tone-btn,
  .language-btn,
  .toolbar button {
    transition: none;
    transform: none;
  }
}

@media (max-width: 720px) {
  .controls { grid-template-columns: 1fr; }

  .conversation-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .conversation-bar-head { justify-content: space-between; }

  .view-strip,
  header,
  .control-head {
    flex-direction: column;
    align-items: flex-start;
  }

  body.compact-view .view-strip {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .status,
  .control-note {
    text-align: left;
    min-width: 0;
    padding-top: 0;
  }

  .history-filters { grid-template-columns: 1fr; }

  .history-filters input,
  .history-filters select { min-height: 44px; }

  .private-sync-status {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (hover: none) and (pointer: coarse) {

  .toolbar-groups {
    grid-template-columns: 1fr;
  }

  #desktopBackTranslateBtn {
    display: none;
  }

  body.compact-view .toolbar-group-actions {
    grid-template-areas:
      "back back"
      "retry copy"
      "clear new";
  }

  body.compact-view .toolbar-group-actions #compactBackTranslateBtn {
    display: inline-flex;
    grid-area: back;
  }

  .conversation-tabs { gap: 5px; }

  .conversation-tab {
    padding: 9px 7px;
    font-size: 0.78rem;
  }
  body { padding: 18px 12px 28px; }
  h1 { font-size: 1.6rem; }

  .pane,
  .control-card {
    border-radius: 18px;
    padding: 14px;
  }

  .speech-panel-actions button,
  .speech-panel .speech-select {
    font-size: 0.78rem;
    padding-left: 8px;
    padding-right: 8px;
  }

  .speech-volume-control {
    gap: 8px;
    font-size: 0.74rem;
    grid-template-columns: auto minmax(92px, 1fr);
  }

  .pane-head {
    align-items: flex-start;
  }

  textarea,
  #output {
    min-height: 160px;
  }
}
