:root {
  --bg: #0f1115;
  --bg-2: #171a21;
  --card: #1d212b;
  --border: #2a2f3c;
  --text: #e6e8ee;
  --muted: #9aa3b2;
  --accent: #5b8cff;
  --accent-hover: #7aa2ff;
  --danger: #ff5f6d;
  --good: #3ecf8e;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); margin-top: 0.5rem; min-height: 1.2em; }

#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.5rem;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 1.2rem; letter-spacing: 0.5px; background: none; border: 0; color: inherit; padding: 0; cursor: pointer; font-family: inherit; }
.brand:hover { opacity: 0.8; }
#user-area { display: flex; align-items: center; gap: 0.75rem; }

#app { max-width: 1600px; margin: 0 auto; padding: 1.5rem clamp(1rem, 3vw, 3rem); }

.btn {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.btn:hover { background: #262b38; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }

input[type="text"], input[type="password"], input[type="number"], input:not([type]), select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  border-radius: 6px;
  font-size: 0.95rem;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* AUTH */
.auth-card {
  max-width: 420px;
  margin: 3rem auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
}
.auth-card h1 { margin-top: 0; }
.tabs { display: flex; gap: 0.5rem; margin: 1rem 0; }
.tab {
  flex: 1; padding: 0.5rem; background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.tab.active { background: var(--bg-2); color: var(--text); border-color: var(--accent); }
.auth-form { display: flex; flex-direction: column; gap: 0.6rem; }

/* LIBRARY */
.library-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem;
}
.upload-btn { display: inline-flex; align-items: center; cursor: pointer; }
.library-list { display: grid; gap: 0.75rem; }
.doc-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex; justify-content: space-between; align-items: center;
  gap: 1rem;
}
.doc-card .doc-info { flex: 1; min-width: 0; }
.doc-card .title { font-weight: 600; margin-bottom: 0.25rem; word-break: break-word; }
.doc-card .meta { color: var(--muted); font-size: 0.85rem; }
.doc-card .progress-bar {
  height: 4px; background: var(--bg-2); border-radius: 2px; margin-top: 0.5rem; overflow: hidden;
}
.doc-card .progress-bar > div { height: 100%; background: var(--good); }
.doc-actions { display: flex; gap: 0.4rem; flex-shrink: 0; }
#upload-status { margin: 0.5rem 0; min-height: 1.2em; }

/* READER */
.reader-header {
  display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem;
  flex-wrap: wrap;
}
.reader-header h2 { margin: 0; flex: 1; min-width: 200px; word-break: break-word; }
.reader-tabs { display: flex; gap: 0.4rem; }
.rtab {
  padding: 0.4rem 0.8rem; background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px; cursor: pointer;
}
.rtab.active { background: var(--accent); border-color: var(--accent); color: white; }

.pane { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem; }

.pdf-controls {
  display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
  margin-bottom: 1rem;
}
.pdf-controls .spacer { flex: 1; }
.pdf-controls input[type="number"] { width: 60px; }
#pdf-container {
  display: flex; justify-content: center; overflow: auto; max-height: 75vh;
  background: #2a2f3c; border-radius: 6px; padding: 1rem;
}
#pdf-canvas { background: white; box-shadow: 0 2px 12px rgba(0,0,0,0.4); }

/* RSVP */
.rsvp-stage {
  background: var(--bg);
  border-radius: 10px;
  padding: 3rem 1rem;
  margin-bottom: 1rem;
  text-align: center;
  overflow-x: auto;       /* allow very long words to scroll horizontally if they exceed viewport */
  overflow-y: hidden;
}
.rsvp-word {
  font-size: clamp(2.2rem, 6vw, 4rem);
  font-weight: 600;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.5px;
  min-height: 1.5em;
  position: relative;
  width: 100%;
  display: block;
  white-space: nowrap;
  overflow: visible;
}
/* Focal letter is anchored at the exact horizontal center of the stage. */
.rsvp-word .focus {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--accent);
}
/* "before" sits to the LEFT of the focal letter, growing leftward. */
.rsvp-word .before {
  position: absolute;
  right: 50%;
  top: 50%;
  transform: translateY(-50%);
  text-align: right;
  white-space: pre;
  margin-right: 0.5ch; /* clear the focal letter's left half */
}
/* "after" sits to the RIGHT of the focal letter, growing rightward. */
.rsvp-word .after {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateY(-50%);
  text-align: left;
  white-space: pre;
  margin-left: 0.5ch; /* clear the focal letter's right half */
}
/* Vertical guide marks framing the focal column */
.rsvp-word::before,
.rsvp-word::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 1px;
  height: 0.6em;
  background: var(--border);
  transform: translateX(-50%);
  z-index: 0;
}
.rsvp-word::before { top: 0; }
.rsvp-word::after  { bottom: 0; }
.rsvp-progress {
  height: 4px; background: var(--bg-2); border-radius: 2px;
  overflow: hidden; margin: 1.5rem auto 0; max-width: 600px;
}
#rsvp-bar { height: 100%; background: var(--accent); width: 0%; transition: width 0.1s; }
.rsvp-meta {
  display: flex; justify-content: space-between; gap: 1rem;
  max-width: 600px; margin: 0.5rem auto 0;
  color: var(--muted); font-size: 0.9rem;
}

