/* Margot - phone first, deliberately plain. A Fable visual pass comes
   later; this is structure and touch targets, not decoration. */

:root {
  --bg: #1d1b19;
  --panel: #272421;
  --panel-2: #322e2a;
  --ink: #f2ede6;
  --ink-quiet: #a9a099;
  --accent: #d98f4e;
  --accent-ink: #2a1c0e;
  --error: #e2705f;
  --radius: 12px;
  --tap: 48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { overflow: hidden; }

/* Beats any class that sets display; a class must never unhide. */
[hidden] { display: none !important; }

.screen { display: none; height: 100%; }
.screen.active { display: flex; flex-direction: column; }

.stack {
  margin: auto;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 30rem;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stack.center { text-align: center; align-items: center; }

h1, h2, h3 { margin: 0; font-weight: 600; }
.brand { font-size: 2.4rem; letter-spacing: 0.01em; }
.tagline { margin: 0; color: var(--ink-quiet); }
.quiet { color: var(--ink-quiet); font-size: 0.88rem; margin: 0; }

label {
  font-size: 0.85rem;
  color: var(--ink-quiet);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input[type="text"], input[type="password"], select {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px solid #4a433d;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  font-size: 1rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); }

button {
  min-height: var(--tap);
  padding: 12px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
button:disabled { opacity: 0.5; }
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid #4a433d;
}
button.big { width: 100%; }
button.huge {
  width: 100%;
  min-height: 96px;
  font-size: 1.3rem;
  border-radius: 20px;
}

form { display: flex; flex-direction: column; gap: 10px; }

.error { color: var(--error); margin: 0; font-size: 0.92rem; }

.banner {
  padding: 12px 16px;
  background: #4a3a22;
  color: #f6e2c8;
  font-size: 0.9rem;
}

/* profiles */
.profile-list { display: flex; flex-direction: column; gap: 10px; }
.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid #4a433d;
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 1.1rem;
  text-align: left;
  font-weight: 500;
}
.dot { width: 22px; height: 22px; border-radius: 50%; flex: none; }

.color-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.color-chip {
  width: var(--tap);
  height: var(--tap);
  min-height: var(--tap);
  border-radius: 50%;
  padding: 0;
  border: 3px solid transparent;
}
.color-chip[aria-pressed="true"] { border-color: var(--ink); }

/* app shell */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px calc(10px);
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid #4a433d;
}
.who { font-weight: 600; flex: none; }
.tabs { display: flex; gap: 6px; margin-left: auto; }
.tab, .icon {
  min-height: 40px;
  padding: 8px 14px;
  background: transparent;
  color: var(--ink-quiet);
  border: 1px solid #4a433d;
  font-size: 0.9rem;
}
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.view { display: none; flex: 1; min-height: 0; flex-direction: column; }
.view.active { display: flex; }

/* chat */
.persona-chips {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
}
.persona {
  flex: none;
  min-height: 40px;
  padding: 8px 14px;
  background: var(--panel);
  color: var(--ink-quiet);
  border: 1px solid #4a433d;
  font-size: 0.92rem;
}
.persona.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg { max-width: 88%; padding: 12px 14px; border-radius: 16px; }
.msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg.tutor { align-self: flex-start; background: var(--panel); }
.msg.pending { color: var(--ink-quiet); font-style: italic; }
.msg.failed { background: #4a2b26; }

.fr {
  display: inline-block;
  margin: 1px 0;
  padding: 1px 6px;
  border-radius: 7px;
  background: var(--panel-2);
  border-bottom: 2px solid var(--accent);
  color: var(--ink);
  font: inherit;
  min-height: 0;
  cursor: pointer;
}
.msg.user .fr { background: rgba(0,0,0,0.16); color: var(--accent-ink); }
.fr.speaking { background: var(--accent); color: var(--accent-ink); }

.feedback {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed #4a433d;
  color: var(--ink-quiet);
  font-size: 0.9rem;
  font-style: italic;
}

#chat-form {
  flex-direction: row;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid #4a433d;
}
#chat-send { flex: none; }

/* sound grid */
.sound-grid { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; }
.cat-label { margin: 18px 0 4px; font-size: 1.05rem; }
.cat-label:first-child { margin-top: 0; }
.cat-blurb { color: var(--ink-quiet); font-size: 0.86rem; margin: 0 0 10px; }
.cells {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.cell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-height: 96px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid #4a433d;
  color: var(--ink);
  text-align: left;
  font-weight: 400;
}
.cell.speaking { border-color: var(--accent); }
.cell .ipa { font-size: 1.4rem; font-weight: 600; color: var(--accent); }
.cell .spell { font-size: 0.78rem; color: var(--ink-quiet); }
.cell .word { font-size: 1.05rem; font-weight: 600; }
.cell .gloss { font-size: 0.78rem; color: var(--ink-quiet); }
.cell .hint { font-size: 0.78rem; color: var(--ink-quiet); margin-top: 4px; }

/* settings sheet */
.voice-list { display: flex; flex-direction: column; gap: 8px; }
.voice-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: 1px solid #4a433d;
}
.voice-row.current { border-color: var(--accent); }
.voice-name { flex: 1; }
.voice-mark { color: var(--accent); font-weight: 700; }

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
}
.sheet-inner {
  width: 100%;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
