/*
 * Arabic age calculator — layout and components.
 * Colour tokens follow the CifraListo.com palette (light theme) as a visual reference.
 * Logical properties (inline/block) keep the layout correct in right-to-left text.
 */

:root {
  color-scheme: light;
  --color-bg: #f4f6f9;
  --color-surface: #ffffff;
  --color-text: #1b2430;
  --color-text-muted: #5a6474;
  --color-border: #d9dee6;
  --color-control-border: #858f9e;
  --color-accent: #2457c5;
  --color-accent-hover: #1d47a3;
  --color-accent-soft: #dde6f7;
  --color-accent-soft-hover: #cbd8f3;
  --color-accent-text: #1e3a8a;
  --color-result-bg: #eef2f7;
  --color-callout-bg: #f2f6fd;
  --color-error: #b42318;
  --color-error-bg: #fef3f2;
  --color-error-border: #f4c7c3;
  --font-sans: system-ui, -apple-system, "Segoe UI", Tahoma, "Geeza Pro", "Noto Sans Arabic", "Noto Naskh Arabic", Arial, sans-serif;
  --radius-card: 20px;
  --radius-control: 12px;
  --gutter: 16px;
  --shadow-card: 0 1px 2px rgb(0 0 0 / 0.06), 0 8px 24px rgb(0 0 0 / 0.08);
  --shadow-soft: 0 1px 2px rgb(0 0 0 / 0.05);
  --focus-ring: 0 0 0 3px var(--color-surface), 0 0 0 5px var(--color-accent);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  line-height: 1.8;
  overflow-wrap: break-word;
}

h1,
h2,
h3 {
  line-height: 1.45;
  margin: 0 0 0.5em;
}

h1 {
  font-size: clamp(1.625rem, 1.2rem + 1.6vw, 2.125rem);
}

h2 {
  font-size: clamp(1.25rem, 1.1rem + 0.6vw, 1.5rem);
}

h3 {
  font-size: 1.125rem;
}

p,
ul,
ol {
  margin: 0 0 1em;
}

ul,
ol {
  padding-inline-start: 1.5em;
}

li + li {
  margin-block-start: 0.4em;
}

a {
  color: var(--color-accent);
  text-underline-offset: 0.2em;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: 4px;
}

[hidden] {
  display: none !important;
}

.container {
  width: 100%;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--gutter);
  padding-right: var(--gutter);
}

.skip-link {
  position: absolute;
  right: var(--gutter); /* page is always RTL */
  top: -100px;
  z-index: 10;
  padding: 0.5em 1em;
  background: var(--color-surface);
  color: var(--color-accent);
  border-radius: var(--radius-control);
}

.skip-link:focus {
  top: var(--gutter);
}

/* Header and footer */

.site-header {
  background: var(--color-surface);
  border-block-end: 1px solid var(--color-border);
}

.site-header .container {
  display: flex;
  align-items: center;
  min-height: 64px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--color-text);
  font-size: 1.1875rem;
  font-weight: 700;
  text-decoration: none;
}

.brand img {
  display: block;
  border-radius: 8px;
}

