:root {
  --bg: #f3f1ec;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #fffdf9;
  --ink: #1e2529;
  --muted: #6f777b;
  --line: rgba(30, 37, 41, 0.11);
  --accent: #f26b38;
  --accent-dark: #db5323;
  --teal: #137c72;
  --teal-soft: #d9f0ec;
  --shadow: 0 24px 70px rgba(40, 44, 48, 0.12);
  --soft-shadow: 0 12px 32px rgba(40, 44, 48, 0.08);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(rgba(255,255,255,0.2), rgba(255,255,255,0.2)),
    radial-gradient(circle at 14% 8%, rgba(242,107,56,0.13), transparent 28rem),
    radial-gradient(circle at 88% 12%, rgba(19,124,114,0.12), transparent 30rem),
    var(--bg);
  font-family: "Segoe UI Variable", "Segoe UI", "Microsoft YaHei UI", "PingFang SC", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }

.ambient {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(4px);
  pointer-events: none;
}
.ambient-one { width: 22rem; height: 22rem; left: -8rem; bottom: 4rem; background: rgba(242,107,56,0.08); }
.ambient-two { width: 18rem; height: 18rem; right: -5rem; top: 22rem; background: rgba(19,124,114,0.08); }

.topbar {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: #fff;
  box-shadow: var(--soft-shadow);
}
.brand-mark svg { width: 34px; height: 34px; }
.brand-mark path:first-child { fill: #1f2a2e; }
.brand-mark .brand-line { fill: none; stroke: #fff; stroke-width: 2.4; stroke-linecap: round; }
.brand-mark .brand-spark { fill: var(--accent); }
.brand strong { display: block; font-size: 18px; letter-spacing: .02em; }
.brand small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }

.server-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,0.62);
  backdrop-filter: blur(14px);
  font-size: 13px;
  white-space: nowrap;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e0a52d;
  box-shadow: 0 0 0 4px rgba(224,165,45,0.14);
}
.server-pill.online .status-dot { background: #2a9d72; box-shadow: 0 0 0 4px rgba(42,157,114,0.14); }
.server-pill.offline .status-dot { background: #d5544f; box-shadow: 0 0 0 4px rgba(213,84,79,0.14); }

.page-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 70px; }

.hero { max-width: 760px; padding: 48px 0 34px; }
.eyebrow { margin: 0 0 12px; color: var(--teal); font-size: 12px; font-weight: 800; letter-spacing: .18em; }
.hero h1 { margin: 0; font-size: clamp(36px, 5vw, 62px); line-height: 1.08; letter-spacing: -.045em; }
.hero h1 em { color: var(--accent); font-style: normal; position: relative; white-space: nowrap; }
.hero h1 em::after { content: ""; position: absolute; left: 0; right: 0; bottom: -4px; height: 7px; border-radius: 99px; background: rgba(242,107,56,.18); }
.hero-copy { max-width: 650px; margin: 22px 0 0; color: var(--muted); font-size: 17px; line-height: 1.8; }

.translator-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: stretch; }
.panel {
  min-width: 0;
  padding: 24px;
  border: 1px solid rgba(255,255,255,0.8);
  border-radius: var(--radius-xl);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}
.input-panel { display: flex; flex-direction: column; }
.result-panel { display: flex; flex-direction: column; background: linear-gradient(160deg, rgba(255,255,255,.94), rgba(250,255,253,.88)); }

.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-heading > div { display: flex; align-items: center; gap: 10px; }
.panel-heading h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.step-number { color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .12em; }
.step-number.accent { color: var(--teal); }
.counter, .result-time { color: var(--muted); font-size: 12px; }

textarea, #contextInput {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
  color: var(--ink);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
textarea {
  flex: 1;
  min-height: 250px;
  padding: 18px;
  border-radius: var(--radius-lg);
  resize: vertical;
  font-size: 17px;
  line-height: 1.75;
}
textarea::placeholder, #contextInput::placeholder { color: #a1a6a8; }
textarea:focus, #contextInput:focus { border-color: rgba(19,124,114,.45); box-shadow: 0 0 0 4px rgba(19,124,114,.08); background: #fff; }

