/* ============================================================
   Roman Numeral Converter — style.css
   Dark/Light theme via data-theme attribute
   ============================================================ */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
  /* Colors */
  --bg:          #f5f5f0;
  --surface:     #ffffff;
  --surface-alt: #f0efea;
  --border:      #d8d5cc;
  --text:        #1a1a18;
  --text-muted:  #6b6860;
  --accent:      #8b0000; /* deep roman red */
  --accent-light:#c5282840;
  --accent-hover:#6a0000;
  --success:     #2e7d32;
  --success-bg:  #e8f5e9;
  --error:       #c62828;
  --error-bg:    #ffebee;
  --badge-valid-bg:   #e8f5e9;
  --badge-valid-text: #2e7d32;
  --badge-invalid-bg: #ffebee;
  --badge-invalid-text:#c62828;

  /* Typography */
  --font-sans:   'Segoe UI', 'Helvetica Neue', Arial, 'Noto Sans JP', sans-serif;
  --font-roman:  Georgia, 'Times New Roman', serif;

  /* Spacing */
  --radius: 8px;
  --radius-lg: 12px;
  --gap: 1.5rem;
}

[data-theme="dark"] {
  --bg:          #121210;
  --surface:     #1e1e1b;
  --surface-alt: #272724;
  --border:      #383835;
  --text:        #e8e6df;
  --text-muted:  #9a9890;
  --accent:      #e57373;
  --accent-light:#e5737320;
  --accent-hover:#ef9a9a;
  --success:     #66bb6a;
  --success-bg:  #1b3a1c;
  --error:       #ef5350;
  --error-bg:    #3b1111;
  --badge-valid-bg:   #1b3a1c;
  --badge-valid-text: #66bb6a;
  --badge-invalid-bg: #3b1111;
  --badge-invalid-text:#ef5350;
}

/* ── 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);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background 0.2s, color 0.2s;
}

/* ── Header ───────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-title {
  font-family: var(--font-roman);
  font-size: 1.4rem;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.site-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

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

/* ── Main ─────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.card-title {
  font-family: var(--font-roman);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-family: var(--font-sans);
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 0.65rem 1.5rem;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

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

/* ── Converter Card ───────────────────────────────────────── */
.converter-card { display: flex; flex-direction: column; gap: 1.25rem; }

.direction-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.direction-badge {
  background: var(--accent-light);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

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

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
  min-width: 200px;
}

.input-group label {
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.input-group input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  font-size: 1rem;
  color: var(--text);
  font-family: var(--font-roman);
  transition: border-color 0.15s;
  width: 100%;
}

.input-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-light);
}

/* ── Result ───────────────────────────────────────────────── */
.result-section {
  background: var(--surface-alt);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 70px;
}

.result-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.result-value {
  font-family: var(--font-roman);
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  word-break: break-all;
}

.result-success { color: var(--text); }
.result-error   { color: var(--error); font-size: 0.95rem; font-weight: 400; }

.validation-box { margin-top: 0.5rem; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-valid {
  background: var(--badge-valid-bg);
  color: var(--badge-valid-text);
}

.badge-invalid {
  background: var(--badge-invalid-bg);
  color: var(--badge-invalid-text);
}

/* ── Steps Card ───────────────────────────────────────────── */
.steps-box { min-height: 2rem; }

.steps-intro {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.steps-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.steps-table th,
.steps-table td {
  padding: 0.5rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.steps-table thead th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--surface-alt);
}

.steps-table tbody tr:hover { background: var(--surface-alt); }
.steps-table tbody tr:last-child td { border-bottom: none; }

.step-symbol {
  font-family: var(--font-roman);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

.step-accumulated {
  font-family: var(--font-roman);
  font-weight: 600;
  color: var(--text);
}

/* ── Year Card ────────────────────────────────────────────── */
.year-row {
  display: flex;
  align-items: flex-end;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.year-result-group {
  flex: 1;
  min-width: 150px;
}

.year-result {
  font-family: var(--font-roman);
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  min-height: 2.5rem;
}

.year-result.success { color: var(--text); }
.year-result.error   { font-size: 0.85rem; color: var(--error); font-weight: 400; }

/* ── Reference Table ──────────────────────────────────────── */
.table-scroll { overflow-x: auto; }

.ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.ref-table th,
.ref-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.ref-table thead th {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--surface-alt);
}

.ref-table tbody tr:nth-child(even) { background: var(--surface-alt); }
.ref-table tbody tr:hover { background: var(--accent-light); }

.roman-cell {
  font-family: var(--font-roman);
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.05em;
}

/* ── History Card ─────────────────────────────────────────── */
.history-card p {
  margin-bottom: 0.75rem;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.history-card p:last-of-type { margin-bottom: 1rem; }

.symbol-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.symbol-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  min-width: 3rem;
}

.sym {
  font-family: var(--font-roman);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.sym-val {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* ── Footer ───────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1rem 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}
.site-footer a:hover { text-decoration: underline; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .main-content { padding: 1rem; gap: 1rem; }
  .card { padding: 1rem; }
  .result-value { font-size: 1.5rem; }
  .header-inner { padding: 0.5rem 1rem; }
  .site-title { font-size: 1.1rem; }
  .input-row { flex-direction: column; }
  .btn-primary { width: 100%; }
}
