:root {
  --bg: #0a0a0a;
  --fg: #f2f2f0;
  --muted: #8a8a86;
  --accent: #f2f2f0;
  --danger: #d9534f;
  --ok: #6fae6f;
  --border: #2a2a28;
  --focus: #ffd166;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  min-height: 100dvh;
}

.screen[hidden] { display: none; }
[hidden] { display: none !important; }

.frame {
  width: 100%;
  max-width: 640px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

h2 {
  font-size: 1.3rem;
  margin: 0;
}

.sub {
  color: var(--muted);
  font-size: 1.05rem;
  margin: 0;
}

.fineprint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

button, .btn-primary, .btn-secondary {
  font-family: inherit;
  font-size: 1rem;
  cursor: pointer;
  border: none;
  border-radius: 6px;
}

.btn-primary {
  background: var(--fg);
  color: var(--bg);
  padding: 0.9rem 1.4rem;
  font-weight: 600;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: fit-content;
}

.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.8rem 1.4rem;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  width: fit-content;
}

.btn-critique {
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--border);
  padding: 0.7rem 1.2rem;
  min-height: 44px;
  width: fit-content;
}

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

/* ROOM */
.room-frame {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.room-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-variant-numeric: tabular-nums;
}

.room-index {
  color: var(--muted);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.room-meta-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.room-timer {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.room-timer[data-low="true"] { color: var(--danger); }

.btn-extend {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  min-height: 32px;
  border-radius: 4px;
}

.btn-extend:disabled {
  opacity: 0.4;
  cursor: default;
}

#room-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1rem;
  padding: 1.5rem 0;
}

.room-prompt {
  font-size: clamp(1.1rem, 4vw, 1.5rem);
  font-weight: 600;
}

.ai-take {
  border-left: 3px solid var(--border);
  padding: 0.75rem 1rem;
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
}

textarea {
  width: 100%;
  min-height: 140px;
  background: #141412;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.9rem;
  font-family: inherit;
  font-size: 1rem;
  resize: vertical;
}

.passage {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.passage-sentence {
  text-align: left;
  background: #141412;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  color: var(--fg);
  font-size: 1rem;
  min-height: 44px;
}

.passage-sentence:hover { border-color: var(--muted); }
.passage-sentence[data-selected="true"] { border-color: var(--focus); }

.room-actions {
  display: flex;
  justify-content: flex-end;
}

/* REVEAL */
.your-answer-label,
.strong-answer-label {
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
}

.your-answer {
  background: #141412;
  border-left: 3px solid var(--border);
  padding: 0.75rem 1rem;
  margin: 0 0 1.25rem;
  font-style: italic;
}

.selfrate-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-rate {
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 0.7rem 1rem;
  min-height: 44px;
}

.btn-rate[aria-pressed="true"] {
  border-color: var(--focus);
  color: var(--focus);
}

.tell {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

.correct { color: var(--ok); }
.incorrect { color: var(--danger); }

/* RESULT */
.fingerprint-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #111110;
}

.fingerprint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.fingerprint-label { color: var(--muted); font-size: 0.9rem; }

.fingerprint-bar {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.fingerprint-bar-fill {
  height: 100%;
  background: var(--fg);
}

.fingerprint-line {
  font-size: 1.05rem;
  font-weight: 600;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  align-items: flex-start;
}

.critique-output {
  background: #141412;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1rem;
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.tertiary {
  color: var(--muted);
  font-size: 0.85rem;
}

.tertiary a { color: var(--muted); }

.error-text { color: var(--danger); }

.subscribe-block {
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.subscribe-label {
  font-size: 0.85rem;
  color: var(--muted);
}

.subscribe-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.subscribe-row input {
  flex: 1;
  min-width: 180px;
  background: #141412;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  font-family: inherit;
  font-size: 0.95rem;
  min-height: 44px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (min-width: 768px) {
  .screen { padding: 2.5rem; }
}

/* Keyboard-open mobile heights (~400px): shrink so Done stays reachable with
   minimal scrolling instead of demanding a full scroll past the textarea. */
@media (max-height: 500px) {
  .screen { align-items: flex-start; padding: 1rem; overflow-y: auto; }
  .room-prompt { font-size: 1.05rem; }
  #room-body { padding: 0.75rem 0; gap: 0.6rem; }
  textarea { min-height: 80px; }
  .room-frame { min-height: 0; }
  .frame { gap: 0.75rem; }
  #reveal-body p { margin: 0.4rem 0; font-size: 0.95rem; }
  .selfrate-buttons { gap: 0.4rem; }
  .btn-rate { padding: 0.5rem 0.8rem; min-height: 40px; }
}
