/* ============================================================
   English Proficiency Test — Design System
   Clean & academic: warm paper, deep slate ink, academic blue.
   Fonts: Spectral (display serif) + IBM Plex Sans (UI)
   ============================================================ */

:root {
  /* --- Surfaces --- */
  --paper:        #F6F4EF;   /* app background — warm off-white */
  --surface:      #FFFFFF;   /* cards / panels */
  --surface-2:    #FBFAF6;   /* inset / subtle fill */
  --surface-3:    #F1EEE7;   /* deeper inset */

  /* --- Ink / text --- */
  --ink:          #1B2A3A;   /* primary text — deep slate-navy */
  --ink-soft:     #4E5D6B;   /* secondary */
  --ink-faint:    #8995A1;   /* tertiary / hints */

  /* --- Lines --- */
  --line:         #E2DED5;   /* warm border */
  --line-soft:    #EDE9E1;
  --line-strong:  #CFC9BD;

  /* --- Brand --- */
  --primary:      #1F4B7A;   /* academic blue */
  --primary-deep: #163A60;
  --primary-700:  #12314F;
  --primary-soft: #E9F0F7;
  --primary-tint: #F2F6FB;
  --primary-ring: rgba(31, 75, 122, 0.22);

  /* --- Accent (used sparingly: seals, score) --- */
  --accent:       #A77E2E;   /* restrained brass */
  --accent-soft:  #F4EEDF;

  /* --- Semantic --- */
  --correct:      #2E7D52;
  --correct-soft: #E6F1EA;
  --correct-line: #BFDCCB;
  --incorrect:    #BC3B2C;
  --incorrect-soft:#FAEAE7;
  --incorrect-line:#EAC4BD;
  --warn:         #B5791C;
  --warn-soft:    #FBF1DD;

  /* --- Radius --- */
  --r-xs: 5px;
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-pill: 999px;

  /* --- Shadow (restrained, academic) --- */
  --sh-sm: 0 1px 2px rgba(27,42,58,0.05), 0 1px 1px rgba(27,42,58,0.04);
  --sh-md: 0 2px 6px rgba(27,42,58,0.06), 0 4px 14px rgba(27,42,58,0.05);
  --sh-lg: 0 8px 28px rgba(27,42,58,0.10), 0 2px 8px rgba(27,42,58,0.06);
  --sh-pop: 0 18px 50px rgba(20,40,64,0.18);

  /* --- Fonts --- */
  --font-ui:   "IBM Plex Sans", system-ui, -apple-system, sans-serif;
  --font-serif:"Spectral", Georgia, serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;

  /* --- Layout --- */
  --shell-max: 1180px;
  --read-max: 760px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#root { min-height: 100vh; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

p { margin: 0; }

button { font-family: inherit; cursor: pointer; }

a { color: var(--primary); text-decoration: none; }

::selection { background: var(--primary-soft); }

/* Scrollbars */
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-thumb { background: #d8d3c8; border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #c4beb0; background-clip: content-box; }

/* ============================================================
   Typography helpers
   ============================================================ */
.serif { font-family: var(--font-serif); }
.mono  { font-family: var(--font-mono); }

.display {
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.08;
}

.eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-ui);
  font-size: 14.5px;
  font-weight: 500;
  line-height: 1;
  padding: 11px 18px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--surface);
  color: var(--ink);
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease, transform .05s ease, color .15s ease;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--sh-sm);
}
.btn-primary:hover { background: var(--primary-deep); border-color: var(--primary-deep); }

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn-ghost:hover { background: var(--surface-2); border-color: var(--ink-faint); }

.btn-subtle {
  background: var(--surface-3);
  color: var(--ink);
  border-color: transparent;
}
.btn-subtle:hover { background: #e8e4db; }

.btn-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--ink-soft);
  padding: 8px 12px;
}
.btn-quiet:hover { background: var(--surface-3); color: var(--ink); }

.btn-danger {
  background: transparent;
  border-color: var(--incorrect-line);
  color: var(--incorrect);
}
.btn-danger:hover { background: var(--incorrect-soft); }

.btn-lg { padding: 14px 26px; font-size: 16px; border-radius: var(--r-md); }
.btn-sm { padding: 8px 13px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ============================================================
   Cards / panels
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-sm);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

/* ============================================================
   Form fields
   ============================================================ */
.field { display: flex; flex-direction: column; gap: 7px; }
.label {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
}
.hint { font-size: 12.5px; color: var(--ink-faint); }

.input, .textarea, .select {
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  width: 100%;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-ring);
}
.input::placeholder, .textarea::placeholder { color: var(--ink-faint); }

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238995A1' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* ============================================================
   Badges / chips
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  color: var(--ink-soft);
  white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary-deep); }
.badge-listen  { background: #EAF0F6; color: #2A5687; }
.badge-read    { background: #F1EDE2; color: #8A6A22; }
.badge-correct { background: var(--correct-soft); color: var(--correct); }
.badge-incorrect { background: var(--incorrect-soft); color: var(--incorrect); }

/* ============================================================
   Utility
   ============================================================ */
.row { display: flex; align-items: center; }
.col { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.spread { justify-content: space-between; }
.center { justify-content: center; align-items: center; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.divider { height: 1px; background: var(--line); border: 0; margin: 0; }

.kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 2px 6px;
  color: var(--ink-soft);
}

/* Fade-in for view transitions */
@keyframes viewIn {
  from { transform: translateY(8px); }
  to   { transform: translateY(0); }
}

/* Recording pulse dot */
@keyframes recPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

/* Speaking prep ring shimmer */
@keyframes speakRing {
  0%   { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -364; }
}
.view-in { animation: viewIn .3s ease; }

@media (prefers-reduced-motion: reduce) {
  .view-in { animation: none; }
  * { scroll-behavior: auto !important; }
}

/* ============================================================
   Responsive — mobile breakpoints
   ============================================================ */

/* Home: two-card grid stacks on small screens */
@media (max-width: 640px) {
  .home-cards {
    grid-template-columns: 1fr !important;
    max-width: 100% !important;
  }
}

/* Test: reading/image two-column layout stacks on mobile */
@media (max-width: 720px) {
  .two-col {
    display: block !important;
  }
  .two-col > * + * {
    margin-top: 22px;
  }
}

/* Results: summary stat grid stacks on very small screens */
@media (max-width: 480px) {
  .results-summary {
    grid-template-columns: 1fr !important;
  }
}

/* Admin: hamburger button — hidden on desktop, shown on mobile */
.admin-menu-btn { display: none !important; }

@media (max-width: 767px) {
  .admin-menu-btn {
    display: inline-flex !important;
  }

  /* Sidebar slides in from the left as an overlay */
  .admin-sidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: var(--sh-pop);
  }
  .admin-sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Backdrop behind open sidebar */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(20, 32, 46, 0.45);
    z-index: 39;
    cursor: pointer;
  }

  /* Admin header: hide label text, keep icons */
  .admin-btn-label { display: none; }

  /* Test header: tighten on mobile */
  .test-header-title { display: none; }
}

@media (min-width: 768px) {
  .sidebar-backdrop { display: none; }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
