/* ===========================================================================
   EN ⇄ 日本語 — conversation translator styles
   Mobile-first, dark by default with a light-scheme variant. Two-sided chat:
   Japanese-origin turns align left, English-origin turns align right.
   =========================================================================== */
:root {
  --bg: #0f172a;
  --bg-elev: #1e293b;
  --bg-elev-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #f43f5e;
  --accent-2: #fb7185;
  --ring: #f43f5e55;
  --ok: #34d399;
  --err: #f87171;

  /* Per-language bubble accents for the two sides of the table. */
  --ja-bubble: #1e3a5f;
  --ja-edge: #38bdf8;
  --en-bubble: #3b2440;
  --en-edge: #fb7185;

  --radius: 18px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: radial-gradient(120% 80% at 50% 0%, #1b2540 0%, var(--bg) 60%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Hiragino Sans", "Noto Sans JP", "Yu Gothic", system-ui, sans-serif;
  min-height: 100dvh;
  line-height: 1.5;
}

/* App shell: a column that fills the viewport so the mic dock anchors low. */
.app {
  max-width: 620px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(14px, env(safe-area-inset-top)) 16px
    calc(14px + env(safe-area-inset-bottom));
  gap: 12px;
}

/* Header ------------------------------------------------------------------ */
.app__header {
  text-align: center;
  flex: 0 0 auto;
}
.app__title {
  font-size: 1.45rem;
  font-weight: 800;
  margin: 0;
  letter-spacing: 1px;
}
.app__subtitle {
  margin: 2px 0 0;
  font-size: 0.74rem;
  color: var(--muted);
  letter-spacing: 0.4px;
}

/* Transcript -------------------------------------------------------------- */
.transcript {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 6px 2px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
  max-width: 280px;
  padding: 24px 12px;
}
.empty__icon {
  font-size: 2.6rem;
  margin: 0 0 10px;
}
.empty__text {
  margin: 0;
  font-size: 1rem;
  line-height: 1.55;
}

/* A conversation turn ----------------------------------------------------- */
.turn {
  --bubble: var(--bg-elev);
  --edge: var(--accent-2);
  max-width: 86%;
  background: var(--bubble);
  border-radius: var(--radius);
  padding: 12px 14px;
  border: 1px solid #ffffff10;
  box-shadow: 0 6px 18px -12px #000;
  animation: rise 0.28s ease both;
}
/* Japanese-origin turns sit on the left; English-origin on the right. */
.turn--ja {
  align-self: flex-start;
  --bubble: var(--ja-bubble);
  --edge: var(--ja-edge);
  border-bottom-left-radius: 6px;
}
.turn--en {
  align-self: flex-end;
  --bubble: var(--en-bubble);
  --edge: var(--en-edge);
  border-bottom-right-radius: 6px;
}

.turn__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.turn__tags {
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--edge);
}
.turn__play {
  background: #ffffff14;
  border: none;
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  width: 38px;
  height: 32px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, transform 0.12s ease;
  flex: 0 0 auto;
}
.turn__play:active {
  transform: scale(0.92);
}
.turn__play.is-playing {
  background: var(--edge);
  color: #0b1220;
  animation: pulse 1.2s ease infinite;
}

.turn__original {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--muted);
}
.turn__translation {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.55;
  font-weight: 600;
  word-break: break-word;
}
.turn__romaji {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px dashed #ffffff1f;
  font-size: 0.92rem;
  font-style: italic;
  color: var(--muted);
}

/* Status & error ---------------------------------------------------------- */
.status {
  flex: 0 0 auto;
  margin: 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
  min-height: 1.2em;
}
.status--busy {
  color: var(--accent-2);
}
.status--busy::after {
  content: "";
  display: inline-block;
  width: 1.1em;
  text-align: left;
  animation: dots 1.2s steps(4, end) infinite;
}
.error {
  flex: 0 0 auto;
  margin: 0;
  background: #7f1d1d33;
  border: 1px solid #ef444455;
  color: #fecaca;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
}

