:root {
  --paper: #f5f2eb;
  --ink: #1a1a1a;
  --ink-soft: #3a3833;
  --ink-faded: #6b6760;
  --rule: #c9c2b3;
  --accent: #7a2a1c;
  --serif: 'EB Garamond', 'Iowan Old Style', Georgia, serif;
  --arabic: 'Amiri', 'Traditional Arabic', serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

body {
  font-family: var(--serif);
  background: var(--paper);
  color: var(--ink);
  font-size: 19px;
  line-height: 1.6;
}

.wrap {
  max-width: 680px;
  margin: 0 auto;
  padding: 4rem 2rem;
}

a {
  color: var(--ink-soft);
  text-decoration: none;
  border-bottom: 1px solid var(--rule);
  transition: color 0.2s ease, border-color 0.2s ease;
}
a:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* Header ------------------------------------------------------------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 2.5rem;
}
.breadcrumb {
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-faded);
}
.lang-toggle { display: flex; gap: 1rem; flex: 0 0 auto; }
.lang-toggle .toggle { margin: 0; font-size: 0.92rem; }

/* Language / direction ---------------------------------------------- */
body.lang-ar { font-family: var(--arabic); }
body:not(.lang-ar) .i18n-ar { display: none; }
body.lang-ar .i18n-en { display: none; }
.ltr-inline { unicode-bidi: isolate; }

h1 {
  font-size: 2.4rem;
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin-bottom: 0.35rem;
}
.title-ar {
  font-family: var(--arabic);
  font-size: 1.9rem;
  direction: rtl;
  color: var(--ink-soft);
  line-height: 1.3;
  margin-bottom: 1.2rem;
}
.lede {
  font-style: italic;
  font-size: 1.05rem;
  color: var(--ink-faded);
  margin-bottom: 2.5rem;
}

hr { border: 0; border-top: 1px solid var(--rule); margin: 2.5rem 0; }

/* System toggle ------------------------------------------------------ */
.toggle-row { margin-bottom: 1.6rem; }
.toggle-row .label {
  display: block;
  font-style: italic;
  font-size: 0.85rem;
  color: var(--ink-faded);
  margin-bottom: 0.4rem;
}
.toggle {
  background: none;
  border: 0;
  border-bottom: 1px solid transparent;
  font-family: var(--serif);
  font-size: 1rem;
  color: var(--ink-faded);
  cursor: pointer;
  padding: 0 0 1px 0;
  margin-right: 1.5rem;
  transition: color 0.2s ease, border-color 0.2s ease;
}
.toggle:hover { color: var(--accent); }
.toggle[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--accent); }

/* Input -------------------------------------------------------------- */
#input {
  width: 100%;
  min-height: 5.5rem;
  font-family: var(--arabic);
  font-size: 2.2rem;
  line-height: 1.7;
  direction: rtl;
  text-align: right;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 0;
  padding: 0.9rem 1rem;
  resize: vertical;
  transition: border-color 0.2s ease;
}
#input:focus { outline: none; border-color: var(--accent); }
#input::placeholder { color: var(--ink-faded); opacity: 0.6; }

/* Total -------------------------------------------------------------- */
.total-block {
  margin: 2.2rem 0 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 1rem;
  flex-wrap: wrap;
}
#total {
  font-family: var(--serif);
  font-size: 4.5rem;
  font-weight: 500;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -0.02em;
}
#total-ar {
  font-family: var(--arabic);
  direction: rtl;
  font-size: 2rem;
  color: var(--ink-faded);
}
#count { font-style: italic; font-size: 0.95rem; color: var(--ink-faded); margin-bottom: 1.5rem; }

