/* ═══════════════════════════════════════════════════════════════
   Tables Turned — The Commons Table
   "A table at night with one lamp."
   ═══════════════════════════════════════════════════════════════ */

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --void: #0a0a0a;
  --surface: #111111;
  --card: #1a1a1a;
  --border: #2a2a2a;
  --border-mid: #3a3a3a;
  --text: #d4c5a9;
  --text-dim: #8a7e6a;
  --text-muted: #5a5347;
  --text-bright: #e8dcc6;
  --gold: #c9a84c;
  --ember: #b8860b;
  --warm: #d4a44c;
  --green: #4a7a4a;
  --red: #7a4a4a;
  --serif: Georgia, 'Times New Roman', serif;
  --mono: 'Courier New', Courier, monospace;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  background: var(--void);
  color: var(--text);
  font-family: var(--serif);
  line-height: 1.7;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ═══ CINEMATIC INTRO ═══ */

#intro {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--void);
  cursor: pointer;
}

.act {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.act.active {
  opacity: 1;
  pointer-events: auto;
}

.act-inner {
  text-align: center;
  max-width: 540px;
  padding: 2rem;
}

.act-text { text-align: left; }

.act-text p {
  min-height: 1.4em;
  font-size: 1.15rem;
  line-height: 1.9;
  color: var(--text);
}

.act-text .mt { margin-top: 1.5rem; }
.act-text .gold { color: var(--gold); }

.sigil-intro {
  font-size: 2.5rem;
  color: var(--gold);
  letter-spacing: 0.5em;
  opacity: 0;
  animation: fadeIn 3s ease forwards;
}

.sigil-intro.instant {
  animation: none;
  opacity: 1;
}

.intro-title {
  font-family: var(--serif);
  font-size: 2.2rem;
  color: var(--text-bright);
  font-weight: normal;
  letter-spacing: 0.03em;
  margin: 1.5rem 0;
  opacity: 0;
  animation: fadeIn 1s ease 0.5s forwards;
}

#enter-btn {
  background: transparent;
  border: 1px solid var(--gold);
  color: var(--gold);
  font-family: var(--sans);
  font-size: 1rem;
  padding: 1rem 3rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  transition: all 0.3s;
  opacity: 0;
  animation: fadeIn 1s ease 1.2s forwards;
}

#enter-btn:hover {
  background: var(--gold);
  color: var(--void);
}

#skip-intro {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 101;
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--text-muted);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  transition: color 0.2s;
}

#skip-intro:hover { color: var(--text-dim); }

/* Typewriter cursor */
.typing::after {
  content: '\25CC';
  color: var(--gold);
  animation: blink 0.7s step-end infinite;
  margin-left: 2px;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ═══ APP SHELL ═══ */

#app {
  max-width: 680px;
  margin: 0 auto;
  padding: 1.5rem;
  padding-bottom: 4rem;
  animation: fadeIn 0.6s ease;
}

header {
  text-align: center;
  padding: 3rem 0 2rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2.5rem;
}

header .sigil {
  font-size: 1.5rem;
  color: var(--gold);
  letter-spacing: 0.5em;
  margin-bottom: 0.75rem;
}

header h1 {
  font-size: 1.75rem;
  color: var(--text-bright);
  font-weight: normal;
  letter-spacing: 0.02em;
  margin-bottom: 0.25rem;
}

header .subtitle {
  color: var(--text-dim);
  font-style: italic;
  font-size: 0.9rem;
  margin: 0;
}

/* ═══ FORM ═══ */

.field { margin-bottom: 1.25rem; }

.field label {
  display: block;
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.35rem;
}

.hint {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  line-height: 1.4;
}

.hint a {
  color: var(--gold);
  text-decoration: none;
}

.hint a:hover {
  border-bottom: 1px solid var(--gold);
}

input[type="text"],
input[type="password"],
textarea,
select {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--serif);
  font-size: 0.95rem;
  padding: 0.6rem 0.75rem;
  line-height: 1.6;
  transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--gold);
}

textarea { resize: vertical; }
textarea::placeholder, input::placeholder { color: var(--text-muted); }
select { font-family: var(--sans); cursor: pointer; }

#links {
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.8;
}

