/* boardViva — professional, token-driven design system.
   Restrained depth, disciplined color, real dark mode. No gimmicks. */

/* ============================================================
   Tokens — light is the default; auto follows the OS; dark is explicit.
   ============================================================ */
:root,
:root[data-theme="light"] {
  color-scheme: light;

  --bg:            #f4f6f9;
  --surface:       #ffffff;
  --surface-2:     #f7f9fb;
  --surface-3:     #eef2f7;
  --border:        #e4e8ed;
  --border-strong: #cfd5dd;

  --text:          #141a22;
  --text-muted:    #4b5563;   /* AA on surfaces */
  --text-meta:     #566170;   /* AA — carries real content (roll, time) */
  --text-faint:    #7a8493;   /* decoration only */

  --accent:        #1f4e8c;   /* links, pill text on soft bg */
  --accent-hover:  #173d6f;
  --accent-soft:   #e9f0fa;

  --btn-primary-bg: #1f4e8c;
  --btn-primary-fg: #ffffff;
  --btn-primary-hover: #173d6f;

  --focus:         #2f6fd0;

  --danger:        #b3261e;
  --danger-soft:   #fbeae8;
  --danger-border: #f0c4c0;
  --success:       #17693f;
  --success-soft:  #e5f3ec;
  --success-border:#bfe0cd;

  --radius:    12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20, 26, 34, 0.05), 0 1px 1px rgba(20, 26, 34, 0.04);
  --shadow-md: 0 6px 20px rgba(20, 26, 34, 0.09);
  --shadow-pop:0 10px 30px rgba(20, 26, 34, 0.12);

  --font: system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "JetBrains Mono", Menlo,
    Consolas, monospace;
}
/* Tap-target base lives on its own plain :root so the mobile override wins by source order. */
:root { --tap: 40px; }

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    color-scheme: dark;

    --bg:            #0f1319;
    --surface:       #171c24;
    --surface-2:     #1c222b;
    --surface-3:     #232b36;
    --border:        #2a323d;
    --border-strong: #3b4551;

    --text:          #e8ecf2;
    --text-muted:    #aab4c2;
    --text-meta:     #9aa6b5;
    --text-faint:    #78828f;

    --accent:        #82b4ef;
    --accent-hover:  #a6cbf5;
    --accent-soft:   #1c2a3d;

    --btn-primary-bg: #7cb0ee;
    --btn-primary-fg: #0b1626;
    --btn-primary-hover: #9cc4f3;

    --focus:         #8fc2ff;

    --danger:        #f3b6b2;
    --danger-soft:   #34211f;
    --danger-border: #5a3330;
    --success:       #93d8b0;
    --success-soft:  #16281f;
    --success-border:#2e4a3a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-pop:0 10px 30px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0f1319;
  --surface:       #171c24;
  --surface-2:     #1c222b;
  --surface-3:     #232b36;
  --border:        #2a323d;
  --border-strong: #3b4551;

  --text:          #e8ecf2;
  --text-muted:    #aab4c2;
  --text-meta:     #9aa6b5;
  --text-faint:    #78828f;

  --accent:        #82b4ef;
  --accent-hover:  #a6cbf5;
  --accent-soft:   #1c2a3d;

  --btn-primary-bg: #7cb0ee;
  --btn-primary-fg: #0b1626;
  --btn-primary-hover: #9cc4f3;

  --focus:         #8fc2ff;

  --danger:        #f3b6b2;
  --danger-soft:   #34211f;
  --danger-border: #5a3330;
  --success:       #93d8b0;
  --success-soft:  #16281f;
  --success-border:#2e4a3a;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-pop:0 10px 30px rgba(0, 0, 0, 0.55);
}

/* ============================================================ Base */

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Smooth theme change — only while toggling (JS adds .theme-anim briefly). */
.theme-anim,
.theme-anim * {
  transition: background-color 0.2s ease, border-color 0.2s ease,
    color 0.18s ease, fill 0.18s ease !important;
}

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

/* Themed browser surfaces — the cheap signal a page was designed. */
::selection {
  background: color-mix(in srgb, var(--accent) 26%, transparent);
  color: var(--text);
}
input, textarea { caret-color: var(--accent); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 9999px;
  border: 3px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Icons: consistent 1.75–2 stroke, inherit currentColor. */
.i { flex: none; display: inline-block; vertical-align: -0.15em; }

/* ============================================================ Top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 22px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 1.06rem;
  letter-spacing: -0.02em;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.brand:hover { color: var(--text); text-decoration: none; }
.brand:hover .brand-accent { color: var(--accent-hover); }

.brand-mark {
  width: 27px;
  height: 27px;
  flex: none;
  border-radius: 8px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-fg);
  font-size: 0.85rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}
.brand-accent { color: var(--accent); }

.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ============================================================ Layout */

.wrap {
  width: 100%;
  max-width: 880px;
  margin: 0 auto;
  padding: 30px 22px 40px;
  flex: 1;
}

.page-title {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 0 0 6px;
}

.page-subtitle {
  color: var(--text-muted);
  margin: 0 0 26px;
  font-size: 1rem;
  max-width: 60ch;
}

/* ============================================================ Buttons */

.btn {
  font: inherit;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.2;
  box-shadow: var(--shadow-sm);
  transition: background 0.14s ease, border-color 0.14s ease,
    box-shadow 0.14s ease, color 0.14s ease, transform 0.14s ease;
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--text-faint);
  text-decoration: none;
  color: var(--text);
}
.btn:active { transform: translateY(1px); box-shadow: none; }