.site-footer {
  margin-block-start: 48px;
  padding-block: 28px;
  background: var(--color-surface);
  border-block-start: 1px solid var(--color-border);
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

.site-footer p {
  margin: 0;
}

.footer-brand {
  color: var(--color-text);
  font-weight: 700;
}

/* Intro */

main {
  padding-block: 32px 0;
}

@media (min-width: 600px) {
  main {
    padding-block-start: 44px;
  }
}

.intro {
  margin-block-end: 28px;
}

.lead {
  color: var(--color-text-muted);
  font-size: 1.125rem;
}

.page-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.page-nav li + li {
  margin: 0;
}

.page-nav a {
  display: inline-block;
  padding: 0.4em 1em;
  border-radius: 999px;
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
}

/* Cards */

.card,
.content {
  margin-block-end: 24px;
  padding: 24px var(--gutter);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
}

.card {
  box-shadow: var(--shadow-card);
}

.content {
  box-shadow: var(--shadow-soft);
}

@media (min-width: 600px) {
  .card,
  .content {
    padding: 32px;
  }
}

.calculator,
.content {
  scroll-margin-block-start: 16px;
}

.content > :last-child,
.card > :last-child {
  margin-block-end: 0;
}

.notice,
.note {
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

.notice {
  padding: 12px 16px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
}

.note {
  margin-block-start: 20px;
  padding-block-start: 16px;
  border-block-start: 1px solid var(--color-border);
}

/* Form */

.age-form {
  margin-block-start: 20px;
}

.age-form fieldset {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.age-form legend {
  padding: 0;
  font-size: 1.0625rem;
  font-weight: 700;
}

.hint {
  margin: 0.25em 0 0.75em;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

/*
 * Narrow screens: day and month share the first row, the year takes the second.
 * Wider screens: day, month and year in one row (right to left).
 */
.date-fields {
  display: grid;
  grid-template-columns: 5.25rem minmax(0, 1fr);
  gap: 12px 10px;
}

.field-year {
  grid-column: 1 / -1;
}

@media (min-width: 480px) {
  .date-fields {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.5fr) minmax(0, 1fr);
  }

  .field-year {
    grid-column: auto;
  }
}

.field label {
  display: block;
  margin-block-end: 4px;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.field select {
  width: 100%;
  min-height: 48px;
  padding-block: 8px;
  padding-inline: 10px 30px;
  appearance: none;
  background-color: var(--color-surface);
  /* Chevron drawn with gradients so no image request is needed; placed on the inline end (left in RTL). */
  background-image:
    linear-gradient(45deg, transparent 50%, var(--color-text-muted) 50%),
    linear-gradient(135deg, var(--color-text-muted) 50%, transparent 50%);
  background-position: left 12px center, left 17px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  border: 1px solid var(--color-control-border);
  border-radius: var(--radius-control);
  color: var(--color-text);
  font: inherit;
  font-size: 1rem;
  text-overflow: ellipsis;
  cursor: pointer;
}

.field select:focus-visible {
  border-color: var(--color-accent);
  border-radius: var(--radius-control);
}

.field select[aria-invalid="true"] {
  border-color: var(--color-error);
  box-shadow: 0 0 0 1px var(--color-error);
}

.today-line {
  margin: 12px 0 0;
  color: var(--color-accent-text);
  font-size: 0.9375rem;
  font-weight: 600;
}

.form-error:empty {
  display: none;
}

.form-error {
  margin: 16px 0 0;
  padding: 10px 14px;
  background: var(--color-error-bg);
  border: 1px solid var(--color-error-border);
  border-radius: var(--radius-control);
  color: var(--color-error);
  font-size: 0.9375rem;
  font-weight: 600;
}

/* Narrow phones: buttons stacked full width (calculate first) so neither label wraps. */
.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-block-start: 20px;
}

@media (min-width: 400px) {
  .form-actions {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

@media (min-width: 600px) {
  .form-actions {
    display: flex;
  }
}

.button {
  min-height: 48px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font: inherit;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  cursor: pointer;
}

.button-primary {
  background: var(--color-accent);
  color: #ffffff;
}

.button-primary:disabled {
  background: var(--color-text-muted);
  cursor: not-allowed;
}

.button-secondary {
  background: var(--color-surface);
  border-color: var(--color-control-border);
  color: var(--color-text);
}

@media (min-width: 600px) {
  .button {
    padding: 0 24px;
  }

  .button-primary {
    min-width: 200px;
  }
}

/* Result */

.result {
  margin-block-start: 24px;
  padding: 20px var(--gutter);
  background: var(--color-result-bg);
  border-inline-start: 4px solid var(--color-accent);
  border-radius: var(--radius-control);
  scroll-margin-block: 16px;
}

@media (min-width: 600px) {
  .result {
    padding: 24px;
  }
}

.result:focus-visible {
  border-radius: var(--radius-control);
}

.result h3 {
  margin-block-end: 0.25em;
  color: var(--color-accent-text);
  font-size: 1rem;
}

.result-sentence {
  margin-block-end: 16px;
  font-size: 1.1875rem;
  font-weight: 700;
  line-height: 1.6;
}

.result-units {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
}

.result-units > div {
  padding: 12px 6px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-control);
  text-align: center;
}

.result-units dt {
  color: var(--color-text-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.result-units dd {
  margin: 0;
  color: var(--color-accent-text);
  font-size: clamp(1.625rem, 1.3rem + 1.4vw, 2.125rem);
  font-weight: 800;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
}

.result-dates {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 0.9375rem;
}

.result-dates span {
  display: block;
}

/* How-to steps: numbered badges */

.steps {
  counter-reset: step;
  padding: 0;
  list-style: none;
}

.steps li {
  counter-increment: step;
  position: relative;
  min-height: 32px;
  padding-inline-start: 44px;
}

.steps li + li {
  margin-block-start: 12px;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  right: 0; /* page is always RTL */
  top: 0;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-accent-soft);
  color: var(--color-accent-text);
  font-weight: 700;
  line-height: 1;
}

/* Hijri limitations callout */

.callout {
  margin-block-start: 24px;
  padding: 16px var(--gutter);
  background: var(--color-callout-bg);
  border: 1px solid var(--color-accent-soft);
  border-inline-start: 4px solid var(--color-accent);
  border-radius: var(--radius-control);
}

@media (min-width: 600px) {
  .callout {
    padding: 20px 24px;
  }
}

.callout h3 {
  scroll-margin-block-start: 16px;
}

.callout ul {
  margin: 0;
}

/* FAQ */

.faq-item {
  padding-block: 16px;
  border-block-start: 1px solid var(--color-border);
}

.faq-item:last-child {
  padding-block-end: 0;
}

.faq-item h3 {
  margin-block-end: 0.35em;
}

.faq-item p {
  margin: 0;
}

/*
 * Hover styles only for devices with a real hover pointer (mouse/trackpad). On touch screens the
 * browser applies :hover on tap and leaves it stuck, which made the last-tapped field look different.
 */
@media (hover: hover) {
  a:hover {
    color: var(--color-accent-hover);
  }

  .brand:hover {
    color: var(--color-accent);
  }

  .page-nav a:hover {
    background: var(--color-accent-soft-hover);
    color: var(--color-accent-text);
  }

  .field select:hover:not([aria-invalid="true"]):not(:focus-visible) {
    border-color: var(--color-text);
  }

  .button-primary:hover:not(:disabled) {
    background: var(--color-accent-hover);
  }

  .button-secondary:hover {
    background: var(--color-bg);
  }
}
