/* PhraseWeaver — accessible, single-column, content-focused stylesheet. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Source+Serif+4:wght@400;600&display=swap');

/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --brand:        #0f766e;   /* teal-700 — primary brand */
  --brand-dark:   #0c5e57;
  --brand-soft:   #ccfbf1;   /* teal-100 — soft brand background */
  --accent:       #c2410c;   /* orange-700 — accent / mastered */
  --accent-soft:  #ffedd5;
  --bg:           #fdfcf8;   /* warm off-white page */
  --surface:      #ffffff;   /* card surface */
  --surface-alt:  #f5f3ee;   /* subtle stripe / hover */
  --text:         #1a1a1a;
  --text-muted:   #525252;
  --text-subtle:  #737373;
  --border:       #e7e5e0;
  --border-strong:#9ca3af;
  --focus:        #2563eb;   /* blue-600 — high-contrast focus ring */
  --error:        #b91c1c;
  --error-soft:   #fef2f2;
  --success:      #15803d;
  --success-soft: #f0fdf4;
  --warning:      #b45309;
  --warning-soft: #fffbeb;
  --info-soft:    #eff6ff;
  --radius:       10px;
  --radius-sm:    6px;
  --shadow:       0 1px 2px rgba(20, 30, 50, 0.04), 0 1px 3px rgba(20, 30, 50, 0.05);
  --shadow-hover: 0 4px 8px rgba(20, 30, 50, 0.06), 0 2px 4px rgba(20, 30, 50, 0.06);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.65;
  max-width: 72ch;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 4rem;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ── Skip link (visible on focus) ──────────────────────────────────────────── */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.skip-link:focus {
  position: static;
  width: auto;
  height: auto;
  display: inline-block;
  padding: 0.5rem 0.875rem;
  margin-bottom: 1rem;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius-sm);
  text-decoration: underline;
  font-weight: 600;
}

/* ── Navigation ────────────────────────────────────────────────────────────── */
nav {
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0 0.875rem;
  margin-bottom: 1.75rem;
}
nav ul { list-style: none; padding: 0; margin: 0; }
nav li { display: inline-block; margin-right: 1.25rem; }
nav li:last-child { margin-right: 0; }
nav a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}
nav a:hover { color: var(--brand); border-bottom-color: var(--brand); }
nav li:first-child a {
  font-family: "Source Serif 4", Georgia, serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--brand);
  letter-spacing: -0.01em;
}
nav li:first-child a:hover { border-bottom-color: transparent; color: var(--brand-dark); }
nav form { display: inline; margin: 0; }
nav form button {
  background: none;
  border: none;
  color: var(--text);
  font: inherit;
  font-weight: 500;
  font-size: 0.95rem;
  padding: 0.25rem 0;
  margin: 0;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: border-color 0.15s ease, color 0.15s ease;
}
nav form button:hover { color: var(--brand); border-bottom-color: var(--brand); }

/* Credit balance line under nav */
body > p[aria-label="Credit balance"] {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin: 0 0 1.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  display: inline-block;
}
body > p[aria-label="Credit balance"] a {
  color: var(--brand);
  font-weight: 500;
}