.btn-primary {
  background: var(--btn-primary-bg);
  border-color: transparent;
  color: var(--btn-primary-fg);
}
.btn-primary:hover {
  background: var(--btn-primary-hover);
  border-color: transparent;
  color: var(--btn-primary-fg);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--accent);
  box-shadow: none;
}
.btn-ghost:hover {
  background: var(--accent-soft);
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  color: var(--accent-hover);
}

.btn-sm { font-size: 0.86rem; padding: 6px 12px; min-height: var(--tap); }

.btn-danger { color: var(--danger); border-color: var(--danger-border); background: var(--surface); }
.btn-danger:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger.is-armed {
  background: var(--danger);
  border-color: var(--danger);
  color: var(--surface);
  font-weight: 700;
}

.btn[disabled], .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Icon-only button (theme toggle). */
.icon-btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
/* Show one icon at a time based on the effective theme. */
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: inline-block; }
:root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .i-sun { display: inline-block; }
  :root[data-theme="auto"] .i-moon { display: none; }
}

/* ============================================================ Focus (always visible) */

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ============================================================ Flash banners */

.flash {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  font-size: 0.94rem;
  font-weight: 500;
  border: 1px solid;
}
.flash .i { stroke-width: 2.2; }
.flash-ok { color: var(--success); background: var(--success-soft); border-color: var(--success-border); }
.flash-err { color: var(--danger); background: var(--danger-soft); border-color: var(--danger-border); }

/* ============================================================ Filter chips */

.filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 26px;
  padding-bottom: 4px;
}
.chip {
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: var(--tap);
  padding: 6px 13px;
  border-radius: 9999px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease,
    transform 0.14s ease;
}
.chip:hover { border-color: var(--text-faint); color: var(--text); }
.chip:active { transform: translateY(1px); }
.chip-n {
  font-variant-numeric: tabular-nums;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 9999px;
  background: var(--surface-3);
  color: var(--text-meta);
}
.chip.is-active {
  background: var(--accent);
  border-color: transparent;
  color: var(--btn-primary-fg);
}
.chip.is-active .chip-n {
  background: transparent;
  color: color-mix(in srgb, var(--btn-primary-fg) 78%, var(--accent));
}

/* ============================================================ Course sections */

.course { margin: 0 0 30px; scroll-margin-top: 78px; }
.course[hidden] { display: none; }

.course-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  font-size: 1.06rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.course-code {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 3px 8px;
  white-space: nowrap;
}
.course-name { color: var(--text); }
.course-count {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-meta);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9999px;
  padding: 2px 10px;
}

/* ============================================================ Question cards */

.qlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.qrow {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}
.qrow:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }

.qtext {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 500;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.qmeta {
  margin-top: 11px;
  padding-top: 11px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 0.82rem;
  color: var(--text-meta);
}
.qmeta .roll {
  font-family: var(--mono);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 600;
}
.qmeta .when { font-variant-numeric: tabular-nums; }

.copy-btn {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  min-width: 94px;      /* fits "Copied" / "Failed" → no jitter on label swap */
  justify-content: center;
  padding: 4px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.copy-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-faint); }
.copy-btn.is-copied { color: var(--success); border-color: var(--success-border); background: var(--success-soft); }
.copy-btn.is-failed { color: var(--danger); border-color: var(--danger-border); background: var(--danger-soft); }

/* Empty state */
.empty {
  color: var(--text-muted);
  font-size: 0.95rem;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 22px 18px;
  text-align: center;
  margin: 0;
}
.empty a { font-weight: 600; white-space: nowrap; }

/* ============================================================ Submission form */