/* Breakdown ---------------------------------------------------------- */
h2 {
  font-style: italic;
  font-weight: 500;
  font-size: 1rem;
  color: var(--ink-faded);
  margin-bottom: 1rem;
}
#breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.2rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--rule);
}
.tile-ar {
  font-family: var(--arabic);
  font-size: 1.8rem;
  line-height: 1.1;
  color: var(--ink);
}
.tile-val {
  font-family: var(--serif);
  font-size: 0.9rem;
  color: var(--accent);
  margin-top: 0.2rem;
}
#breakdown .empty { font-style: italic; color: var(--ink-faded); font-size: 0.95rem; }

/* Suggestions -------------------------------------------------------- */
details.suggestions { margin-top: 1.4rem; }
details.suggestions > summary {
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-soft);
  cursor: pointer;
  list-style: none;
}
details.suggestions > summary::-webkit-details-marker { display: none; }
details.suggestions > summary::before { content: '+ '; color: var(--accent); font-style: normal; }
details.suggestions[open] > summary::before { content: '\00D7 '; color: var(--accent); font-style: normal; } /* x */
.sg-hint { color: var(--ink-faded); font-size: 0.82rem; }

.sg-list { display: flex; flex-direction: column; margin-top: 0.9rem; }
.suggestion {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  width: 100%;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  cursor: pointer;
  padding: 0.55rem 0;
  font-family: var(--serif);
  transition: background 0.15s ease;
}
.sg-list .suggestion:last-child { border-bottom: 0; }
.suggestion:hover, .suggestion:focus-visible { background: rgba(122, 42, 28, 0.05); outline: none; }
.sg-ar {
  font-family: var(--arabic);
  direction: rtl;
  font-size: 1.5rem;
  line-height: 1.4;
  color: var(--ink);
}
.suggestion:hover .sg-ar, .suggestion:focus-visible .sg-ar { color: var(--accent); }
.sg-note { font-style: italic; font-size: 0.9rem; color: var(--ink-faded); }

/* Notes -------------------------------------------------------------- */
.note {
  font-style: italic;
  font-size: 0.88rem;
  color: var(--ink-faded);
  line-height: 1.55;
  margin-top: 2rem;
  padding-left: 0.9rem;
  border-left: 1px solid var(--rule);
}
.note .ar-inline { font-family: var(--arabic); direction: rtl; }

/* Chronogram --------------------------------------------------------- */
details.chronogram {
  margin-top: 2.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--rule);
}
details.chronogram summary {
  font-style: italic;
  font-size: 1rem;
  color: var(--ink-soft);
  cursor: pointer;
  list-style: none;
}
details.chronogram summary::-webkit-details-marker { display: none; }
details.chronogram summary::before { content: '+ '; color: var(--accent); }
details.chronogram[open] summary::before { content: '\2212 '; } /* minus */
details.chronogram p {
  font-size: 0.98rem;
  color: var(--ink-soft);
  margin-top: 1rem;
}
details.chronogram .ar-inline { font-family: var(--arabic); direction: rtl; }

/* FAQ ---------------------------------------------------------------- */
details.faq {
  margin-top: 2.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--rule);
}
details.faq summary {
  font-style: italic;
  font-size: 1rem;
  color: var(--ink-soft);
  cursor: pointer;
  list-style: none;
}
details.faq summary::-webkit-details-marker { display: none; }
details.faq summary::before { content: '+ '; color: var(--accent); font-style: normal; }
details.faq[open] summary::before { content: '\2212 '; color: var(--accent); font-style: normal; }
details.faq dl { margin-top: 1rem; }
details.faq dt { font-weight: 500; margin-top: 1.2rem; color: var(--ink); }
details.faq dd { color: var(--ink-soft); font-size: 0.96rem; line-height: 1.55; margin-top: 0.3rem; }

footer {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.82rem;
  font-style: italic;
  color: var(--ink-faded);
}
footer a { color: var(--ink-soft); }

@media (max-width: 600px) {
  body { font-size: 17px; }
  .wrap { padding: 3rem 1.5rem; }
  h1 { font-size: 2rem; }
  .title-ar { font-size: 1.6rem; }
  #input { font-size: 1.9rem; }
  #total { font-size: 3.4rem; }
}
