/* Exam Bean — base styles (minimal scaffold; to be expanded with the full
   News Bean design system as the app grows).
*/

:root {
  --paper: #F7F3EB;
  --paper-2: #EFE8D7;
  --ink: #2A2824;
  --ink-2: #1E1D1A;
  --muted: #7A7468;
  --muted-2: #B8B0A0;
  --line: #DFD7C4;
  --line-2: #CDC3AE;
  --accent: #4B8BF5;
  --accent-2: #3B6FCA;
  --accent-soft: #A5C4FA;
  --err: #C33636;
  --err-soft: #F3D0D0;
  --r-sm: 10px;
  --r-md: 14px;
  --font-serif: 'Iowan Old Style', 'Palatino', Georgia, 'Source Han Serif SC', 'Noto Serif CJK SC', serif;
  --font-display: 'Avenir Next', 'SF Pro Display', -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--ink); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* hero */
.home-hero {
  position: relative;
  padding: 48px 24px 24px;
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.home-admin-link {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.home-admin-link:hover,
.home-admin-link:active {
  background: var(--paper-2);
  color: var(--ink);
}
.home-hero h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 32px;
  letter-spacing: -0.02em;
  margin: 0 0 6px;
}
.home-hero .tagline {
  color: var(--muted);
  font-size: 14px;
  margin: 0;
}

.home-main {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 16px 120px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 64px 16px;
}

.home-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
}
.section-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex: 1 1 auto;
}
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.chip.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.chip:not(.active):hover { color: var(--ink); border-color: var(--line-2); }
#homeSearch {
  flex: 0 0 200px;
  padding: 8px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--paper);
  font-size: 14px;
}
#homeSearch:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.card-tags {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag {
  font-size: 11px;
  color: var(--muted);
  background: var(--paper);
  padding: 2px 6px;
  border-radius: 4px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
  transition: transform 0.1s, border-color 0.15s;
}
.card:hover { border-color: var(--line-2); }
.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
}
.card-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
}
.badge {
  background: var(--ink);
  color: var(--paper);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}
.badge.free {
  background: #1A5F33;
  color: #D6F0E0;
}

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.06s;
  background: transparent;
  color: var(--ink);
}
.btn:active { transform: scale(0.97); }
.btn.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn.primary:hover { background: var(--ink-2); }
.btn.ghost {
  background: transparent;
  border-color: var(--line-2);
}
.btn.ghost:hover { background: var(--paper-2); }

/* =====================================================================
   Detail page — study-key gate + split-pane reader + explain panel
   ===================================================================== */

.detail-page { height: 100vh; overflow: hidden; }
.detail-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

/* study-key gate */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  z-index: 30;
  padding: 16px;
}
.gate-card {
  max-width: 420px;
  width: 100%;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 28px 24px;
  text-align: center;
}
.gate-card h2 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0 0 6px;
}
.gate-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.gate-help { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.gate-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--paper);
  font-size: 16px;
  margin-bottom: 8px;
}
.gate-card input:focus { outline: 2px solid var(--accent-soft); }
.gate-error { color: var(--err); font-size: 13px; min-height: 18px; margin-bottom: 10px; }
.gate-actions {
  display: flex; gap: 10px; justify-content: center;
}

/* top bar */
.detail-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  z-index: 20;
  flex-shrink: 0;
}
.top-back {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: 999px;
  color: var(--ink);
}
.top-back:active { background: var(--paper-2); }
.top-title {
  flex: 1 1 auto;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
}
.top-spacer { width: 36px; }

/* font size control */
.fs-wrap { position: relative; }
.fs-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 1px;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 999px;
  font-family: var(--font-display);
  font-weight: 600;
  cursor: pointer;
  transition: background .18s, color .18s;
}
.fs-btn:hover, .fs-btn:active { background: var(--paper-2); color: var(--ink); }
.fs-btn .fs-a-small { font-size: 11px; }
.fs-btn .fs-a-big   { font-size: 16px; }
.fs-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  box-shadow: 0 6px 20px rgba(0,0,0,0.08);
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 50;
  min-width: 64px;
}
.fs-opt {
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  color: var(--ink);
  text-align: left;
}
.fs-opt:hover { background: var(--paper-2); }
.fs-opt.active {
  background: var(--accent);
  color: #fff;
}