.field { margin: 0 0 24px; }
.field label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 0.92rem; }
.field input {
  font: inherit;
  font-size: 1rem;              /* >=16px → no iOS auto-zoom */
  width: 100%;
  max-width: 260px;
  min-height: var(--tap);
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.field .hint { display: block; margin-top: 6px; font-size: 0.82rem; color: var(--text-meta); }

.form-section-title { font-size: 1.02rem; font-weight: 700; letter-spacing: -0.01em; margin: 30px 0 14px; }

.course-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 14px;
  padding: 4px 16px 16px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.course-block[aria-current="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow-sm); }
.course-block legend { font-weight: 700; font-size: 0.92rem; padding: 6px 6px 6px 0; display: flex; align-items: center; gap: 8px; }

.qboxes { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.qbox { position: relative; display: flex; gap: 8px; align-items: stretch; }
.qbox textarea {
  flex: 1;
  font: inherit;
  font-size: 1rem;
  min-height: 46px;
  padding: 9px 40px 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
  line-height: 1.5;
}
.qbox textarea::placeholder { color: var(--text-meta); opacity: 1; }
.qbox textarea:focus { background: var(--surface); }
.qbox-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.qbox-remove:hover { background: var(--danger-soft); color: var(--danger); }

.form-actions { margin-top: 26px; }
.submit-btn { padding: 11px 26px; font-size: 1rem; }

/* ============================================================ Admin */

.login {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  box-shadow: var(--shadow-sm);
}
.login-title { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 6px; }
.login label { font-weight: 700; font-size: 0.9rem; }
.login input {
  font: inherit;
  font-size: 1rem;
  width: 100%;
  min-height: var(--tap);
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}

.admin-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin: 0 0 18px;
}
.admin-count { margin: 0; color: var(--text-muted); font-size: 0.95rem; }
.admin-num { font-weight: 800; font-size: 1.15rem; color: var(--text); font-variant-numeric: tabular-nums; }
.admin-summary .logout { margin-left: auto; }

.table-scroll {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  -webkit-overflow-scrolling: touch;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.admin-table th, .admin-table td { padding: 11px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
.admin-table tbody tr:last-child td { border-bottom: none; }
.admin-table th {
  background: var(--surface-2);
  font-weight: 700;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  position: sticky;
  top: 0;
}
.admin-table tbody tr:hover td { background: var(--surface-2); }
.admin-table .qtext { min-width: 260px; white-space: pre-wrap; font-size: 0.9rem; }
.admin-table td.roll, .admin-table td.course { white-space: nowrap; font-family: var(--mono); font-size: 0.85rem; }
.admin-table td.when { white-space: nowrap; color: var(--text-meta); font-variant-numeric: tabular-nums; }
.admin-table .col-actions { text-align: right; }
.del-form { display: inline; }

/* ============================================================ Footer */

.site-foot { border-top: 1px solid var(--border); background: var(--surface); }
.site-foot-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 18px;
  padding-bottom: 18px;
  font-size: 0.85rem;
  color: var(--text-meta);
}

/* ============================================================ Motion */

@keyframes row-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
.qlist .qrow { animation: row-in 0.42s cubic-bezier(0.22, 0.61, 0.36, 1) both; }
.qlist .qrow:nth-child(1) { animation-delay: 0.02s; }
.qlist .qrow:nth-child(2) { animation-delay: 0.06s; }
.qlist .qrow:nth-child(3) { animation-delay: 0.10s; }
.qlist .qrow:nth-child(4) { animation-delay: 0.14s; }
.qlist .qrow:nth-child(5) { animation-delay: 0.18s; }
.qlist .qrow:nth-child(n+6) { animation-delay: 0.22s; }

/* ============================================================ Responsive */

@media (max-width: 600px) {
  :root { --tap: 44px; }
  .wrap { padding: 22px 15px 32px; }
  .topbar-inner { padding: 10px 15px; }
  .page-title { font-size: 1.5rem; }
  .filter { gap: 7px; }
  .chip { font-size: 0.82rem; padding: 6px 11px; }

  /* Cards: let the copy button claim a full-width thumb-friendly row. */
  .qmeta { flex-wrap: wrap; gap: 8px 14px; }
  .copy-btn { margin-left: auto; min-height: 40px; }

  /* Admin table: stack rows into labeled cards on narrow screens. */
  .table-scroll { border: none; background: transparent; box-shadow: none; overflow: visible; }
  .admin-table { font-size: 0.9rem; }
  .admin-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .admin-table, .admin-table tbody, .admin-table tr, .admin-table td { display: block; width: auto; }
  .admin-table tr {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px 12px;
    margin: 0 0 12px;
    box-shadow: var(--shadow-sm);
  }
  .admin-table td { border-bottom: none; padding: 7px 0; display: flex; justify-content: space-between; gap: 14px; }
  .admin-table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }
  .admin-table .qtext { min-width: 0; }
  .admin-table .qtext::before { display: block; margin-bottom: 2px; }
  .admin-table .col-actions { text-align: left; }
  .admin-table .col-actions::before { display: none; }
}

/* ============================================================ Reduced motion */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .theme-anim, .theme-anim * { transition: none !important; }
  .qlist .qrow { animation: none; }
  .qrow:hover, .btn:active, .chip:active { transform: none; }
}