.tone-block { margin-top: 18px; }
.field-label { margin-bottom: 10px; color: var(--muted); font-size: 13px; font-weight: 650; }
.tone-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tone-chip {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  cursor: pointer;
  font-size: 13px;
  transition: .18s ease;
}
.tone-chip:hover { border-color: rgba(19,124,114,.35); transform: translateY(-1px); }
.tone-chip.active { color: #fff; border-color: var(--teal); background: var(--teal); box-shadow: 0 8px 20px rgba(19,124,114,.2); }

.context-box { margin-top: 13px; border-top: 1px dashed var(--line); padding-top: 13px; }
.context-box summary { cursor: pointer; color: var(--muted); font-size: 13px; user-select: none; }
.context-box summary span { margin-left: 4px; color: #9aa0a2; font-size: 12px; }
#contextInput { margin-top: 10px; padding: 11px 13px; border-radius: 12px; font-size: 13px; }

.translate-button {
  width: 100%;
  margin-top: 18px;
  padding: 15px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 0;
  border-radius: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #f58f37);
  box-shadow: 0 14px 30px rgba(242,107,56,.25);
  cursor: pointer;
  font-weight: 750;
  transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}
.translate-button:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 18px 36px rgba(242,107,56,.31); }
.translate-button:active:not(:disabled) { transform: translateY(0); }
.translate-button:disabled { cursor: wait; opacity: .7; }
.translate-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.shortcut-hint { margin: 10px 0 0; text-align: center; color: #989da0; font-size: 11px; }
kbd { padding: 2px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; background: rgba(255,255,255,.8); font: inherit; }

.result-stage {
  flex: 1;
  min-height: 390px;
  display: grid;
  place-items: center;
  padding: 28px;
  border: 1px solid rgba(19,124,114,.12);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 0%, rgba(19,124,114,.08), transparent 58%),
    rgba(255,255,255,.6);
  overflow: hidden;
}
.empty-state, .loading-state { text-align: center; }
.empty-state h3 { margin: 22px 0 7px; font-size: 18px; }
.empty-state p, .loading-state p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.empty-orbit { position: relative; width: 145px; height: 88px; margin: 0 auto; }
.empty-orbit::before { content: ""; position: absolute; inset: 13px 5px; border: 1px dashed rgba(19,124,114,.22); border-radius: 50%; }
.empty-orbit span { position: absolute; display: grid; place-items: center; width: 46px; height: 46px; border-radius: 15px; color: #fff; font-weight: 750; box-shadow: 0 10px 24px rgba(30,37,41,.13); }
.empty-orbit span:nth-child(1) { left: 1px; top: 21px; background: var(--teal); transform: rotate(-8deg); }
.empty-orbit span:nth-child(2) { left: 51px; top: 0; background: var(--accent); transform: rotate(5deg); }
.empty-orbit span:nth-child(3) { right: 4px; bottom: 0; background: #2f3c43; transform: rotate(8deg); }

.loading-state strong { display: block; margin: 22px 0 7px; font-size: 17px; }
.wave { height: 58px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.wave i { width: 7px; height: 18px; border-radius: 99px; background: linear-gradient(var(--accent), var(--teal)); animation: wave 1s ease-in-out infinite; }
.wave i:nth-child(2) { animation-delay: .1s; }
.wave i:nth-child(3) { animation-delay: .2s; }
.wave i:nth-child(4) { animation-delay: .3s; }
.wave i:nth-child(5) { animation-delay: .4s; }
@keyframes wave { 0%, 100% { height: 16px; opacity: .45; } 50% { height: 54px; opacity: 1; } }

.result-copy { width: 100%; align-self: center; }
.result-copy p {
  margin: 0;
  color: #173b39;
  font-family: "Segoe UI Variable Display", "Segoe UI", Georgia, serif;
  font-size: clamp(24px, 2.5vw, 34px);
  font-weight: 620;
  line-height: 1.45;
  letter-spacing: -.025em;
  overflow-wrap: anywhere;
}
.result-copy.is-playing p { animation: resultIn .35s ease both; }
@keyframes resultIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.result-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 14px; }
.icon-button {
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255,255,255,.75);
  cursor: pointer;
  font-size: 13px;
  transition: .18s ease;
}
.icon-button:hover:not(:disabled) { border-color: rgba(19,124,114,.35); background: #fff; transform: translateY(-1px); }
.icon-button:disabled { cursor: default; opacity: .4; }
.icon-button svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.history-section { margin-top: 54px; }
.history-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 17px; }
.history-heading .eyebrow { margin-bottom: 5px; }
.history-heading h2 { margin: 0; font-size: 27px; letter-spacing: -.03em; }
.text-button { border: 0; padding: 8px 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; }
.text-button:hover { color: var(--accent-dark); }
.history-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }
.history-empty { grid-column: 1 / -1; padding: 25px; border: 1px dashed var(--line); border-radius: var(--radius-lg); color: var(--muted); text-align: center; font-size: 14px; }
.history-card {
  min-width: 0;
  padding: 17px;
  border: 1px solid rgba(255,255,255,.8);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,.72);
  box-shadow: var(--soft-shadow);
  cursor: pointer;
  transition: .18s ease;
}
.history-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.history-card .history-meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 9px; color: var(--muted); font-size: 11px; }
.history-card strong { display: -webkit-box; overflow: hidden; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-size: 14px; line-height: 1.55; }
.history-card p { display: -webkit-box; overflow: hidden; margin: 9px 0 0; -webkit-line-clamp: 2; -webkit-box-orient: vertical; color: var(--teal); font-size: 14px; line-height: 1.55; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: calc(100% - 32px);
  padding: 11px 16px;
  border-radius: 999px;
  color: #fff;
  background: rgba(30,37,41,.92);
  box-shadow: 0 14px 34px rgba(0,0,0,.2);
  opacity: 0;
  transform: translate(-50%, 14px);
  pointer-events: none;
  transition: .22s ease;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #c64742; }

@media (max-width: 900px) {
  .translator-grid { grid-template-columns: 1fr; }
  .history-list { grid-template-columns: repeat(2, 1fr); }
  .result-stage { min-height: 320px; }
}

@media (max-width: 620px) {
  .topbar { width: calc(100% - 22px); padding-top: 16px; }
  .brand small { display: none; }
  .server-pill { padding: 9px 11px; font-size: 11px; }
  .page-shell { width: calc(100% - 22px); }
  .hero { padding: 34px 0 24px; }
  .hero h1 { font-size: 39px; }
  .hero-copy { font-size: 15px; }
  .panel { padding: 17px; border-radius: 22px; }
  textarea { min-height: 220px; font-size: 16px; }
  .result-stage { min-height: 300px; padding: 20px; }
  .result-copy p { font-size: 25px; }
  .history-list { grid-template-columns: 1fr; }
  .result-actions { grid-template-columns: 1fr 1fr; }
  #retryButton { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a1c;
    --panel: rgba(31,36,38,.88);
    --panel-solid: #1f2426;
    --ink: #f2f2ef;
    --muted: #a7afb2;
    --line: rgba(255,255,255,.12);
    --shadow: 0 24px 70px rgba(0,0,0,.28);
    --soft-shadow: 0 12px 32px rgba(0,0,0,.24);
  }
  body { background: radial-gradient(circle at 14% 8%, rgba(242,107,56,.15), transparent 28rem), radial-gradient(circle at 88% 12%, rgba(19,124,114,.17), transparent 30rem), var(--bg); }
  .brand-mark, .server-pill, .tone-chip, .icon-button, .history-card { background: rgba(35,41,43,.86); }
  textarea, #contextInput { color: var(--ink); background: rgba(25,30,32,.78); }
  .result-panel { background: linear-gradient(160deg, rgba(31,36,38,.96), rgba(25,38,37,.9)); }
  .result-stage { border-color: rgba(77,191,177,.16); background: radial-gradient(circle at 50% 0%, rgba(19,124,114,.16), transparent 58%), rgba(22,27,29,.6); }
  .result-copy p { color: #d9f4ee; }
  .empty-orbit span:nth-child(3) { background: #506168; }
}


/* One-tap voice translation */
.voice-action {
  display: grid;
  gap: 10px;
  margin: 0 0 16px;
}
.voice-button {
  position: relative;
  width: 100%;
  min-height: 92px;
  display: grid;
  grid-template-columns: 56px 1fr 12px;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid rgba(242,107,56,.22);
  border-radius: 20px;
  background: linear-gradient(135deg, rgba(242,107,56,.09), rgba(255,255,255,.76));
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease;
}
.voice-button:hover:not(:disabled) { transform: translateY(-2px); border-color: rgba(242,107,56,.42); box-shadow: 0 12px 28px rgba(242,107,56,.12); }
.voice-button:disabled { cursor: not-allowed; opacity: .62; }
.voice-icon {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  border-radius: 18px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), #f49b3a);
  box-shadow: 0 10px 24px rgba(242,107,56,.24);
  transition: .2s ease;
}
.voice-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.voice-copy { min-width: 0; }
.voice-copy strong { display: block; font-size: 17px; letter-spacing: -.01em; }
.voice-copy small { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.voice-status-dot { width: 10px; height: 10px; border-radius: 50%; background: #b5bbbd; transition: .2s ease; }
.voice-action[data-state="listening"] .voice-button { border-color: rgba(224,76,60,.5); background: linear-gradient(135deg, rgba(224,76,60,.16), rgba(255,255,255,.8)); box-shadow: 0 0 0 5px rgba(224,76,60,.08); }
.voice-action[data-state="listening"] .voice-icon { background: linear-gradient(135deg, #e04c3c, #f17b45); animation: voicePulse 1.35s ease-in-out infinite; }
.voice-action[data-state="listening"] .voice-status-dot { background: #e04c3c; box-shadow: 0 0 0 5px rgba(224,76,60,.14); animation: dotPulse 1s ease-in-out infinite; }
.voice-action[data-state="processing"] .voice-icon { background: linear-gradient(135deg, #3975c6, #4b9bd8); animation: voiceSpin 1s linear infinite; }
.voice-action[data-state="processing"] .voice-status-dot { background: #3975c6; }
.voice-action[data-state="speaking"] .voice-button { border-color: rgba(19,124,114,.42); background: linear-gradient(135deg, rgba(19,124,114,.13), rgba(255,255,255,.8)); }
.voice-action[data-state="speaking"] .voice-icon { background: linear-gradient(135deg, var(--teal), #2daa8f); }
.voice-action[data-state="speaking"] .voice-status-dot { background: var(--teal); box-shadow: 0 0 0 5px rgba(19,124,114,.14); animation: dotPulse 1s ease-in-out infinite; }
.voice-action[data-state="error"] .voice-button { border-color: rgba(199,72,68,.4); background: rgba(199,72,68,.08); }
.voice-action[data-state="error"] .voice-status-dot { background: #c74844; }
.auto-speak-toggle {
  display: inline-flex;
  align-items: center;
  justify-self: flex-start;
  gap: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  user-select: none;
}
.auto-speak-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #cbd0d2;
  transition: .2s ease;
}
.toggle-track i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(0,0,0,.18);
  transition: transform .2s ease;
}
.auto-speak-toggle input:checked + .toggle-track { background: var(--teal); }
.auto-speak-toggle input:checked + .toggle-track i { transform: translateX(16px); }
@keyframes voicePulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
@keyframes dotPulse { 0%,100% { opacity: .5; } 50% { opacity: 1; } }
@keyframes voiceSpin { from { transform: rotate(0); } to { transform: rotate(360deg); } }
@media (max-width: 620px) {
  .voice-button { grid-template-columns: 52px 1fr 10px; gap: 12px; padding: 14px; border-radius: 18px; }
  .voice-icon { width: 52px; height: 52px; border-radius: 16px; }
  .voice-copy strong { font-size: 16px; }
  .voice-copy small { font-size: 11.5px; }
}


.voice-button { touch-action: none; user-select: none; -webkit-user-select: none; }
.auto-translate-note {
  margin: 14px 0 0;
  text-align: center;
  color: #92999c;
  font-size: 12px;
  line-height: 1.6;
}


/* Compact single-column layout: Chinese input, result, then settings */
.translator-grid {
  grid-template-columns: minmax(0, 900px);
  justify-content: center;
}
.input-panel .result-panel {
  width: 100%;
  margin: 18px 0 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}
.input-panel .result-stage {
  min-height: 260px;
}
.input-panel .tone-block {
  margin-top: 22px;
}
@media (max-width: 620px) {
  .hero { padding: 24px 0 16px; }
  .hero h1 { font-size: 34px; }
  .hero-copy { display: none; }
  textarea { min-height: 140px; max-height: 180px; }
  .voice-button { min-height: 80px; }
  .input-panel .result-stage { min-height: 220px; padding: 18px; }
  .input-panel .result-copy p { font-size: 23px; }
  .input-panel .result-actions { margin-top: 10px; }
}
