/* ═══════════════════════════════════════════
   TypeProof — Design System
   ═══════════════════════════════════════════ */

/* ── Theme Variables ── */
:root,
[data-theme="light"] {
  color-scheme: light;

  --bg-page: #F5F4F0;
  --bg-surface: #FFFFFF;
  --bg-inset: #F5F4F0;

  --border-default: #d1d0cc;
  --border-muted: #dddcd8;
  --border-subtle: #e8e7e3;

  --text-primary: #1A1A2E;
  --text-secondary: #4A4A6A;
  --text-tertiary: #7A7A96;
  --text-link: #2563EB;

  --accent: #2563EB;
  --accent-subtle: rgba(37, 99, 235, 0.08);


  --success-subtle: #dafbe1;
  --success-fg: #1a7f37;
  --success-border: rgba(26, 127, 55, 0.2);

  --danger: #d1242f;

  --btn-primary-bg: #2563EB;
  --btn-primary-text: #ffffff;
  --btn-primary-border: #2563EB;
  --btn-primary-hover: #1d4ed8;

  --btn-secondary-bg: #FFFFFF;
  --btn-secondary-text: #1A1A2E;
  --btn-secondary-border: #d1d0cc;
  --btn-secondary-hover: #F5F4F0;

  --shadow-sm: 0 1px 0 rgba(26, 26, 46, 0.04);


  --code-bg: rgba(74, 74, 106, 0.08);

  --timeline-bg: #ffffff;
  --timeline-chart-bg: #F5F4F0;
  --timeline-text: #4A4A6A;
  --timeline-grid: #e8e7e3;

  --fade-gradient: linear-gradient(to bottom, transparent, var(--bg-surface));
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg-page: #0f0f1e;
  --bg-surface: #1a1a2e;
  --bg-inset: #0c0c1a;

  --border-default: #2e2e4a;
  --border-muted: #232340;
  --border-subtle: #232340;

  --text-primary: #e6e6f0;
  --text-secondary: #9090b0;
  --text-tertiary: #6a6a8a;
  --text-link: #60A5FA;

  --accent: #60A5FA;
  --accent-subtle: rgba(96, 165, 250, 0.12);


  --success-subtle: #0d2818;
  --success-fg: #3fb950;
  --success-border: rgba(63, 185, 80, 0.2);

  --danger: #f85149;

  --btn-primary-bg: #2563EB;
  --btn-primary-text: #ffffff;
  --btn-primary-border: rgba(96, 165, 250, 0.2);
  --btn-primary-hover: #3b82f6;

  --btn-secondary-bg: #232340;
  --btn-secondary-text: #e6e6f0;
  --btn-secondary-border: #2e2e4a;
  --btn-secondary-hover: #2e2e4a;

  --shadow-sm: 0 0 transparent;


  --code-bg: rgba(96, 165, 250, 0.1);

  --timeline-bg: #1a1a2e;
  --timeline-chart-bg: #0f0f1e;
  --timeline-text: #9090b0;
  --timeline-grid: #232340;

  --fade-gradient: linear-gradient(to bottom, transparent, var(--bg-surface));

  scrollbar-color: #2e2e4a #0f0f1e;
}

/* ── Reset ── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  margin: 0;
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: 'Sora', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.2s ease, color 0.2s ease;
}

::selection {
  background: var(--accent-subtle);
  color: var(--text-primary);
}

:focus-visible {
  outline: 2px solid var(--text-link);
  outline-offset: 2px;
}

/* ── Header ── */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.header-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: opacity 0.15s;
}

.logo-link:hover {
  opacity: 0.75;
  text-decoration: none;
}

.logo-wordmark {
  height: 32px;
  width: auto;
  display: block;
}

/* Theme-aware wordmark: show light on light, dark on dark */
.logo-wordmark--dark {
  display: none;
}

.logo-wordmark--light {
  display: block;
}

[data-theme="dark"] .logo-wordmark--light {
  display: none;
}

[data-theme="dark"] .logo-wordmark--dark {
  display: block;
}