.rsvp-controls {
  display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap;
  margin-bottom: 1rem;
}

.rsvp-settings {
  display: grid; gap: 0.5rem;
  max-width: 600px; margin: 0 auto;
}
.rsvp-settings label { display: flex; align-items: center; gap: 0.5rem; }
.rsvp-settings input[type="range"] { width: 100%; }
.wpm-presets { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.checkbox { font-size: 0.9rem; }

/* Full text below RSVP */
.rsvp-fulltext-wrap {
  margin-top: 1.5rem;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}
.rsvp-fulltext-header {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.rsvp-fulltext {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  max-height: 50vh;
  overflow-y: auto;
  line-height: 1.7;
  font-size: 1rem;
  color: var(--muted);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.rsvp-fulltext .w {
  cursor: pointer;
  padding: 0 1px;
  border-radius: 3px;
  transition: background 0.1s, color 0.1s;
}
.rsvp-fulltext .w:hover { background: var(--bg-2); color: var(--text); }
.rsvp-fulltext .w.read { color: var(--text); }
.rsvp-fulltext .w.current {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

/* Modal */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  width: min(560px, 92vw);
  max-height: 85vh; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 0.5rem;
}
.modal-header h3 { margin: 0; }
.modal-header .btn-ghost { font-size: 1.4rem; padding: 0 0.6rem; line-height: 1; }
.share-create {
  display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap;
  margin: 1rem 0;
}
.share-list { display: flex; flex-direction: column; gap: 0.5rem; }
.share-row {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 0.6rem 0.8rem;
  display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
}
.share-row input[type="text"] {
  flex: 1; min-width: 200px; font-family: ui-monospace, monospace;
  font-size: 0.85rem;
}
.share-row .meta { font-size: 0.8rem; color: var(--muted); flex-basis: 100%; }
.share-row.revoked { opacity: 0.55; }
.share-row.revoked input { text-decoration: line-through; }

/* Public reader */
.public-banner {
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.5rem; font-size: 0.9rem; color: var(--muted);
}

/* ============ Admin & Profile ============ */
.admin-badge {
  display: inline-block;
  background: #6d28d9;
  color: #fff;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  margin: 0 0.5rem;
  vertical-align: middle;
}
.table-wrap { overflow-x: auto; margin-top: 1rem; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.75rem;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .role-admin {
  color: #a78bfa;
  font-weight: 700;
}
.data-table .role-user { color: var(--muted); }
.data-table .row-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}
.data-table .row-actions .btn { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.data-table .you-marker {
  font-size: 0.7rem;
  color: var(--muted);
  margin-left: 0.4rem;
}