/* body-level font-size classes scale the passage text + translation */
body.fs-s .para { font-size: 15px; line-height: 1.7; }
body.fs-m .para { font-size: 17px; line-height: 1.8; }
body.fs-l .para { font-size: 20px; line-height: 1.9; }
@media (min-width: 768px) {
  body.fs-s .para { font-size: 16px; }
  body.fs-m .para { font-size: 18px; }
  body.fs-l .para { font-size: 22px; }
}

/* main content — holds pane(s) + divider as a flex column */
.detail-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.pane {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 18px 140px;
  /* isolate each pane's internals from the global layout graph — when the
     flex ratio changes, the pane's child word-spans don't force a reflow
     of anything outside this box */
  contain: layout style paint;
  /* prevent long-press text-selection menu; single-tap lookup instead */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.para {
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 1.8;
  color: var(--ink);
  margin: 0 0 14px;
}

/* word + collocation spans */
.w {
  display: inline;
  padding: 1px 0;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.1s;
}
.w:active { background: rgba(75, 139, 245, 0.18); }
.coll {
  display: inline;
  border-bottom: 2px solid var(--accent-soft);
  border-radius: 2px;
}
.coll .w:active { background: rgba(75, 139, 245, 0.18); }

/* divider */
.divider {
  flex: 0 0 18px;
  position: relative;
  cursor: row-resize;
  background: transparent;
  touch-action: none;
}
.divider::before {
  content: "";
  position: absolute;
  left: 0; right: 0;
  top: 50%;
  height: 1px;
  background: var(--line);
}
.divider-handle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 54px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted-2);
  opacity: 0.7;
}
.divider:active .divider-handle { background: var(--accent); opacity: 1; }
.detail-main.split .divider {
  background: var(--paper);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
/* While dragging: freeze pane scrollbars. Size is driven by inline
   `flex: 0 0 Npx` set in JS — don't override it from CSS. */
.detail-main.dragging .pane {
  overflow-y: hidden;
  pointer-events: none;
  will-change: flex-basis;
}
.detail-main.dragging {
  touch-action: none;
}
.detail-main.dragging .divider-handle {
  background: var(--accent);
  opacity: 1;
}

/* split FAB */
.split-fab {
  position: fixed;
  right: 14px;
  bottom: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  border: none;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
  cursor: pointer;
  z-index: 40;
}
.split-fab:active { transform: scale(0.95); }
.split-fab-icon { font-size: 15px; }

/* explain panel (ported from News Bean) */
.explain {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 100px);
  width: min(92%, 500px);
  background: #1C1A17;
  color: #FAF8F3;
  border-radius: 14px;
  padding: 14px 16px 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  z-index: 80;
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.2s ease;
}
.explain.show { transform: translate(-50%, 0); opacity: 1; }
.explain-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.explain-word {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #FAF8F3;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.explain-actions { display: flex; gap: 6px; }
.ico-btn {
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center; justify-content: center;
  border-radius: 999px;
  border: none;
  background: rgba(250, 248, 243, 0.08);
  color: #FAF8F3;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ico-btn:hover, .ico-btn:active { background: rgba(250, 248, 243, 0.18); }
.ico-btn svg { width: 16px; height: 16px; }

.explain-line2 {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0;
}
.explain-phon {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 14px;
  color: rgba(165, 196, 250, 0.9);
  letter-spacing: 0.02em;
}
.explain-ctx {
  font-size: 14px;
  color: rgba(250, 248, 243, 0.96);
  font-weight: 500;
}
.explain-mean {
  font-size: 14px;
  margin-top: 10px;
  line-height: 1.6;
  color: rgba(250, 248, 243, 0.78);
}
.explain-breakdown {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(250, 248, 243, 0.15);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.bd-row { font-size: 13px; line-height: 1.5; color: rgba(250, 248, 243, 0.85); }
.bd-row .bd-word { font-weight: 600; color: rgba(250, 248, 243, 0.95); }
.bd-row .bd-sep { color: rgba(250, 248, 243, 0.45); }
.explain-base {
  margin-top: 10px;
  font-size: 12px;
  color: rgba(250, 248, 243, 0.65);
  font-style: italic;
}

/* responsive tweaks */
@media (max-width: 500px) {
  .para { font-size: 16px; line-height: 1.75; }
  .pane { padding: 16px 14px 140px; }
}

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

.admin-page { background: var(--paper); min-height: 100vh; }
.admin-shell { padding: 24px 16px 80px; }
.admin-main { max-width: 900px; margin: 0 auto; }

/* dedicated login page — centered card, not the dashboard chrome */
.admin-login-page {
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-2) 100%);
  min-height: 100vh;
  min-height: 100dvh;
}
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px 48px;
  position: relative;
}
.login-back {
  position: absolute;
  top: 20px;
  left: 20px;
  color: var(--muted);
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.login-back:hover { background: var(--paper-2); color: var(--ink); }

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 12px 40px rgba(42, 40, 36, 0.06);
  padding: 40px 32px 32px;
}