/* ── Theme Toggle ── */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.theme-toggle:hover {
  background: var(--btn-secondary-hover);
  color: var(--text-primary);
}

[data-theme="light"] .icon-sun {
  display: none;
}

[data-theme="light"] .icon-moon {
  display: block;
}

[data-theme="dark"] .icon-sun {
  display: block;
}

[data-theme="dark"] .icon-moon {
  display: none;
}

/* ── Layout ── */
main {
  max-width: 880px;
  margin: 0 auto;
  padding: 18px 24px 64px;
}

/* ── Typography ── */
h1,
h2,
h3 {
  color: var(--text-primary);
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 16px;
}

small {
  color: var(--text-secondary);
}

a {
  color: var(--text-link);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ── File Card ── */
.file-card {
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--bg-surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, border-color 0.2s;
}

.file-card-dots {
  display: flex;
  gap: 6px;
}

.file-card-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border-default);
  transition: background-color 0.2s;
}

.file-card-title {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 500;
}

.file-card pre {
  background: transparent;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 20px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-color: var(--btn-primary-border);
  box-shadow: var(--shadow-sm);
}

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

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  border-color: var(--btn-secondary-border);
  box-shadow: var(--shadow-sm);
}

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

/* ── Hidden ── */
.hidden {
  display: none !important;
}

/* ═══════════════════════════════════════════
   EDITOR VIEW
   ═══════════════════════════════════════════ */

.editor-hero {
  text-align: center;
  margin-bottom: 15px;
  padding-top: 5px;
}

.hero-title {
  font-size: 36px;
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: -0.03em;
}

.hero-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 100%;
  margin: 0 auto;
  line-height: 1.65;
}

#app-editor textarea {
  width: 100%;
  min-height: 300px;
  padding: 16px;
  border: none;
  outline: none;
  resize: vertical;
  font-family: 'JetBrains Mono', monospace;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  background: var(--bg-surface);
  transition: background-color 0.2s, color 0.2s;
}

#app-editor textarea::placeholder {
  color: var(--text-tertiary);
}

#turnstile-widget {
  margin-top: 16px;
}

.editor-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.status-text {
  color: var(--text-secondary);
  font-size: 14px;
}

.char-count {
  color: var(--text-tertiary);
  font-size: 13px;
  font-family: 'JetBrains Mono', monospace;
  margin-left: auto;
}

.char-count-error {
  color: var(--danger) !important;
  font-weight: 600;
}

/* ── Features ── */
.features-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border-subtle);
}

.feature-item {
  display: flex;
  gap: 12px;
  padding: 16px;
  border-radius: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: background-color 0.2s, border-color 0.2s;
}

.feature-icon {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--accent-subtle);
  color: var(--accent);
}

.feature-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.feature-text strong {
  font-size: 13px;
  font-weight: 600;
}

.feature-text span {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* ═══════════════════════════════════════════
   VIEWER VIEW
   ═══════════════════════════════════════════ */

.section-block {
  margin-bottom: 32px;
}

/* ── Pre / Code ── */
pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  margin: 0;
  padding: 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-primary);
  background: var(--bg-surface);
}

.replay-pre {
  min-height: 120px;
}

/* ── Text Truncation ── */
.text-wrapper {
  position: relative;
}

.text-container {
  position: relative;
  max-height: 300px;
  overflow: hidden;
  transition: max-height 0.3s ease-out;
}

.text-container.expanded {
  max-height: none;
  overflow: visible;
}

.text-container::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 80px;
  background: var(--fade-gradient);
  pointer-events: none;
  transition: opacity 0.3s;
  opacity: 0;
}

.text-container.is-truncated:not(.expanded)::after {
  opacity: 1;
}