.key-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.key-row input { flex: 1; }

.key-link {
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--gold);
  white-space: nowrap;
  text-decoration: none;
}

.key-saved {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-dim);
  margin: 0;
}

.key-saved a {
  color: var(--gold);
  cursor: pointer;
  text-decoration: none;
}

/* ═══ FLIP BUTTON ═══ */

#flip-btn {
  display: block;
  width: 100%;
  font-family: var(--sans);
  font-size: 0.95rem;
  padding: 1rem;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  transition: all 0.2s;
  margin-top: 1.5rem;
}

#flip-btn:hover {
  background: var(--gold);
  color: var(--void);
}

#flip-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

#flip-btn:disabled:hover {
  background: transparent;
  color: var(--gold);
}

#flip-status {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-dim);
  min-height: 1.2em;
  margin-top: 0.75rem;
  text-align: center;
}

#flip-status.error { color: var(--red); }

/* ═══ PROCESSING VIEW ═══ */

#processing-view {
  text-align: center;
  padding-top: 2rem;
}

.processing-sigil {
  font-size: 2rem;
  color: var(--gold);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

#proc-status {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 1rem 0;
}

#proc-papers {
  text-align: left;
  margin-bottom: 1.5rem;
}

.paper-found {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
  padding-left: 1.2rem;
  position: relative;
}

.paper-found::before {
  content: '\2713';
  position: absolute;
  left: 0;
  color: var(--green);
}

#stream-out {
  text-align: left;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 50vh;
  overflow-y: auto;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  display: none;
}

#stream-out.visible { display: block; }

/* ═══ RESULTS VIEW ═══ */

#results-view {
  animation: fadeIn 0.5s ease;
}

.brief-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2rem;
  margin-bottom: 2rem;
  font-size: 0.95rem;
  line-height: 1.8;
}

.brief-box h1 {
  font-size: 1.3rem;
  color: var(--gold);
  font-weight: normal;
  margin-bottom: 1rem;
}

.brief-box h2 {
  font-size: 1.1rem;
  color: var(--text-bright);
  font-weight: normal;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.brief-box h3 {
  font-size: 0.95rem;
  color: var(--text-dim);
  font-weight: normal;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
}

.brief-box p {
  margin-bottom: 0.75rem;
  max-width: 65ch;
  color: var(--text);
}

.brief-box strong { color: var(--text-bright); }
.brief-box em { color: var(--text-dim); }

.brief-box hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

.brief-box ul, .brief-box ol {
  padding-left: 1.5rem;
  margin-bottom: 0.75rem;
}

.brief-box li { margin-bottom: 0.5rem; }

.brief-box .pmid {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--gold);
}

.export-row {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.export-btn {
  flex: 1;
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: all 0.2s;
}

.export-btn:hover {
  background: var(--gold);
  color: var(--void);
}

.export-btn.primary {
  background: var(--gold);
  color: var(--void);
}

.export-btn.primary:hover {
  background: var(--warm);
}

#again-btn {
  display: block;
  width: 100%;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-family: var(--sans);
  font-size: 0.8rem;
  padding: 0.75rem;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: all 0.2s;
}

#again-btn:hover {
  color: var(--text-dim);
  border-color: var(--border-mid);
}

/* ═══ SETTINGS ═══ */

#settings {
  margin-top: 3rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

#settings summary {
  font-family: var(--sans);
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  cursor: pointer;
  padding: 0.5rem 0;
}

.settings-inner { padding-top: 0.75rem; }
.settings-inner .field { margin-bottom: 1rem; }

/* ═══ RESPONSIVE ═══ */

@media (max-width: 600px) {
  #app { padding: 1rem; }
  header { padding: 2rem 0 1.5rem; }
  header h1 { font-size: 1.4rem; }
  .act-text p { font-size: 1rem; }
  .sigil-intro { font-size: 1.8rem; }
  .intro-title { font-size: 1.6rem; }
  #enter-btn { padding: 0.75rem 2rem; font-size: 0.9rem; }
  .brief-box { padding: 1.25rem; }
  .export-row { flex-direction: column; }
  .key-row { flex-direction: column; gap: 0.5rem; }
  .key-row input { width: 100%; }
}
