:root {
  --bg0: #f3efe6;
  --bg1: #e7f0ec;
  --ink: #14201e;
  --ink-soft: #3d4f4b;
  --muted: #6b7c77;
  --brand: #0f3d3a;
  --brand-2: #1b5c56;
  --accent: #c4a35a;
  --accent-soft: rgba(196, 163, 90, 0.18);
  --danger: #b42318;
  --ok: #1f7a4c;
  --card: rgba(255, 255, 255, 0.72);
  --card-solid: #fffdf8;
  --line: rgba(20, 32, 30, 0.1);
  --shadow: 0 18px 50px rgba(15, 61, 58, 0.12);
  --radius: 22px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --display: ui-serif, Georgia, Cambria, "Times New Roman", serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  background:
    radial-gradient(1200px 700px at 10% -10%, #d9ebe4 0%, transparent 55%),
    radial-gradient(900px 600px at 100% 0%, #f0e2c4 0%, transparent 50%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
select, input[type="range"] { width: 100%; }
button:disabled, select:disabled, input:disabled { cursor: not-allowed; opacity: 0.55; }
button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 3px solid #2f6fed;
  outline-offset: 3px;
}

.bg-orb {
  position: fixed;
  width: 48vw;
  height: 48vw;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.45;
  pointer-events: none;
  z-index: 0;
  animation: drift 16s ease-in-out infinite alternate;
}
.bg-orb-a { top: -8%; left: -10%; background: #9fd0c4; }
.bg-orb-b { right: -12%; bottom: 10%; background: #e4c989; animation-delay: -6s; }
.bg-grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(4%, 6%, 0) scale(1.08); }
}

.app {
  position: relative;
  z-index: 1;
  width: min(720px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(14px + var(--safe-t)) 16px calc(18px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: rise 0.6s ease both;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background:
    radial-gradient(circle at 30% 30%, #e8f3ef, transparent 45%),
    linear-gradient(145deg, var(--brand), var(--brand-2));
  box-shadow: 0 10px 24px rgba(15, 61, 58, 0.28);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 14px 10px 16px;
  border: 2.5px solid #e8f3ef;
  border-top: 0;
  border-radius: 0 0 40px 40px;
}
.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.55rem, 5vw, 1.9rem);
  letter-spacing: -0.03em;
  line-height: 1;
}
.brand-tag {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 500;
}

.top-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--brand);
  transition: transform 0.15s ease, background 0.15s ease;
}
.icon-btn:active { transform: scale(0.96); }

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 6px;
  border-radius: 18px;
  background: rgba(255, 253, 248, 0.7);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
  animation: rise 0.7s ease both;
}
.mode-btn {
  border-radius: 14px;
  padding: 12px 10px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--ink-soft);
  transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.mode-btn.is-active {
  background: var(--brand);
  color: #f7fbf9;
  box-shadow: 0 10px 24px rgba(15, 61, 58, 0.22);
}

