:root {
  color-scheme: light dark;
  --bg: #faf7f2;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665e;
  --line: #e7e1d7;
  --accent: #c2410c;
  --accent-text: #ffffff;
  --learner: #fde7d9;
  --unclear: #fde68a;
  --danger: #b91c1c;
  --ok: #15803d;
  --radius: 18px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  --gutter: max(16px, env(safe-area-inset-left), env(safe-area-inset-right));
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1f1c19;
    --text: #f3efe8;
    --muted: #a39d93;
    --line: #34302b;
    --accent: #fb923c;
    --accent-text: #1a1007;
    --learner: #3a2618;
    --unclear: #6b4e10;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent);
  outline-offset: 2px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 14px;
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  margin: 0;
}

/* Buttons */

.primary,
.secondary {
  border-radius: 999px;
  padding: 11px 20px;
  font-weight: 600;
  border: 1px solid transparent;
}

.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.secondary {
  background: var(--surface);
  border-color: var(--line);
}

.secondary.small {
  padding: 6px 12px;
  font-size: 14px;
  flex: none;
}

.link {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 4px;
  font-size: 15px;
}

.icon-button {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.icon {
  width: 20px;
  height: 20px;
}

/* Fetching a history reply's voices: dimmed and pulsing, and taps are ignored meanwhile. */
.replay[aria-busy="true"] {
  cursor: progress;
  animation: breathe 1.2s ease-in-out infinite;
}

/* Sign-in and setup */

.panel {
  max-width: 420px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 48px) var(--gutter) 32px;
}

.panel h1 {
  margin: 0 0 8px;
  font-size: 30px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
}

label.stack {
  gap: 6px;
  margin-top: 0;
  font-weight: 600;
  font-size: 15px;
}

input[type="email"] {
  width: 100%;
  font-size: 16px; /* 16px or more keeps iOS from zooming in on focus */
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 400;
}

.status {
  min-height: 1.4em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

/* Signed-in layout */

.layout {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 8px) var(--gutter) 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--line);
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 16px;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
}

.tab[aria-current="page"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.badge {
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  text-align: center;
}

.views,
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Talk */

.log-scroll {
  padding: 16px var(--gutter) 260px; /* room for the docked mic */
}

.log {
  list-style: none;
  margin: 0 auto;
  padding: 0;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.turn {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 86%;
}

.turn-learner {
  align-self: flex-end;
  align-items: flex-end;
}

.turn-tutor {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.turn-learner .bubble {
  background: var(--learner);
  border-bottom-right-radius: 6px;
}

.turn-tutor .bubble {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.bubble-text {
  margin: 0;
  overflow-wrap: anywhere;
}

mark.unclear {
  background: var(--unclear);
  color: inherit;
  border-radius: 4px;
  padding: 0 2px;
  text-decoration: underline dotted;
}

.token {
  white-space: nowrap;
}

/* Spanish stretches of a reply are the ones to learn from (and tap); English is plain support. */
.part-target {
  font-weight: 500;
}

.part-target .word {
  text-decoration: underline dotted color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 3px;
}

.part-native {
  color: var(--muted);
}

.word {
  all: unset;
  cursor: pointer;
  border-radius: 4px;
}

.word:hover,
.word:focus-visible {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.corrections-toggle {
  margin-top: 8px;
  padding: 2px 10px;
  border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);
  border-radius: 999px;
  background: transparent;
  font-size: 14px;
}

.corrections {
  list-style: none;
  margin: 10px 0 2px;
  padding: 0;
  display: grid;
  gap: 10px;
  font-size: 15px;
}

.corrections .said {
  color: var(--muted);
  text-decoration: line-through;
}

.corrections .better {
  color: var(--ok);
}

.corrections .why {
  display: block;
  color: var(--muted);
  font-size: 14px;
}

.new-words {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chips {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
}

.chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  font-size: 13px;
}

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px var(--gutter) calc(env(safe-area-inset-bottom) + 16px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  pointer-events: none;
}

.dock > * {
  pointer-events: auto;
}

.dock .status {
  margin: 0;
  max-width: 680px;
}

.starters {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 680px;
}

.starter {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 15px;
}

.input-row {
  width: 100%;
  max-width: 680px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.composer {
  flex: 1;
  min-width: 0; /* let the text field shrink instead of pushing the mic off-screen */
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.composer input {
  flex: 1;
  min-width: 0;
  font-size: 16px; /* 16px or more keeps iOS from zooming in on focus */
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.gloss {
  width: 100%;
  max-width: 680px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px 10px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.gloss-text {
  flex: 1;
  margin: 0;
}

.mic-dock {
  flex: none;
  width: 92px; /* fixed, so changing labels don't shift the text field */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.mic {
  width: 76px;
  height: 76px;
  display: grid;
  place-items: center;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform 0.15s;
}

.mic:active:not(:disabled) {
  transform: scale(0.96);
}

.mic .icon {
  width: 34px;
  height: 34px;
}

.mic .icon-stop,
.mic[data-state="recording"] .icon-mic {
  display: none;
}

.mic[data-state="recording"] .icon-stop {
  display: block;
}

.mic[data-state="recording"] {
  background: var(--danger);
  animation: pulse 1.4s ease-in-out infinite;
}

.mic[data-state="processing"] {
  cursor: progress;
  animation: breathe 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 45%, transparent);
  }
  50% {
    box-shadow: 0 0 0 14px transparent;
  }
}

@keyframes breathe {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mic {
    animation: none !important;
    transition: none;
  }
}

.mic-label {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.mic-clock {
  min-height: 1.2em;
  color: var(--danger);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

/* Review */

.review-view {
  align-items: center;
  padding: 24px var(--gutter) calc(env(safe-area-inset-bottom) + 24px);
}

.card {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 28px 20px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.card p {
  margin: 0;
}

.card-word {
  font-size: 34px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.card-meaning {
  font-size: 20px;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
