:root {
  --bg: #f5f1e8;
  --surface: #fffdf8;
  --surface-soft: #fbf7ef;
  --text: #1f2a32;
  --muted: #788087;
  --line: #ded8cc;
  --blue: #285f82;
  --blue-dark: #1c4964;
  --green: #2f6b57;
  --green-soft: #e2ede7;
  --green-dark: #244f40;
  --orange: #c9783f;
  --orange-dark: #a95f2d;
  --orange-soft: rgba(201, 120, 63, 0.22);
  --gold: #bd8a2f;
  --shadow: 0 14px 32px rgba(37, 43, 48, 0.12);
  --recorder-size: 136px;
  --recorder-dock-height: 206px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  overflow-x: hidden;
}

button {
  font: inherit;
}

.app-shell {
  width: min(100%, 720px);
  height: 100vh;
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 16px 0;
  overflow: hidden;
}

.home-view,
.translator-view {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.home-view {
  justify-content: center;
  gap: 38px;
}

.is-hidden {
  display: none;
}

.brand-block,
.top-bar {
  border-left: 5px solid var(--gold);
  padding-left: 14px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.16;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

h1 {
  font-size: clamp(35px, 9vw, 58px);
}

h2 {
  font-size: 21px;
}

.primary-action,
.speak-button,
.direction-button,
.secondary-action,
.modal-action {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.primary-action {
  width: 100%;
  min-height: 76px;
  background: var(--blue);
  color: white;
  font-size: 25px;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.modal-layer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(30, 35, 40, 0.36);
}

.modal-layer.is-hidden {
  display: none;
}

.modal-card {
  width: min(100%, 420px);
  background: var(--surface);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 24px 70px rgba(25, 30, 35, 0.22);
}

.modal-card h2 {
  font-size: 23px;
}

.modal-copy {
  margin: 14px 0 18px;
  color: #3c4850;
  font-size: 16px;
  line-height: 1.5;
}

.modal-copy p {
  margin: 0 0 9px;
}

.modal-action {
  width: 100%;
  min-height: 62px;
  background: var(--blue);
  color: white;
  font-size: 19px;
  font-weight: 800;
}

.modal-action span {
  font-size: 16px;
  font-weight: 700;
  opacity: 0.9;
}

.translator-view {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) var(--recorder-dock-height);
  gap: 8px;
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
}

.direction-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.direction-button {
  min-width: 0;
  min-height: 42px;
  padding: 6px 8px;
  background: #ece7dc;
  color: #586069;
  font-size: 17px;
  font-weight: 800;
  overflow-wrap: anywhere;
  border: 1px solid #d7d0c4;
}

.direction-button[data-mode="chinese"].is-active {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
  box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.18);
}

.direction-button[data-mode="english"].is-active {
  background: var(--green);
  color: white;
  border-color: var(--green);
  box-shadow: inset 0 -3px 0 rgba(255, 255, 255, 0.18);
}

.direction-button[data-mode="english"]:not(.is-active) {
  background: var(--green-soft);
  color: var(--green-dark);
  border-color: #c3d7cd;
}

.direction-button[data-mode="chinese"]:not(.is-active) {
  background: #e8eef2;
  color: var(--blue-dark);
  border-color: #cbd7df;
}

.content-area {
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 9px;
  min-height: 0;
  overflow: hidden;
}

.text-panel {
  min-height: 0;
  max-height: none;
  padding: 12px 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.text-panel.translated {
  background: var(--surface-soft);
}

.panel-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex: 0 0 auto;
}

.text-panel p {
  margin: 6px 0 0;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.42;
  overflow-wrap: anywhere;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.secondary-action {
  width: auto;
  min-width: 96px;
  min-height: 34px;
  padding: 6px 10px;
  background: var(--blue);
  color: white;
  font-size: 14px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.secondary-action:disabled {
  cursor: not-allowed;
  opacity: 0.38;
}

.speak-actions {
  position: sticky;
  bottom: 0;
  z-index: 5;
  width: 100%;
  height: var(--recorder-dock-height);
  display: grid;
  justify-items: center;
  align-content: end;
  grid-template-rows: 26px var(--recorder-size) 22px;
  gap: 6px;
  padding: 8px 0 10px;
  pointer-events: none;
}

.speak-actions::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(-1 * env(safe-area-inset-bottom));
  width: 100vw;
  height: calc(var(--recorder-dock-height) + 30px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(245, 241, 232, 0), rgba(245, 241, 232, 0.96) 34%, var(--bg));
  z-index: -1;
  pointer-events: none;
}

.speak-actions > * {
  pointer-events: auto;
}

.mic-hint {
  min-height: 24px;
  max-width: min(100%, 520px);
  margin: 0;
  color: var(--orange-dark);
  font-size: 14px;
  font-weight: 800;
  text-align: center;
  line-height: 1.3;
}

.mic-hint.is-warning {
  color: #9a4f34;
}

.speak-button {
  position: relative;
  width: min(40vw, var(--recorder-size));
  aspect-ratio: 1;
  min-width: 132px;
  min-height: 132px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 22px;
  border-radius: 999px;
  background: radial-gradient(circle at 35% 25%, #e3a06e, var(--orange));
  color: white;
  text-align: center;
  box-shadow: 0 18px 42px rgba(169, 95, 45, 0.28);
}

.speak-button::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: inherit;
  background: var(--orange-soft);
  opacity: 0;
  transform: scale(0.96);
  z-index: -1;
}

.speak-button.is-pressed::before {
  animation: record-glow 1.35s ease-in-out infinite;
}

.speak-button span,
.speak-button strong {
  display: block;
  overflow-wrap: anywhere;
}

.speak-button span {
  font-size: 21px;
  font-weight: 900;
}

.speak-button strong {
  margin-top: 4px;
  font-size: 19px;
}

.speak-button.is-pressed {
  background: radial-gradient(circle at 35% 25%, #dd935e, var(--orange-dark));
}

.listening-feedback {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-height: 28px;
  color: var(--orange-dark);
  font-size: 15px;
  font-weight: 800;
  opacity: 0;
  visibility: hidden;
  transition: opacity 160ms ease;
}

.listening-feedback.is-visible {
  opacity: 1;
  visibility: visible;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--orange);
  animation: pulse 1.2s ease-in-out infinite;
  flex: 0 0 auto;
}

.wave-bars {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 18px;
}

.wave-bars i {
  display: block;
  width: 4px;
  height: calc(7px + (var(--mic-level, 0) * 15px));
  border-radius: 999px;
  background: var(--orange);
  opacity: calc(0.45 + (var(--mic-level, 0) * 0.55));
  transform: scaleY(calc(0.8 + (var(--mic-level, 0) * 0.9)));
  transform-origin: center;
  transition: height 80ms linear, opacity 80ms linear, transform 80ms linear;
}

.wave-bars i:nth-child(2) {
  animation-delay: 0.1s;
}

.wave-bars i:nth-child(3) {
  animation-delay: 0.2s;
}

.wave-bars i:nth-child(4) {
  animation-delay: 0.3s;
}

.privacy-note {
  display: none;
}

@keyframes record-glow {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.96);
  }

  50% {
    opacity: 0.95;
    transform: scale(1.08);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.9);
  }

  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

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

@media (max-width: 380px) {
  .app-shell {
    padding: 15px 14px;
  }

  .translator-view {
    grid-template-rows: auto auto minmax(0, 1fr) var(--recorder-dock-height);
  }

  .brand-block,
  .top-bar {
    padding-left: 12px;
  }

  h2 {
    font-size: 21px;
  }

  .direction-button {
    font-size: 16px;
  }

  .text-panel p {
    font-size: 18px;
  }

  .text-panel {
    max-height: none;
  }

  .speak-button {
    width: min(40vw, var(--recorder-size));
    min-width: 128px;
    min-height: 128px;
  }

  .speak-button span {
    font-size: 20px;
  }

  .speak-button strong {
    font-size: 18px;
  }
}
