:root {
  --bg: #fafafa;
  --text: #1a1a1a;
  --text-muted: #555;
  --border: #ccc;
  --card-bg: #fff;
  --card-border: #ddd;
  --pre-bg: #f0f0f0;
  --status-bg: #e8e8e8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --status-ready-bg: #d4edda;
  --status-ready-text: #155724;
  --status-error-bg: #f8d7da;
  --status-error-text: #721c24;
  --status-working-bg: #fff3cd;
  --status-working-text: #856404;
  --chart-text: #1a1a1a;
  --chart-grid: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --bg: #1d1f20;
  --text: #d4d4d8;
  --text-muted: #a1a1aa;
  --border: #3f3f46;
  --card-bg: #2e3044;
  --card-border: #3f3f46;
  --pre-bg: #2e3044;
  --status-bg: #2e3044;
  --accent: #4ade80;
  --accent-hover: #2abc89;
  --btn-text: #1a1a1a;
  --status-ready-bg: #1a3a2a;
  --status-ready-text: #6ee7a0;
  --status-error-bg: #3b1c1c;
  --status-error-text: #fca5a5;
  --status-working-bg: #3b2f1c;
  --status-working-text: #fcd34d;
  --chart-text: #d4d4d8;
  --chart-grid: rgba(255, 255, 255, 0.1);
}

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

body {
  font-family: "Atkinson Hyperlegible Next", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
  color: var(--text);
  background: var(--bg);
}

h1 {
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

h2 {
  margin-bottom: 1rem;
}

h3 {
  font-size: 0.9rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

/* Status bar */
.status {
  padding: 0.75rem 1rem;
  background: var(--status-bg);
  border-radius: 6px;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.status.ready   { background: var(--status-ready-bg);   color: var(--status-ready-text); }
.status.error   { background: var(--status-error-bg);   color: var(--status-error-text); }
.status.working { background: var(--status-working-bg); color: var(--status-working-text); }

/* Sections */
section {
  margin-bottom: 1.5rem;
}

.hidden {
  display: none;
}

/* Form elements */
label {
  display: block;
  margin-bottom: 0.4rem;
  font-weight: 600;
}

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

input[type="file"] {
  margin-bottom: 0.75rem;
}

select {
  display: block;
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card-bg);
  color: var(--text);
  margin-bottom: 0;
}

button {
  padding: 0.5rem 1.5rem;
  background: var(--accent);
  color: var(--btn-text, #fff);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.95rem;
  margin-right: 0.5rem;
}

button:hover {
  background: var(--accent-hover);
}

button:focus-visible,
select:focus-visible,
input[type="file"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.secondary {
  background: #6b7280;
}

button.secondary:hover {
  background: #4b5563;
}

/* Column picker grid */
.column-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.column-grid > div {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.35rem;
}

/* Log-rank result */
.logrank-result {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* Assumption note */
.assumption-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

/* Chart */
#chart-container {
  margin-bottom: 1rem;
}

/* At-risk table */
#atrisk-container {
  margin-bottom: 1.5rem;
}

.atrisk-wrapper {
  overflow-x: auto;
}

.atrisk-table {
  border-collapse: collapse;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  min-width: 100%;
}

.atrisk-table th,
.atrisk-table td {
  padding: 0.3rem 0.8rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.atrisk-table thead th {
  color: var(--text-muted);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

.atrisk-table thead th.median-col {
  color: var(--accent);
}

.atrisk-table tbody th {
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  padding-right: 1.5rem;
}

/* Summary text */
#summary-text pre {
  background: var(--pre-bg);
  color: var(--text);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Copy button */
.copy-btn {
  margin-top: 0.5rem;
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

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

/* Back button */
.back-btn {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 100;
}

.back-btn a {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0.5rem;
  background: transparent;
  color: var(--text);
  border-radius: 6px;
  text-decoration: none;
  transition: color 0.2s;
}

.back-btn a:hover { color: var(--accent); }

.back-btn a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.back-btn svg { width: 1.25rem; height: 1.25rem; }

/* Theme toggle */
.theme-toggle {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 100;
}

.theme-toggle button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0.5rem;
  margin: 0;
  background: transparent;
  color: var(--text);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.2s;
}

.theme-toggle button:hover  { color: var(--accent); background: transparent; }

.theme-toggle button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.theme-toggle svg { width: 1.25rem; height: 1.25rem; }

.theme-toggle .sun  { display: none; }
.theme-toggle .moon { display: block; }

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