/* Turnstile — A Game of Formal Proof */

:root {
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #1c2128;
  --bg-hover: #252c35;
  --border: #30363d;
  --border-light: #21262d;

  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-faint: #484f58;

  --accent: #58a6ff;
  --accent-dim: #1f6feb;
  --accent-glow: rgba(88, 166, 255, 0.15);

  --success: #3fb950;
  --success-dim: rgba(63, 185, 80, 0.15);
  --warning: #d29922;
  --error: #f85149;
  --error-dim: rgba(248, 81, 73, 0.15);

  --scope-1: #58a6ff;
  --scope-2: #bc8cff;
  --scope-3: #f0883e;
  --scope-4: #3fb950;

  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --radius: 6px;
  --radius-lg: 10px;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 80px;
}

/* ── Menu Screen ─────────────────────────────────── */

.menu-header {
  text-align: center;
  padding: 48px 0 32px;
}

.logo {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 4px;
}

.progress-summary {
  color: var(--text-faint);
  font-size: 0.85rem;
  margin-top: 12px;
  font-family: var(--font-mono);
}

.worlds {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.world {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.world-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.world-symbol {
  font-family: var(--font-mono);
  font-size: 1.8rem;
  color: var(--accent);
  width: 40px;
  text-align: center;
  flex-shrink: 0;
  line-height: 1;
  padding-top: 4px;
}

.world-name {
  font-size: 1.1rem;
  font-weight: 600;
}

.world-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.world-progress {
  color: var(--text-faint);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  margin-top: 4px;
}

.world-locked {
  color: var(--text-faint);
  font-size: 0.85rem;
  font-style: italic;
  text-align: center;
  padding: 8px 0;
}

.level-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.level-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: left;
  width: 100%;
  font-family: var(--font-sans);
}

.level-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border);
}

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

.level-btn.completed {
  opacity: 0.85;
}

.level-status {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.level-btn.completed .level-status {
  color: var(--success);
}

.level-name {
  flex: 1;
}

.level-best {
  color: var(--text-faint);
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

/* ── Level Screen ────────────────────────────────── */

.level-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.back-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 1.1rem;
  width: 36px;
  height: 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}

.back-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

.level-title {
  font-size: 1.3rem;
  font-weight: 600;
}

.goal-bar {
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.goal-label {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.goal-prop {
  font-family: var(--font-mono);
  font-size: 1.1rem;
  color: var(--text);
}

.level-description {
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.6;
  margin-bottom: 20px;
}

/* ── Proof Area ──────────────────────────────────── */

.proof-area {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 12px;
  margin-bottom: 16px;
  min-height: 80px;
}

.proof-area.compact {
  margin-bottom: 0;
}

.proof-empty {
  color: var(--text-faint);
  font-size: 0.85rem;
  text-align: center;
  padding: 20px;
  font-style: italic;
}

.proof-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 4px;
  transition: background 0.1s;
  min-height: 36px;
}

.proof-line.selectable {
  cursor: pointer;
}

.proof-line.selectable:hover {
  background: var(--bg-hover);
}

.proof-line.selected {
  background: var(--accent-glow);
  outline: 1px solid var(--accent-dim);
}

.proof-line.closed-scope {
  opacity: 0.4;
}

.line-depth {
  display: flex;
  gap: 0;
  flex-shrink: 0;
}

.scope-bar {
  width: 3px;
  height: 24px;
  margin-right: 8px;
  border-radius: 2px;
  background: var(--scope-1);
}

.scope-bar:nth-child(2) { background: var(--scope-2); }
.scope-bar:nth-child(3) { background: var(--scope-3); }
.scope-bar:nth-child(4) { background: var(--scope-4); }

.line-num {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
  width: 24px;
  text-align: right;
  flex-shrink: 0;
}

.line-prop {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  flex: 1;
  color: var(--text);
}

.line-just {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  text-align: right;
}

/* ── Scope Info ──────────────────────────────────── */

.scope-info {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.scope-badge {
  background: var(--scope-1);
  color: var(--bg);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 3px;
  margin-right: 6px;
}

/* ── Rule Palette ────────────────────────────────── */

.rule-palette {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.rule-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.rule-group-label {
  font-size: 0.75rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  width: 100%;
  margin-bottom: 2px;
}

.rule-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.rule-btn:hover {
  background: var(--bg-hover);
  border-color: var(--text-faint);
}

.rule-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.rule-symbol {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.9rem;
}

.rule-name {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rule-btn.active .rule-name {
  color: var(--accent);
}

/* ── Input Prompt ────────────────────────────────── */

.input-prompt {
  background: var(--bg-elevated);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}

.prompt-text {
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.prompt-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.prop-input-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quick-vars {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.quick-var-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 2px 8px;
  cursor: pointer;
  transition: background 0.1s;
}

.quick-var-btn:hover {
  background: var(--bg-hover);
}

.prop-input {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}

.prop-input:focus {
  border-color: var(--accent);
}

.prop-submit-btn {
  background: var(--accent-dim);
  border: none;
  border-radius: var(--radius);
  color: white;
  font-size: 0.85rem;
  padding: 8px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
  align-self: flex-end;
}

.prop-submit-btn:hover {
  background: var(--accent);
}

.cancel-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 4px 12px;
  cursor: pointer;
  margin-top: 8px;
  transition: color 0.15s;
}

.cancel-btn:hover {
  color: var(--text);
}

/* ── Controls ────────────────────────────────────── */

.controls-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.ctrl-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
}

.ctrl-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

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

.ctrl-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent-dim);
  color: var(--accent);
}

.ctrl-btn.primary {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}

.ctrl-btn.primary:hover {
  background: var(--accent);
}

/* ── Error ───────────────────────────────────────── */

.error-msg {
  background: var(--error-dim);
  border: 1px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  font-size: 0.85rem;
  padding: 8px 12px;
  margin-bottom: 12px;
  animation: fadeIn 0.2s ease-out;
}

/* ── Hint ────────────────────────────────────────── */

.hint-area {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warning);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 12px;
}

/* ── Victory Screen ──────────────────────────────── */

.victory-screen {
  text-align: center;
  padding: 48px 0 32px;
}

.victory-symbol {
  font-size: 4rem;
  color: var(--success);
  margin-bottom: 16px;
  animation: fadeIn 0.4s ease-out;
}

.victory-title {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  animation: fadeIn 0.6s ease-out;
}

.victory-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 24px;
}

.proof-review {
  margin: 0 auto 24px;
  max-width: 500px;
}

.victory-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ── Animations ──────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────────── */

@media (max-width: 480px) {
  #app { padding: 16px 12px 60px; }
  .logo { font-size: 1.6rem; }
  .goal-prop { font-size: 0.95rem; }
  .rule-btn { padding: 5px 8px; font-size: 0.8rem; }
  .rule-name { display: none; }
}
