:root {
  --paper: #f6f1e7;
  --surface: #fffdf8;
  --ink: #2a211b;
  --muted: #6d5f53;
  --line: #d8ccba;
  --key: #fffdf8;
  --key-edge: #c9bba6;
  --key-pressed: #eadfcc;
  --accent: #a33d1f;
  --accent-ink: #ffffff;
  --accent-soft: #f6dfd3;
  --key-size: 68px;
  --arabic: "Noto Naskh Arabic", "Noto Sans Arabic", "Segoe UI", "Geeza Pro", "Tahoma", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1d1916;
    --surface: #27211c;
    --ink: #f2eadf;
    --muted: #b5a797;
    --line: #463c33;
    --key: #332b25;
    --key-edge: #14100d;
    --key-pressed: #463b32;
    --accent: #e0754f;
    --accent-ink: #1d1916;
    --accent-soft: #4c2c20;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

main, .masthead {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 0 16px;
}

.masthead { padding-top: 14px; }

h1 { margin: 0 0 10px; font-size: 1.15rem; font-weight: 700; }

h2 { margin: 0; font-size: 1.15rem; }

[lang="ar"] { font-family: var(--arabic); }

/* English and Arabic together. A heading puts each language at its own edge,
   since Arabic starts on the right. */
.bi-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px 16px;
}

.bi-head [lang="ar"] { font-size: 1.12em; }

.bi {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5em;
}

.bi [lang="ar"] { font-size: 1.08em; }

/* Paragraphs side by side: English on the left, Arabic on the right. */
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 40px;
  margin-top: 6px;
}

.pair p { margin: 0; }

.pair [lang="ar"] { font-size: 1.08em; line-height: 1.7; }

button, input { font: inherit; color: inherit; }

button {
  min-height: 44px;
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover { border-color: var(--muted); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

#text {
  display: block;
  width: 100%;
  min-height: 120px;
  padding: 12px 16px;
  resize: vertical;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: var(--arabic);
  font-size: 1.75rem;
  line-height: 1.6;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  min-width: 96px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 28px;
  margin: 14px 0 10px;
}

.setting { display: flex; align-items: center; gap: 10px; margin: 0; }

/* Seven languages don't fit on one line beside two labels, so the labels
   share the top line, each at its own edge, with the languages below. */
.setting.language {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  margin-bottom: 12px;
}

.setting.language .label { grid-row: 1; }

.setting.language .label[lang="ar"] { grid-column: 2; justify-self: end; }

.setting.language .segments { grid-column: 1 / -1; }

.languages a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 12px 4px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: inherit;
  text-decoration: none;
}

.languages a:hover { border-color: var(--muted); }

.languages a[aria-current="page"] {
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  padding: 3px 11px 3px 9px;
}

.languages .flag {
  flex: none;
  border-radius: 2px;
  /* A thin edge keeps white stripes visible on a light background. */
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.18);
}

.setting .label { font-weight: 600; }

.setting .label[lang="ar"] { font-size: 1.08em; }

.segments { display: flex; flex-wrap: wrap; gap: 6px; }

.segments button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
}

.segments button b { font: 400 1.6rem/1 var(--arabic); }

.segments small {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.25;
}

.segments small [lang="ar"] { font-size: 1.05em; }

.segments button[aria-pressed="true"] {
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  padding: 3px 9px;
}

.segments button[aria-pressed="true"] small { color: var(--ink); }

.size-choice input { width: 170px; height: 32px; accent-color: var(--accent); }

.size-choice output { min-width: 3.2em; color: var(--muted); font-variant-numeric: tabular-nums; }

.toggle { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }

.toggle input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }

.toggle [lang="ar"] { font-size: 1.08em; }

/* Width is capped by key size and shrinks to the screen; height always follows the setting. */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: calc(var(--key-size) * 14.2);
  margin: 0 auto;
  user-select: none;
  -webkit-user-select: none;
}

.row { display: flex; gap: 6px; }

.key {
  flex: var(--span, 1) 1 0;
  min-width: 0;
  height: var(--key-size);
  min-height: 0;
  padding: 0;
  overflow: hidden;
  background: var(--key);
  border: 1px solid var(--line);
  border-bottom: 3px solid var(--key-edge);
  border-radius: 8px;
  font: 400 calc(var(--key-size) * 0.46)/1 var(--arabic);
  touch-action: none;
}

.key.pressed, .key:active {
  background: var(--key-pressed);
  border-bottom-width: 1px;
  padding-top: 2px;
}

.key.function {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: 600 clamp(10px, calc(var(--key-size) * 0.19), 17px)/1.1 "Segoe UI", system-ui, sans-serif;
  color: var(--muted);
}

.key.function [lang="ar"] { font-size: 1.1em; font-weight: 400; }

.key.backspace { font-size: clamp(14px, calc(var(--key-size) * 0.3), 26px); }

