:root {
  color-scheme: light;
  --ink: #17211d;
  --muted: #607068;
  --paper: #f4f1e8;
  --surface: #fffdf7;
  --line: #d8d4c7;
  --deep: #173f35;
  --accent: #b04b2f;
  --accent-soft: #f5ddd2;
  --gold: #bb8b32;
  --success: #2e6f4e;
  --danger: #a2332a;
  --shadow: 0 14px 38px rgb(30 42 36 / 8%);
}

* { box-sizing: border-box; }
html { font-family: Inter, "Noto Sans SC", "Segoe UI", Arial, sans-serif; color: var(--ink); background: var(--paper); }
body { margin: 0; min-height: 100vh; }
a { color: inherit; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); text-underline-offset: .18em; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 2rem;
  padding: 1rem max(1.25rem, calc((100vw - 1180px) / 2));
  background: var(--deep); color: #f8f5e9; border-bottom: 3px solid var(--gold);
}
.brand { display: inline-flex; align-items: center; gap: .7rem; font-weight: 750; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 2.4rem; height: 2.4rem; border: 1px solid rgb(255 255 255 / 40%); border-radius: 50%; font-family: "Noto Naskh Arabic", "Segoe UI", serif; }
nav { display: flex; gap: 1.2rem; flex-wrap: wrap; }
nav a { color: #f8f5e9; text-decoration: none; font-size: .94rem; opacity: .9; }
nav a:hover { opacity: 1; text-decoration: underline; }

.page-shell { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 3rem 0 5rem; }
.site-footer { padding: 1.25rem; text-align: center; color: var(--muted); border-top: 1px solid var(--line); font-size: .9rem; }

.hero { padding: 2.3rem 0; }
.compact-hero { max-width: 820px; }
.eyebrow { margin: 0 0 .5rem; color: var(--accent); font-size: .78rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2 { font-family: "Noto Serif SC", Georgia, serif; line-height: 1.15; }
h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.7rem); letter-spacing: -.035em; }
h2 { margin: 0 0 1rem; }
.lede { color: var(--muted); font-size: 1.1rem; line-height: 1.75; }