/* Manual typing panel ----------------------------------------------------- */
.typer {
  flex: 0 0 auto;
  background: var(--bg-elev);
  border: 1px solid #ffffff12;
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: rise 0.22s ease both;
}
.typer__direction {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.typer__lang {
  font-weight: 600;
  font-size: 0.95rem;
  min-width: 70px;
  text-align: center;
}
.typer__swap {
  background: var(--bg-elev-2);
  color: var(--accent-2);
  border: none;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  font-size: 1.2rem;
  cursor: pointer;
  transition: transform 0.25s ease;
}
.typer__swap:active {
  transform: rotate(180deg) scale(0.9);
}
.typer__text {
  width: 100%;
  background: var(--bg-elev-2);
  border: 1px solid #ffffff10;
  border-radius: 12px;
  outline: none;
  resize: vertical;
  color: var(--text);
  font-size: 1.1rem;
  font-family: inherit;
  line-height: 1.55;
  min-height: 64px;
  padding: 10px 12px;
}
.typer__text::placeholder {
  color: #64748b;
}
.typer__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.typer__actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.counter {
  font-size: 0.72rem;
  color: var(--muted);
}
.textbtn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 6px 4px;
}
.textbtn:active {
  color: var(--accent-2);
}
.typer__go {
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 10px 18px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.typer__go:active {
  transform: scale(0.97);
}
.typer__go:disabled {
  filter: grayscale(0.5) brightness(0.7);
  cursor: default;
}

/* Control dock: mic hero centered, secondary controls flanking ------------ */
.dock {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 8px;
}
.ctrl {
  background: var(--bg-elev);
  border: 1px solid #ffffff12;
  color: var(--text);
  border-radius: 16px;
  font-size: 1.3rem;
  width: 56px;
  height: 56px;
  cursor: pointer;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, transform 0.12s ease;
}
.ctrl:active {
  transform: scale(0.94);
}
.ctrl.is-active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

/* The mic — the prominent hero control. */
.mic {
  position: relative;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  flex: 0 0 auto;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  box-shadow: 0 12px 30px -8px var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, filter 0.2s ease;
}
.mic:active {
  transform: scale(0.96);
}
.mic__icon {
  font-size: 2.4rem;
  line-height: 1;
  z-index: 1;
}
.mic__ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  pointer-events: none;
}
.mic.is-recording {
  background: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
}
.mic.is-recording .mic__ring {
  box-shadow: 0 0 0 0 #ef444488;
  animation: ripple 1.4s ease-out infinite;
}
.mic.is-busy {
  cursor: default;
}
.mic.is-busy .mic__icon {
  visibility: hidden;
}
.mic.is-busy .mic__ring {
  border: 4px solid #ffffff55;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
}
.mic.is-unavailable {
  filter: grayscale(0.6) brightness(0.7);
}

/* Footer / health --------------------------------------------------------- */
.app__footer {
  flex: 0 0 auto;
  text-align: center;
  font-size: 0.72rem;
}
.health {
  color: var(--muted);
}
.health.ok {
  color: var(--ok);
}
.health.bad {
  color: var(--err);
}

/* Shared spinner (typing button) ------------------------------------------ */
.spinner {
  width: 16px;
  height: 16px;
  border: 2.5px solid #ffffff55;
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Animations -------------------------------------------------------------- */
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes pulse {
  50% {
    opacity: 0.55;
  }
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}
@keyframes ripple {
  0% {
    box-shadow: 0 0 0 0 #ef444488;
  }
  100% {
    box-shadow: 0 0 0 26px #ef444400;
  }
}
@keyframes dots {
  0% {
    content: "";
  }
  25% {
    content: ".";
  }
  50% {
    content: "..";
  }
  75% {
    content: "...";
  }
}

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

/* Light scheme ------------------------------------------------------------ */
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5f9;
    --bg-elev: #ffffff;
    --bg-elev-2: #eef2f7;
    --text: #0f172a;
    --muted: #64748b;
    --ja-bubble: #e0f2fe;
    --ja-edge: #0369a1;
    --en-bubble: #ffe4e6;
    --en-edge: #be123c;
  }
  body {
    background: radial-gradient(120% 80% at 50% 0%, #ffe4e6 0%, var(--bg) 55%);
  }
  .turn {
    border-color: #00000010;
    box-shadow: 0 4px 14px -10px #000;
  }
  .turn__play {
    background: #00000010;
  }
  .ctrl {
    border-color: #00000012;
    box-shadow: 0 1px 3px #0000000f;
  }
  .typer__text {
    border-color: #00000012;
  }
}