.key.g {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.key.g.pressed, .key.g:active { filter: brightness(0.86); }

.key.shift[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}

.clocks, .help {
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.clocks-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 16px;
  margin: 10px 0 12px;
}

.note { margin: 0; color: var(--muted); }

.add-clock { gap: 8px; margin-inline-start: auto; }

.note .label { font-weight: 400; }

.add-clock input {
  width: 170px;
  min-height: 44px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.error { flex-basis: 100%; justify-content: flex-end; margin: 0; color: var(--accent); }

.error[hidden] { display: none; }

.clock-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* The dial on the left; name, time and details beside it. */
.clock {
  display: grid;
  grid-template-columns: auto 1fr auto;
  column-gap: 14px;
  align-items: center;
  padding: 12px 4px 12px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.clock h3 { grid-column: 2; margin: 0; font-size: 1rem; font-weight: 600; }

.clock h3 [lang="ar"] { font-weight: 400; }

.clock .remove {
  grid-column: 3;
  grid-row: 1;
  min-width: 44px;
  min-height: 36px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.25rem;
}

.clock time {
  grid-column: 2 / -1;
  font-size: 1.85rem;
  font-weight: 600;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.clock p { grid-column: 2 / -1; margin: 0; color: var(--muted); font-size: 0.85rem; }

.clock p[lang="ar"] { font-size: 0.92rem; text-align: right; padding-inline-end: 10px; }

.clock .sun-times { font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }

/* Analog dial. The face is the sky over that city right now. */
.dial {
  grid-row: 1 / span 6;
  width: 104px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--sky-top, #1a2240), var(--sky-bottom, #3a3a66));
  box-shadow:
    inset 0 0 0 3px rgb(255 255 255 / 0.14),
    inset 0 -10px 18px rgb(0 0 0 / 0.12),
    0 2px 6px rgb(0 0 0 / 0.22);
  transition: background 1.5s;
}

.dial svg { display: block; width: 100%; height: 100%; overflow: visible; }

.dial .tick { stroke: var(--ink); stroke-width: 0.8; opacity: 0.4; }

.dial .tick.hour { stroke-width: 1.9; opacity: 0.85; stroke-linecap: round; }

.dial .numerals text {
  fill: var(--ink);
  font: 600 11px/1 var(--arabic);
  text-anchor: middle;
  dominant-baseline: central;
}

.dial .hand { stroke: var(--ink); stroke-linecap: round; }

.dial .hour-hand { stroke-width: 3.6; }

.dial .minute-hand { stroke-width: 2.4; }

.dial .second-hand { stroke: #e2552f; stroke-width: 1.1; stroke-linecap: round; }

.dial .pin { fill: #e2552f; stroke: var(--ink); stroke-width: 0.8; }

.dial .stars { opacity: var(--stars, 0); transition: opacity 1.5s; }

.dial .stars circle { fill: #fff; }

.dial .sun, .dial .moon { transition: opacity 1.5s; }

.dial .sun { opacity: 0; fill: #ffcf4d; }

.dial .sun .glow { fill: #ffe9a3; opacity: 0.45; }

.dial .moon { fill: #f1ecd2; opacity: 0.95; }

.dial.sun-up .sun { opacity: 1; }

.dial.sun-up .moon { opacity: 0; }

.help { padding-bottom: 24px; }

.site-footer {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding: 16px 16px 40px;
  border-top: 1px solid var(--line);
}

.site-footer a, .legal a { color: var(--muted); }

/* Privacy and other text pages. */
.legal {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.legal h1 { font-size: 1.6rem; margin: 16px 0 4px; }

.legal h2 { font-size: 1.05rem; margin: 22px 0 4px; }

.legal .pair { gap: 4px 48px; margin-top: 8px; }

.legal section p { margin: 0; line-height: 1.6; }

.help .pair + h2, .help .map + h2 { margin-top: 28px; }

.help .privacy { margin-top: 28px; color: var(--muted); }

.map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px 16px;
  max-width: 900px;
  margin: 12px 0 0;
}

.map div { display: flex; justify-content: space-between; border-bottom: 1px solid var(--line); }

.map dt { font-weight: 600; font-family: ui-monospace, Consolas, monospace; font-size: 0.9rem; align-self: center; }

.map dd { margin: 0; font-size: 1.3rem; line-height: 1.5; }

@media (max-width: 640px) {
  .row, .keyboard { gap: 3px; }
  .key { border-radius: 5px; font-size: min(calc(var(--key-size) * 0.46), 6.2vw); }
  .error { justify-content: flex-start; }
  /* On a phone both labels share the top line, English at the left edge and
     Arabic at the right, with the control on the line below. */
  .setting { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; width: 100%; }
  .setting .label { grid-row: 1; }
  .setting .label[lang="ar"] { grid-column: 2; justify-self: end; }
  .setting .segments { grid-column: 1 / -1; }
  .add-clock { margin-inline-start: 0; }
  .add-clock input, .size-choice input { width: 100%; min-width: 0; }
  .pair { grid-template-columns: 1fr; gap: 10px; }
}