.lang-pair {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: stretch;
  animation: rise 0.75s ease both;
}
.lang-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lang-card label {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.lang-card .voice-label { font-size: 0.62rem; margin-top: 1px; }
.lang-select, .voice-select, .drawer-body select {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card-solid);
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
}
.voice-select { font-size: 0.85rem; font-weight: 500; color: var(--ink-soft); }
.swap-btn {
  width: 44px;
  align-self: center;
  height: 44px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--brand);
  font-size: 1.2rem;
  font-weight: 700;
  border: 1px solid rgba(196, 163, 90, 0.35);
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 28px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-weight: 500;
  animation: rise 0.8s ease both;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 rgba(31, 122, 76, 0.45);
  flex: 0 0 auto;
}
.status-dot.is-listening {
  background: var(--accent);
  animation: pulse 1.2s ease infinite;
}
.status-dot.is-busy {
  background: #2f6fed;
  animation: pulse 1s ease infinite;
}
.status-dot.is-error { background: var(--danger); animation: none; }
.status-dot.is-paused { background: #8d6d2e; animation: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(196, 163, 90, 0.55); }
  70% { box-shadow: 0 0 0 12px rgba(196, 163, 90, 0); }
  100% { box-shadow: 0 0 0 0 rgba(196, 163, 90, 0); }
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.panel { display: none; animation: rise 0.45s ease both; }
.panel.is-visible { display: block; }
.hint-line {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
  margin-bottom: 14px;
}

.ptt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.ptt-btn {
  position: relative;
  overflow: hidden;
  min-height: 190px;
  border-radius: 28px;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 6px;
  text-align: left;
  color: #f4faf8;
  background:
    linear-gradient(160deg, rgba(255,255,255,0.14), transparent 40%),
    linear-gradient(155deg, #14524c, #0f3d3a 60%, #0b2e2b);
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s ease;
}
.ptt-btn[data-side="b"] {
  background:
    linear-gradient(160deg, rgba(255,255,255,0.16), transparent 40%),
    linear-gradient(155deg, #8d6d2e, #6d5320 55%, #4d3a14);
}
.ptt-btn:active,
.ptt-btn.is-held {
  transform: scale(0.985);
  filter: brightness(1.05);
  box-shadow: 0 10px 28px rgba(15, 61, 58, 0.28);
}
.ptt-btn.is-held .ptt-wave,
.ptt-btn.is-recording .ptt-wave {
  opacity: 1;
  transform: scale(1);
}
.ptt-btn.is-recording {
  outline: 3px solid rgba(255, 255, 255, 0.55);
  outline-offset: 3px;
  animation: recPulse 1.4s ease-in-out infinite;
}
.ptt-btn.is-starting { filter: saturate(0.65); }
@keyframes recPulse {
  0%, 100% { filter: brightness(1.05); }
  50% { filter: brightness(1.18); }
}
.ptt-flag { font-size: 1.7rem; line-height: 1; margin-bottom: auto; }
.ptt-lang {
  font-family: var(--display);
  font-size: 1.45rem;
  letter-spacing: -0.02em;
}
.ptt-action {
  font-size: 0.82rem;
  opacity: 0.85;
  font-weight: 500;
}
.ptt-wave {
  position: absolute;
  inset: auto -20% -35%;
  height: 70%;
  background: radial-gradient(circle at 50% 0%, rgba(255,255,255,0.28), transparent 60%);
  opacity: 0;
  transform: scale(0.8);
  transition: 0.25s ease;
  pointer-events: none;
}

.live-visual {
  position: relative;
  width: min(240px, 62vw);
  aspect-ratio: 1;
  margin: 8px auto 18px;
}
.live-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(15, 61, 58, 0.15);
  animation: spin 18s linear infinite;
  background:
    conic-gradient(from 0deg, transparent 0 70%, rgba(196,163,90,0.45), transparent);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 10px), #000 calc(100% - 9px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 10px), #000 calc(100% - 9px));
}
.live-core {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: linear-gradient(160deg, #1b5c56, #0f3d3a);
  color: #f4faf8;
  display: grid;
  place-items: center;
  text-align: center;
  font-weight: 700;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, background 0.2s ease;
}
.panel-live.is-on .live-core {
  background: linear-gradient(160deg, #b42318, #7a160f);
  animation: breathe 1.8s ease-in-out infinite;
}
.panel-live.is-paused .live-core {
  background: linear-gradient(160deg, #8d6d2e, #5d451b);
  animation: none;
}
.panel-live.is-on .live-ring { animation-duration: 4s; border-color: rgba(180, 35, 24, 0.25); }
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.04); }
}
@keyframes spin { to { transform: rotate(360deg); } }

.live-toggle {
  width: 100%;
  border-radius: 18px;
  padding: 16px 18px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #f7fbf9;
  background: linear-gradient(145deg, var(--brand-2), var(--brand));
  box-shadow: 0 14px 30px rgba(15, 61, 58, 0.25);
}
.live-controls { display: grid; gap: 9px; }
.live-controls .btn-secondary { width: 100%; }
.live-mute { background: rgba(15, 61, 58, 0.08); color: var(--brand); border-color: rgba(15, 61, 58, 0.16); }
.panel-live.is-on .live-toggle {
  background: linear-gradient(145deg, #c24137, #8f1f16);
}
.live-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.86rem;
  margin: 12px 0 0;
}
.live-warning {
  margin: 10px 0 0;
  padding: 10px 12px;
  border-radius: 13px;
  background: rgba(180, 35, 24, 0.07);
  color: #7a211a;
  font-size: 0.78rem;
  line-height: 1.4;
}

.transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: visible;
  padding-right: 2px;
  scroll-behavior: smooth;
}
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}
.bubble {
  background: var(--card-solid);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px 14px 12px;
  box-shadow: 0 8px 24px rgba(20, 32, 30, 0.05);
  animation: rise 0.35s ease both;
}
.bubble-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}
.bubble-dir {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15, 61, 58, 0.07);
  color: var(--brand);
}
.bubble-original {
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.45;
  margin-bottom: 8px;
}
.bubble-translation {
  font-size: 1.05rem;
  line-height: 1.45;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.live-input { border-left: 4px solid var(--accent); }
.live-output { border-left: 4px solid var(--brand-2); }
.bubble.is-interrupted { opacity: 0.72; border-style: dashed; }
.bubble-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.chip-btn {
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(15, 61, 58, 0.08);
  color: var(--brand);
  font-weight: 600;
  font-size: 0.82rem;
  border: 1px solid transparent;
}
.chip-btn:active { transform: scale(0.97); }
.chip-btn.is-playing {
  background: var(--brand);
  color: #f7fbf9;
}

.trust {
  text-align: center;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.4;
  margin-top: auto;
}
.trust p { margin: 0; }

.drawer[hidden] { display: none; }
.drawer {
  position: fixed;
  inset: 0;
  z-index: 40;
}
.dialog-open { overflow: hidden; }
.drawer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 24, 22, 0.45);
  backdrop-filter: blur(4px);
  animation: fade 0.2s ease both;
}
.drawer-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(88dvh, 720px);
  overflow: auto;
  background: #fffdf8;
  border-radius: 24px 24px 0 0;
  padding: 16px 16px calc(20px + var(--safe-b));
  box-shadow: 0 -20px 50px rgba(0,0,0,0.18);
  animation: sheet 0.28s ease both;
}
.drawer-panel:focus { outline: none; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.drawer-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
}
.drawer-body { display: flex; flex-direction: column; gap: 14px; }
.check {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 14px;
  background: rgba(15, 61, 58, 0.04);
  font-size: 0.95rem;
  line-height: 1.35;
}
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--brand); }
.field { display: flex; flex-direction: column; gap: 8px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field-meta {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
}
.field-meta strong { color: var(--brand); }
.btn-secondary {
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
  font-weight: 700;
  border: 1px solid rgba(180, 35, 24, 0.15);
}
.prose p { margin: 0 0 12px; line-height: 1.5; color: var(--ink-soft); }
.consent .drawer-panel { max-height: min(92dvh, 620px); }
.consent-check { background: rgba(196, 163, 90, 0.16); font-weight: 650; }
.consent-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.consent-actions .live-toggle { width: auto; padding: 12px 14px; font-size: 0.95rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(92vw, 420px);
  background: var(--ink);
  color: #f7fbf9;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: rise 0.25s ease both;
}
.toast[hidden] { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet {
  from { transform: translateY(24px); opacity: 0.6; }
  to { transform: translateY(0); opacity: 1; }
}

@media (max-width: 520px) {
  .app { padding-left: 10px; padding-right: 10px; gap: 10px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 12px; }
  .brand-tag { max-width: 48vw; font-size: 0.66rem; }
  .lang-pair { grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr); gap: 5px; }
  .lang-card { padding: 8px; gap: 5px; min-width: 0; }
  .lang-card label { font-size: 0.62rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .lang-select, .voice-select { padding: 9px 7px; font-size: 0.82rem; min-width: 0; }
  .swap-btn { width: 36px; height: 40px; border-radius: 12px; }
  .ptt-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .ptt-btn { min-height: 155px; padding: 15px 12px; border-radius: 22px; }
  .ptt-lang { font-size: 1.13rem; }
  .ptt-action { font-size: 0.74rem; }
  .live-visual { width: min(190px, 50vw); margin: 3px auto 12px; }
  .hint-line { margin-bottom: 9px; font-size: 0.8rem; }
  .status-bar { font-size: 0.82rem; }
}

@media (max-width: 350px) {
  .brand-tag { display: none; }
  .top-actions { gap: 4px; }
  .icon-btn { width: 38px; height: 38px; }
  .ptt-btn { min-height: 145px; }
}

@media (max-height: 700px) and (orientation: portrait) {
  .ptt-btn { min-height: 130px; }
  .live-visual { width: min(165px, 44vw); }
}

@media (min-width: 720px) {
  .app { padding-top: 28px; }
}

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