.toggle-text-btn {
  display: block;
  width: 100%;
  padding: 8px;
  background: var(--bg-inset);
  color: var(--text-secondary);
  border: none;
  border-top: 1px solid var(--border-default);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.toggle-text-btn:hover {
  background: var(--btn-secondary-hover);
  color: var(--text-primary);
}

/* ── Stats ── */
.stats-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  padding: 16px;
  border-radius: 6px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, border-color 0.2s;
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Replay ── */
.replay-section {
  margin: 0;
}

.replay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.replay-btn {
  font-weight: 500;
}

.replay-icon {
  width: 18px;
  height: 18px;
}

.cursor {
  display: inline-block;
  width: 2px;
  height: 1.15em;
  background: var(--accent);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

.selection {
  background-color: var(--accent-subtle);
  border-radius: 2px;
}

/* ── Timeline ── */
.timeline-container {
  background: var(--timeline-bg);
  border: 1px solid var(--border-default);
  border-radius: 6px;
  padding: 16px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, border-color 0.2s;
}

.timeline-svg {
  display: block;
  width: 100%;
  height: auto;
}

.timeline-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 0 0;
  justify-content: center;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.legend-color {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
}

.timeline-marker {
  cursor: pointer;
  transition: opacity 0.2s;
}

.timeline-marker:hover {
  opacity: 0.8;
}

/* ── Proof Box ── */
.proof-box {
  margin-bottom: 32px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  background: var(--bg-surface);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.2s, border-color 0.2s;
}

.proof-box>summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  background: var(--bg-inset);
  border-bottom: 1px solid transparent;
  transition: background-color 0.2s, border-color 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
}

.proof-box>summary::-webkit-details-marker {
  display: none;
}

.proof-box>summary::before {
  content: "\25B6";
  font-size: 10px;
  margin-right: 8px;
  display: inline-block;
  transition: transform 0.15s;
  color: var(--text-tertiary);
}

.proof-box[open]>summary::before {
  transform: rotate(90deg);
}

.verified-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--success-fg);
  background: var(--success-subtle);
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--success-border);
}

.proof-box[open]>summary {
  border-bottom-color: var(--border-default);
}

.proof-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.proof-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.proof-item strong {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.proof-item small {
  display: block;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-size: 12px;
}

.proof-item code {
  background: var(--code-bg);
  padding: 8px 12px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  word-break: break-all;
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  transition: background-color 0.2s, border-color 0.2s;
}

.highlight-item {
  background: var(--success-subtle);
  border: 1px solid var(--success-border);
  padding: 16px;
  border-radius: 6px;
  margin-bottom: 8px;
}

.highlight-item strong {
  color: var(--success-fg);
}

.highlight-item code {
  background: var(--bg-surface);
  border-color: var(--border-default);
  font-size: 13px;
  color: var(--text-primary);
  display: block;
  margin-top: 8px;
  padding: 12px;
}


/* ── Share Section ── */
.share-section {
  padding-top: 32px;
  border-top: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}

.share-box {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  margin-bottom: 12px;
  align-items: center;
}

.share-box input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border-default);
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}

.share-box input:focus {
  border-color: var(--text-link);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.share-hint {
  color: var(--text-secondary);
  font-size: 13px;
  margin: 0 0 20px;
}

.share-description {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
  margin: 0 0 16px;
  max-width: 600px;
}

.share-cta {
  margin-bottom: 8px;
}

/* ── Footer ── */
.site-footer {
  text-align: center;
  padding: 24px;
  font-size: 12px;
  color: var(--text-tertiary);
  border-top: 1px solid var(--border-subtle);
}

.footer-sep {
  margin: 0 6px;
  opacity: 0.5;
}

.footer-contact {
  color: var(--text-tertiary);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s;
}

.footer-contact:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  main {
    padding: 16px 16px 48px;
  }

  .hero-title {
    font-size: 28px;
  }

  .hero-subtitle {
    font-size: 14px;
  }

  #app-editor textarea {
    min-height: 120px;
    max-height: 30dvh;
    font-size: 16px; /* prevents iOS auto-zoom on focus */
  }

  .features-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .editor-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .char-count {
    margin-left: 0;
    text-align: center;
  }

  .share-box {
    flex-direction: column;
  }

  .share-box .btn-primary {
    width: 100%;
  }

  .stats-container {
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  }

  .replay-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-value {
    font-size: 18px;
  }
}