.panel, .generated-card, .match-card, .summary-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.panel { padding: clamp(1.2rem, 3vw, 2rem); margin-bottom: 1.5rem; }
.converter-panel { border-top: 4px solid var(--accent); }
label { display: grid; gap: .5rem; color: #31433b; font-weight: 700; }
input, select, textarea {
  width: 100%; border: 1px solid #bfc7c1; border-radius: 9px; padding: .78rem .9rem;
  background: #fff; color: var(--ink); font-weight: 450;
}
textarea { resize: vertical; line-height: 1.6; }
textarea[dir="auto"], .rtl-input { font-size: 1.22rem; }
input:focus, select:focus, textarea:focus { outline: 3px solid rgb(176 75 47 / 18%); border-color: var(--accent); }

.form-grid { display: grid; gap: 1rem; }
.controls-grid { grid-template-columns: minmax(180px, 1fr) minmax(160px, .8fr) auto; align-items: end; margin-top: 1rem; }
.two-columns { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.filter-grid { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 1rem; }

.primary-button, .secondary-button {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: .72rem 1.05rem;
  border-radius: 9px; text-decoration: none; font-weight: 800; border: 1px solid transparent;
}
.primary-button { background: var(--accent); color: white; border-color: var(--accent); }
.primary-button:hover { background: #923a25; }
.secondary-button { background: transparent; color: var(--deep); border-color: #9aada4; }
.secondary-button:hover { background: #edf2ee; }
.small { min-height: 34px; padding: .42rem .72rem; font-size: .88rem; }
.subtle { color: var(--muted); font-size: .9rem; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }

.explain-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-top: 3rem; border: 1px solid var(--line); background: var(--line); }
.explain-grid article { padding: 1.4rem; background: var(--paper); }
.explain-grid h2 { font-size: 1.1rem; }
.explain-grid p { color: var(--muted); line-height: 1.7; margin-bottom: 0; }

#results, #analysis { margin-top: 2rem; }
.result-heading, .section-title-row, .page-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.result-heading { margin-bottom: 1rem; }
.result-heading h2 { margin: 0; }
.text-link { color: var(--accent); font-weight: 700; }
.generated-card { padding: 1.35rem; border-left: 5px solid var(--gold); }
.result-card-label { color: var(--muted); font-size: .84rem; font-weight: 750; }
.generated-output { margin: .6rem 0; font-family: "Charis SIL", "Noto Serif", Georgia, serif; font-size: clamp(1.6rem, 4vw, 2.7rem); overflow-wrap: anywhere; }
.arabic-output, .arabic-name, .arabic-cell, .glyph-cell { font-family: "Noto Naskh Arabic", "Amiri", "Segoe UI", serif; }
.arabic-output { font-size: 2rem; }

.warning-list { margin: .8rem 0 0; padding-left: 1.25rem; color: #7b4a20; line-height: 1.55; }
.block-warnings { padding: 1rem 1rem 1rem 2.4rem; background: #fff1dc; border-radius: 10px; }
.dictionary-section { margin-top: 2rem; }
.match-list { display: grid; gap: .8rem; }
.match-card { display: grid; grid-template-columns: 58px 1fr auto; gap: 1rem; align-items: start; padding: 1.15rem; box-shadow: none; }
.match-score { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: #e6eee9; color: var(--deep); font-weight: 850; }
.name-line { display: flex; align-items: baseline; gap: .8rem 1rem; flex-wrap: wrap; }
.arabic-name { font-size: 1.65rem; color: var(--deep); }
.latin-name { font-size: 1.25rem; font-family: "Charis SIL", Georgia, serif; }
.chinese-name { color: var(--accent); font-weight: 800; }
.match-reason, .aliases, .source-note { margin: .55rem 0; color: var(--muted); }
.source-note { font-size: .88rem; }
.tag-row { display: flex; gap: .45rem; flex-wrap: wrap; }
.tag { display: inline-flex; padding: .22rem .55rem; background: #eceae2; border-radius: 999px; font-size: .78rem; }
.tag.reviewed { background: #dcefe2; color: #275c3f; }
.tag.draft { background: #fff0d8; color: #80541e; }
.icon-link { color: var(--accent); font-size: .9rem; }

.notice { padding: .9rem 1rem; margin: 1rem 0; border-radius: 9px; border: 1px solid; }
.notice.warning { background: #fff2df; border-color: #e5b875; color: #68451f; }
.notice.success { background: #e2f2e8; border-color: #94c5a7; color: #285d40; }
.notice.error { background: #fbe3df; border-color: #d98d82; color: #7d2922; }
.empty-state { padding: 2rem; text-align: center; color: var(--muted); border: 1px dashed #aeb9b3; border-radius: 12px; }

.analysis-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.summary-card { padding: 1rem; box-shadow: none; }
.summary-card span { display: block; color: var(--muted); font-size: .82rem; }
.summary-card strong { display: block; margin-top: .4rem; }
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: white; }
.data-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.data-table th, .data-table td { padding: .72rem .8rem; border-bottom: 1px solid #e5e2d9; text-align: left; vertical-align: top; }
.data-table th { position: sticky; top: 0; background: #ebe8df; color: #34473e; font-size: .82rem; white-space: nowrap; }
.data-table tbody tr:hover { background: #faf8f1; }
.character-table { min-width: 1280px; }
.glyph-cell { font-size: 1.4rem; white-space: nowrap; }
.code-cell { font-family: "Cascadia Mono", Consolas, monospace; font-size: .8rem; }
.cell-warning { color: var(--danger); min-width: 180px; }
.footnote { color: var(--muted); font-size: .86rem; }

.page-heading { margin-bottom: 1.4rem; }
.page-heading h1 { font-size: clamp(2rem, 4vw, 3rem); }
.page-heading p:not(.eyebrow) { color: var(--muted); }
.filter-panel { padding: 1rem; }
.table-meta { margin: .6rem 0; color: var(--muted); font-size: .9rem; }
.admin-table .arabic-cell { font-size: 1.35rem; }
.action-cell { white-space: nowrap; }
.inline-form { display: inline; }
.link-button { border: 0; padding: 0; background: none; text-decoration: underline; text-underline-offset: .18em; }
.link-button.danger { color: var(--danger); margin-left: .6rem; }
.form-section h2 { font-size: 1.25rem; border-bottom: 1px solid var(--line); padding-bottom: .7rem; }
.entry-form label { margin-bottom: 1rem; }
.field-help { color: var(--muted); font-size: .82rem; font-weight: 450; }
.required { color: var(--danger); font-size: .78rem; }
.form-actions { display: flex; gap: .8rem; }
code { padding: .1rem .3rem; border-radius: 4px; background: #eceae2; }

.transliteration-options {
  margin-top: 1.1rem; padding: 1rem; border: 1px solid var(--line); border-radius: 10px;
  background: #faf8f1;
}
.transliteration-options summary { cursor: pointer; color: var(--deep); font-weight: 800; }
.option-toolbar { display: flex; align-items: center; gap: .8rem; margin: 1rem 0 .35rem; flex-wrap: wrap; }
.option-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; margin-top: .9rem; }
.check-option {
  display: grid; grid-template-columns: auto 1fr; align-items: start; gap: .7rem; padding: .8rem;
  border: 1px solid #dedacf; border-radius: 9px; background: var(--surface); font-weight: 450;
}
.check-option input { width: auto; margin-top: .18rem; accent-color: var(--accent); }
.check-option strong, .check-option small { display: block; }
.check-option strong { color: var(--ink); font-size: .92rem; }
.check-option small { margin-top: .3rem; color: var(--muted); line-height: 1.45; }
.contextual-option { border-style: dashed; }
.active-options { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .75rem; }
.option-tag { background: var(--accent-soft); color: #77311f; }

.guide-card-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.guide-card {
  display: block; min-height: 230px; padding: 1.35rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: var(--shadow); text-decoration: none; transition: transform .16s ease, border-color .16s ease;
}
.guide-card:hover { transform: translateY(-2px); border-color: #a7b5ad; }
.guide-card h2 { margin: 1.25rem 0 .7rem; font-size: 1.35rem; }
.guide-card p { color: var(--muted); line-height: 1.65; }
.guide-card .text-link { display: inline-block; margin-top: .6rem; }
.guide-comparison { margin-top: 2.5rem; }
.guide-heading { margin-bottom: .8rem; }
.guide-heading h2 { margin-bottom: 0; }
.comparison-table { min-width: 900px; }
.guide-signature { font-size: 1rem; line-height: 1.7; }
.guide-principles { margin-top: 2rem; }
.breadcrumbs { display: flex; gap: .35rem; color: var(--muted); font-size: .9rem; }
.guide-detail-hero { padding-bottom: 1.5rem; }
.guide-detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.guide-detail-grid .panel { margin: 0; }
.mapping-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; }
.mapping-pair {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: .35rem; padding: .65rem;
  background: #f3f0e7; border-radius: 8px; text-align: center;
}
.mapping-pair bdi { color: var(--deep); font-family: "Noto Naskh Arabic", "Amiri", serif; font-size: 1.55rem; }
.mapping-pair strong { font-family: "Charis SIL", Georgia, serif; }
.guide-list { margin: 0; padding-left: 1.25rem; color: #3f5048; line-height: 1.75; }
.guide-list li + li { margin-top: .55rem; }
.book-variant-panel { border-top: 4px solid var(--gold); }
.book-variant-panel .primary-button { margin-top: 1rem; }
.caution-panel { background: #fff9ed; }
.guide-source { margin: 1.4rem 0 0; padding: 1rem; color: var(--muted); border-top: 1px solid var(--line); }

@media (max-width: 820px) {
  .site-header, .page-heading, .result-heading { align-items: flex-start; flex-direction: column; }
  .controls-grid, .two-columns, .filter-grid, .analysis-summary, .explain-grid, .option-grid, .guide-card-grid, .guide-detail-grid { grid-template-columns: 1fr; }
  .match-card { grid-template-columns: 48px 1fr; }
  .match-card .icon-link { grid-column: 2; }
  .mapping-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .site-header { padding-inline: 1rem; }
  nav { gap: .65rem 1rem; }
  .page-shell { width: min(100% - 1rem, 1180px); padding-top: 1.5rem; }
  .panel { border-radius: 10px; }
}
