/* ============================================================
   Prime Factorize — style.css
   Dark / Light theme via data-theme attribute on <html>
   ============================================================ */

:root {
  --bg: #0f1117;
  --surface: #1a1d26;
  --surface-2: #242736;
  --border: #2e3144;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --accent: #6c8ef6;
  --accent-2: #a78bfa;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --orange: #fb923c;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  --font-mono: 'JetBrains Mono', 'Fira Mono', 'Cascadia Code', 'Consolas', monospace;
  --font-sans: 'Inter', 'Noto Sans JP', system-ui, sans-serif;
}

[data-theme='light'] {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #d1d9e6;
  --text: #1e2533;
  --text-muted: #64748b;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

/* ---- Layout ---- */
.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.header-title h1 {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

.header-title .subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--accent); }

/* ---- Card ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

/* ---- Input section ---- */
.input-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.input-group {
  flex: 1;
  min-width: 180px;
}

.input-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.number-input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 1.1rem;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  transition: border-color 0.15s;
  outline: none;
}

.number-input:focus { border-color: var(--accent); }
.number-input::placeholder { color: var(--text-muted); opacity: 0.6; }

.btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.6rem 1.4rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
}
.btn-primary:hover { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); }

/* ---- Examples ---- */
.examples {
  margin-top: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.examples-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.example-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.example-btn:hover { background: var(--border); border-color: var(--accent); }

/* ---- Error ---- */
.error-msg {
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: 0.6rem 0.9rem;
  color: var(--red);
  font-size: 0.88rem;
  margin-bottom: 1rem;
}

/* ---- Result grid ---- */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.result-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.result-card--wide {
  grid-column: 1 / -1;
}

.result-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.result-value {
  font-size: 1rem;
  font-weight: 600;
  word-break: break-word;
}

.result-value.mono { font-family: var(--font-mono); font-size: 0.95rem; }
.factorization-value { font-size: 1.1rem; color: var(--accent); }
.divisors-value { font-size: 0.82rem; color: var(--text-muted); }

.value-yes { color: var(--green); }
.value-no  { color: var(--text-muted); }

.tag-prime    { color: var(--accent); }
.tag-perfect  { color: var(--green); }
.tag-abundant { color: var(--orange); }
.tag-deficient { color: var(--text-muted); }

/* ---- Tree ---- */
.tree-container {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow-x: auto;
}

.tree-text {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text);
  white-space: pre;
  line-height: 1.7;
}

/* ---- Section headings ---- */
.section-heading {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-heading::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ---- History ---- */
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}

.history-list {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--accent-2);
  cursor: pointer;
  transition: background 0.12s;
}
.history-item:hover { background: var(--border); }

.history-empty {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0.25rem 0;
}

.btn-xs {
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
}

/* ---- Responsive ---- */
@media (max-width: 500px) {
  .header-title h1 { font-size: 1.3rem; }
  .result-grid { grid-template-columns: 1fr 1fr; }
}