.login-brand {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.login-brand h1 {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  color: var(--ink);
}
.login-sub {
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

.login-form label {
  display: block;
  margin-bottom: 16px;
}
.login-form label > span {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.login-form input {
  width: 100%;
  padding: 12px 14px;
  font-size: 15px;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--paper);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.login-form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(75, 139, 245, 0.18);
}
.login-submit {
  width: 100%;
  margin-top: 4px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
}
.login-form .admin-status { margin-bottom: 12px; }

@media (max-width: 480px) {
  .login-card { padding: 32px 24px 28px; border-radius: 14px; }
  .login-brand h1 { font-size: 22px; }
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.admin-header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0;
}
.admin-header .spacer { flex: 1; }
.admin-header .back-link {
  color: var(--muted);
  font-size: 14px;
}
.admin-header .back-link:hover { color: var(--ink); }

.btn.small { padding: 6px 12px; font-size: 13px; }

.admin-status {
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: 14px;
  margin: 0 0 16px;
}
.admin-status.info { background: #E8ECF5; color: #2A2A2A; }
.admin-status.ok { background: #D6F0E0; color: #1A5F33; }
.admin-status.err { background: #F8D9D9; color: #7B1E1E; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.admin-table th { color: var(--muted); font-weight: 600; font-size: 13px; }
.admin-table tr:hover td { background: var(--paper-2); }

/* upload form */
.upload-form label {
  display: block;
  margin: 0 0 14px;
}
.upload-form label > span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.upload-form input[type="text"],
.upload-form input[type="password"],
.upload-form input[type="number"],
.upload-form select,
.upload-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--paper);
}
.upload-form textarea { resize: vertical; line-height: 1.5; }
.upload-form input:focus,
.upload-form select:focus,
.upload-form textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
.upload-form .row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

/* AI box */
.ai-box {
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  margin: 0 0 16px;
  background: var(--paper-2);
}
.ai-box legend {
  padding: 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.btn.ai {
  background: linear-gradient(135deg, #6E56CF 0%, #3B82F6 100%);
  color: #fff;
  border: none;
  padding: 10px 18px;
  font-weight: 600;
}
.btn.ai:hover { filter: brightness(1.08); }
.btn.ai:disabled { opacity: 0.55; cursor: wait; }
.btn.ai .ai-icon { font-size: 15px; }

.ai-fill-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--paper-2);
  border: 1px dashed var(--line-2);
  border-radius: var(--r-sm);
  margin: 6px 0 16px;
}
.ai-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
  flex: 1 1 200px;
}
.ai-status { font-size: 13px; padding: 4px 10px; border-radius: 999px; }
.ai-status.info { background: #E8ECF5; color: #2A2A2A; }
.ai-status.ok { background: #D6F0E0; color: #1A5F33; }
.ai-status.err { background: #F8D9D9; color: #7B1E1E; }

@media (max-width: 640px) {
  .upload-form .row.two { grid-template-columns: 1fr; }
  .admin-table { font-size: 13px; }
  .admin-table th, .admin-table td { padding: 8px 10px; }
}