/* ── Typography ────────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: "Source Serif 4", Georgia, serif;
  color: var(--text);
  letter-spacing: -0.015em;
  line-height: 1.25;
  margin-top: 1.75rem;
  margin-bottom: 0.625rem;
}
h1 {
  font-size: 2rem;
  font-weight: 600;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}
h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-top: 2rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--border);
}
h3 {
  font-size: 1.15rem;
  font-weight: 600;
}
h4, h5, h6 { font-size: 1rem; font-weight: 600; }

p { margin: 0.625rem 0; }

a {
  color: var(--brand);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color 0.15s ease;
}
a:hover { color: var(--brand-dark); text-decoration-thickness: 2px; }
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

code, kbd {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-alt);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
kbd { border: 1px solid var(--border); }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
fieldset {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem 1.25rem 1.25rem;
  margin-bottom: 1.25rem;
  border-radius: var(--radius);
}
legend {
  font-weight: 600;
  padding: 0 0.4rem;
  color: var(--text);
  font-size: 0.95rem;
}

label {
  display: block;
  margin-top: 0.875rem;
  font-weight: 500;
  font-size: 0.95rem;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="search"],
input[type="tel"],
select,
textarea {
  display: block;
  width: 100%;
  padding: 0.55rem 0.7rem;
  margin-top: 0.3rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
input[type="number"]:focus,
input[type="search"]:focus,
input[type="tel"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  display: inline-block;
  margin: 0 0.5rem 0 0;
  accent-color: var(--brand);
  transform: scale(1.1);
}
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

textarea { min-height: 8rem; line-height: 1.5; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
button,
input[type="submit"] {
  display: inline-block;
  margin-top: 0.875rem;
  margin-right: 0.4rem;
  padding: 0.55rem 1.1rem;
  font: inherit;
  font-weight: 500;
  font-size: 0.97rem;
  cursor: pointer;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
button:hover,
input[type="submit"]:hover {
  background: var(--surface-alt);
  border-color: var(--text-muted);
}
button:focus-visible,
input[type="submit"]:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Form submit buttons get the primary brand treatment */
input[type="submit"],
button[type="submit"] {
  color: #ffffff;
  background: var(--brand);
  border-color: var(--brand);
  font-weight: 600;
}
input[type="submit"]:hover,
button[type="submit"]:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  color: #ffffff;
}

button[disabled],
input[type="submit"][disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ── Django messages / aria-live alerts ───────────────────────────────────── */
.messages { list-style: none; padding: 0; margin: 0 0 1.25rem; }
.messages li {
  padding: 0.7rem 0.95rem;
  border-left: 4px solid var(--brand);
  background: var(--info-soft);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  font-size: 0.97rem;
}
.messages li.error   { border-left-color: var(--error);   background: var(--error-soft); }
.messages li.warning { border-left-color: var(--warning); background: var(--warning-soft); }
.messages li.success { border-left-color: var(--success); background: var(--success-soft); }

/* ── Details / summary ─────────────────────────────────────────────────────── */
details {
  margin: 0.75rem 0;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
}
details[open] { background: var(--surface); }
summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  padding: 0.15rem 0;
}
summary:hover { color: var(--brand); }
summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Cards (article, section) ──────────────────────────────────────────────── */
article, section {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ── Audio player ──────────────────────────────────────────────────────────── */
audio {
  display: block;
  margin-top: 0.6rem;
  width: 100%;
  height: 36px;
}

/* ── Footer ────────────────────────────────────────────────────────────────── */
footer {
  border-top: 1px solid var(--border);
  margin-top: 3rem;
  padding-top: 1rem;
  color: var(--text-subtle);
  font-size: 0.875rem;
}
footer p { margin: 0; }

/* ── Help text ─────────────────────────────────────────────────────────────── */
.help-text {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
  line-height: 1.5;
}

/* ── Dashboard ─────────────────────────────────────────────────────────────── */
.dashboard-page { position: relative; }

.island-list { list-style: none; padding: 0; margin: 0 0 1.25rem; }

.island-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 0.85rem;
  position: relative;
  box-shadow: var(--shadow);
  transition: box-shadow 0.18s ease, transform 0.18s ease, border-left-color 0.18s ease;
}
.island-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-1px);
}

