/* LinguaMind SPA — design system locked in CLAUDE.md:
   paper #FAFAF7, ink #0F172A, accent #0EA5E9, SF Pro (system) typography.
   Mirrors the iOS app's look so the WKWebView surface and native screens feel
   like one product. NO Google Fonts (intentional divergence from tandem). */

:root {
  --paper:        #FAFAF7;
  --ink:          #0F172A;
  --muted:        #475569;
  --line:         rgba(15, 23, 42, 0.08);
  --accent:       #0EA5E9;
  --accent-ink:   #FFFFFF;
  --warn:         #DC2626;
  --good:         #059669;

  --radius:       12px;
  --radius-sm:    8px;
  --shadow-sm:    0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md:    0 4px 14px rgba(15, 23, 42, 0.08);

  --font-sans:    -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
                  "Helvetica Neue", Inter, system-ui, sans-serif;
  --font-mono:    ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:      #0A0A0A;
    --ink:        #FAFAF7;
    --muted:      #94A3B8;
    --line:       rgba(250, 250, 247, 0.10);
    --accent:     #38BDF8;
    --accent-ink: #0A0A0A;
    --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md:  0 4px 14px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* --- Header ---------------------------------------------------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
  font-size: 0.95rem;
}

.brand-word { font-size: 1rem; }

.tabs {
  display: flex;
  gap: 0.25rem;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.85rem;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}
.tab:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.tab[aria-current="page"] { color: var(--ink); background: color-mix(in srgb, var(--ink) 9%, transparent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Main / container ------------------------------------------------ */

main {
  flex: 1;
  padding: 1.25rem max(1rem, env(safe-area-inset-left)) 2rem;
  padding-right: max(1rem, env(safe-area-inset-right));
}

.container {
  max-width: 760px;
  margin: 0 auto;
}

h1 { font-size: 1.75rem; letter-spacing: -0.02em; margin: 0 0 0.5rem; }
h2 { font-size: 1.15rem; letter-spacing: -0.01em; margin: 1.5rem 0 0.5rem; }
p  { color: var(--muted); margin: 0.5rem 0 1rem; line-height: 1.55; }

.note { color: var(--muted); font-size: 0.9rem; }
.note-sep { color: var(--muted); opacity: 0.4; margin: 0 0.5rem; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Form primitives ------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0;
}
.field label { font-size: 0.85rem; color: var(--muted); font-weight: 500; }
.field input,
.field textarea,
.field select {
  appearance: none;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
  font: inherit;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.field textarea { min-height: 9rem; resize: vertical; line-height: 1.5; }
.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  transition: transform 80ms ease, background 120ms ease, border-color 120ms ease;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 5%, var(--paper)); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn-primary:hover { background: color-mix(in srgb, var(--ink) 88%, transparent); }

.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

/* --- Cards ------------------------------------------------------------ */

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  margin: 0.6rem 0;
}
.card-row { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
.card-title { font-weight: 600; }
.card-meta { color: var(--muted); font-size: 0.85rem; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.75rem;
  color: var(--muted);
}
.pill-good  { color: var(--good);  border-color: color-mix(in srgb, var(--good)  35%, var(--line)); }
.pill-warn  { color: var(--warn);  border-color: color-mix(in srgb, var(--warn)  35%, var(--line)); }
.pill-accent{ color: var(--accent);border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }

/* --- Flashcard surface ------------------------------------------------ */

.flashcard {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 2rem 1.5rem;
  min-height: 18rem;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.flashcard .phrase   { font-size: 2rem; letter-spacing: -0.01em; line-height: 1.15; }
.flashcard .gloss    { font-size: 1.25rem; color: var(--muted); }
.flashcard .sentence { font-size: 0.95rem; color: var(--muted); font-style: italic; }
.flashcard .grades   { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.4rem; margin-top: 1rem; }
.flashcard .grade-btn{ padding: 0.7rem 0.4rem; }

/* --- Tutor chat ------------------------------------------------------- */

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-bottom: 5rem;
}
.msg {
  max-width: 80%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.5;
}
.msg-user      { align-self: flex-end; background: var(--ink); color: var(--paper); border-color: var(--ink); }
.msg-assistant { align-self: flex-start; background: var(--paper); }
.msg-system    { align-self: center; color: var(--muted); background: transparent; border: none; font-size: 0.85rem; }

.composer {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 0;
  background: color-mix(in srgb, var(--paper) 96%, transparent);
  backdrop-filter: blur(12px);
}
.composer textarea {
  flex: 1;
  min-height: 2.6rem;
  max-height: 8rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  background: var(--paper);
  color: var(--ink);
  resize: vertical;
}

/* --- Empty states + errors ------------------------------------------- */

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
}
.empty-glyph { font-size: 2rem; margin-bottom: 0.75rem; opacity: 0.6; }

.error {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--line));
  background: color-mix(in srgb, var(--warn) 8%, var(--paper));
  color: var(--warn);
}

/* --- Footer ----------------------------------------------------------- */

.app-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.25rem;
  padding: 1.25rem 1rem max(1.25rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.app-footer .note { text-decoration: none; }
.app-footer .note:hover { color: var(--ink); }