/* Island theme accents — refined: only the left rail tints, body stays clean */
.island-tropical-beach  { border-left-color: #d97706; }
.island-volcano         { border-left-color: #b91c1c; }
.island-jungle          { border-left-color: #15803d; }
.island-oasis           { border-left-color: #0d9488; }
.island-cliffs          { border-left-color: #1d4ed8; }
.island-bioluminescent  { border-left-color: #7c3aed; }
.island-monsoon         { border-left-color: #334155; }
.island-glacier         { border-left-color: #64748b; }
.island-coral           { border-left-color: #db2777; }
.island-bamboo          { border-left-color: #65a30d; }

.island-link {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.2rem;
  font-weight: 600;
  text-decoration: none;
  letter-spacing: -0.01em;
}
.island-link:hover,
.island-link:focus { text-decoration: underline; text-decoration-thickness: 2px; }

.island-edit-controls { margin-top: 0.6rem; }
.island-rename-input  { width: 100%; margin-top: 0.3rem; margin-bottom: 0.5rem; }

/* Familiarity / mastery badge inline with text */
.familiarity-badge,
.mastered-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 0.4rem;
}

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

/* ── Flashcards ────────────────────────────────────────────────────────────── */
.flashcard-controls { margin-bottom: 1.25rem; }
.flashcard-controls button { margin-right: 0.5rem; margin-bottom: 0.4rem; }

.flashcard-back {
  margin-top: 0.85rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.flashcard-record-status,
.phrase-record-status {
  display: block;
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--info-soft);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  color: var(--text);
  min-height: 1.5rem;
}
.flashcard-record-status:empty,
.phrase-record-status:empty { display: none; }

/* ── Island detail / phrases ───────────────────────────────────────────────── */
.island-toolbar {
  margin-bottom: 1.25rem;
  padding: 0.75rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.island-toolbar form { display: inline; margin: 0; }
.island-toolbar button { margin-top: 0.3rem; margin-bottom: 0.3rem; }

.phrase-list { list-style: none; padding: 0; margin: 0 0 1.25rem; }

.phrase-card {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0.95rem 1.15rem;
  margin-bottom: 0.65rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: box-shadow 0.18s ease;
}
.phrase-card:hover { box-shadow: var(--shadow-hover); }

.phrase-meta {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.phrase-text {
  margin: 0.3rem 0;
  font-size: 1.08rem;
  line-height: 1.55;
}
.phrase-phonetic {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--text-muted);
  font-size: 0.9rem;
}
.phrase-translation {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
}
.phrase-grammar {
  margin-top: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: var(--brand-soft);
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
}

.phrase-edit { margin-top: 0.75rem; }
.phrase-edit-btn,
.phrase-delete-btn,
.phrase-cancel-btn,
.phrase-update-btn,
.phrase-speaker-toggle-btn,
.phrase-record-btn,
.phrase-play-btn,
.phrase-play-source-btn,
.phrase-play-target-btn,
.flashcard-record-btn {
  font-size: 0.92rem;
  padding: 0.4rem 0.85rem;
  margin-top: 0.4rem;
}
.phrase-delete-btn,
.island-delete-btn {
  color: var(--error);
  border-color: #fca5a5;
}
.phrase-delete-btn:hover,
.island-delete-btn:hover {
  background: var(--error-soft);
  border-color: var(--error);
  color: var(--error);
}

/* ── Dialog (native <dialog>) ──────────────────────────────────────────────── */
dialog {
  max-width: 48ch;
  width: 90%;
  padding: 1.5rem 1.5rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(20, 30, 50, 0.18), 0 4px 12px rgba(20, 30, 50, 0.12);
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgba(15, 23, 42, 0.5); }
dialog h2 { margin-top: 0; border-bottom: none; padding-bottom: 0; }
dialog p { margin: 0.6rem 0; }
dialog button { margin-top: 0.85rem; }

/* ── Audio gate notice ─────────────────────────────────────────────────────── */
#audio-gate-notice {
  padding: 0.65rem 0.9rem;
  background: var(--warning-soft);
  border-left: 4px solid var(--warning);
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.92rem;
  color: var(--text);
}
#audio-gate-notice[hidden] { display: none; }

/* ── Tags / labels (e.g., language tags) ───────────────────────────────────── */
.tags {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  margin-right: 0.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--brand-soft);
  color: var(--brand-dark);
  border-radius: 999px;
}

/* ── Mastery / familiarity SVG accents ─────────────────────────────────────── */
.mastery-fill-circle { stroke: var(--accent); }
