/* Kalimo web pages: the landing page (/i), the root page (/) and the 404 page.
   Colours, sizes and fonts come from assets/design/design-tokens.json.
   If the tokens change, change the values here too.
   The Content-Security-Policy allows no inline style, so every style lives in this file. */

/* Fonts: bundled files only, no font host. Licence texts are next to the files.
   The files are WOFF2 copies of the fonts in assets/fonts: the same letters, only
   packed smaller (see README.md). Only the four weights that this file uses. */
@font-face {
  font-family: "Readex Pro";
  src: url("fonts/ReadexPro-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Readex Pro";
  src: url("fonts/ReadexPro-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("fonts/IBMPlexSansArabic-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans Arabic";
  src: url("fonts/IBMPlexSansArabic-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* Tokens: light theme. */
:root {
  color-scheme: light dark;
  --primary: #2747C9;
  --on-primary: #FFFFFF;
  --secondary: #FFD43B;
  --on-secondary: #1F2430;
  --background: #FBFAF6;
  --surface: #FFFFFF;
  --on-surface: #1F2430;
  --surface-variant: #F1EEE6;
  --on-surface-variant: #575D6A;
  --outline: #878274;
  --error: #B42318;
  --success: #0F7A5F;
  --warning: #9E5A00;

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-xxl: 32px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --touch: 48px;
  --fast: 120ms;

  --font-display: "Readex Pro", system-ui, sans-serif;
  --font-body: "IBM Plex Sans Arabic", system-ui, sans-serif;
}

/* Tokens: dark theme, when the device asks for it. */
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #A9B9FF;
    --on-primary: #0E1D66;
    --secondary: #7A5C00;
    --on-secondary: #FFF3C4;
    --background: #11141B;
    --surface: #1A1E27;
    --on-surface: #EEEBE4;
    --surface-variant: #272C37;
    --on-surface-variant: #B4B8C2;
    --outline: #828898;
    --error: #FF8E80;
    --success: #5CD3AE;
    --warning: #F2B45E;
  }
}

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

/* Buttons and cards set their own display, so "hidden" must always win. */
[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--background);
  color: var(--on-surface);
  font: 400 1rem/1.5 var(--font-body);
  overflow-wrap: break-word;
}

/* Focus ring: 2px primary, 2px away, on every control. */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ---------- Page frame ---------- */

.page {
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
  padding: var(--space-xxl) var(--space-lg) var(--space-xl);
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.page > * {
  margin: 0;
}
.page > * + * {
  margin-top: var(--space-lg);
}

.logo {
  flex: none;
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 1px solid var(--surface-variant);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.logo svg {
  display: block;
  width: 100%;
  height: 100%;
}
.logo-k {
  fill: var(--on-surface);
}
.logo-mark {
  fill: var(--secondary);
}

/* The heading and the line under it. */
.page > .intro {
  margin-top: var(--space-xl);
}
.intro > * {
  margin: 0;
}

/* "title": Readex Pro 600, 22px. */
.title {
  font: 600 1.375rem/1.3 var(--font-display);
  color: var(--on-surface);
}

/* "body" in the quiet text colour. */
.lead {
  color: var(--on-surface-variant);
}
.intro > .lead {
  margin-top: var(--space-sm);
}

/* "caption": 12px. */
.hint {
  font-size: 0.75rem;
  line-height: 1.35;
  letter-spacing: 0.2px;
  color: var(--on-surface-variant);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* The safety-net line in i.html. It stays invisible for 4 seconds, and page.js
   hides it long before that. So it is seen only when the script never ran.
   "!important" keeps the wait when the device asks for no motion (end of this file):
   this is a wait, not a movement. */
.boot {
  visibility: hidden;
  animation: boot-show 0s linear 4s forwards !important;
}
@keyframes boot-show {
  to {
    visibility: visible;
  }
}

/* ---------- Icons: Material Icons (rounded), the same ones as in the app ---------- */

.icon {
  flex: none;
  width: 1.5rem;
  height: 1.5rem;
  fill: currentColor;
}

/* ---------- Buttons (design: Button) ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  min-width: var(--touch);
  min-height: var(--touch);
  margin: 0;
  padding: var(--space-sm) var(--space-xl);
  border: 0;
  border-radius: var(--radius-md);
  font: 500 0.9375rem/1.35 var(--font-body);
  letter-spacing: 0.1px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--fast) ease-out;
  -webkit-tap-highlight-color: transparent;
}
.btn .icon {
  width: 1.25rem;
  height: 1.25rem;
}
.btn-primary {
  min-height: 56px;
  background: var(--primary);
  color: var(--on-primary);
}
.btn-secondary {
  background: var(--surface-variant);
  color: var(--on-surface);
}
.btn-wide {
  width: 100%;
}
.btn[aria-disabled="true"] {
  opacity: 0.38;
  cursor: default;
}

/* Hover and press: a thin layer of the text colour over the fill. */
@supports (background: color-mix(in srgb, red 10%, blue)) {
  .btn-primary:hover {
    background: color-mix(in srgb, var(--on-primary) 8%, var(--primary));
  }
  .btn-primary:active {
    background: color-mix(in srgb, var(--on-primary) 14%, var(--primary));
  }
  .btn-secondary:not([aria-disabled="true"]):hover {
    background: color-mix(in srgb, var(--on-surface) 8%, var(--surface-variant));
  }
  .btn-secondary:not([aria-disabled="true"]):active {
    background: color-mix(in srgb, var(--on-surface) 14%, var(--surface-variant));
  }
}

/* ---------- Cards and banners (design: Feedback) ---------- */

.card,
.banner {
  padding: var(--space-lg);
  background: var(--surface);
  border: 1px solid var(--surface-variant);
  border-radius: var(--radius-lg);
}
.page > .card,
.page > .banner,
.page > .btn-primary {
  margin-top: var(--space-xl);
}
.card-title,
.banner-title {
  margin: 0;
  font: 500 0.9375rem/1.35 var(--font-body);
  letter-spacing: 0.1px;
}
.steps {
  margin: var(--space-sm) 0 0;
  padding-left: 1.4em;
  color: var(--on-surface-variant);
}
.steps li + li {
  margin-top: var(--space-xs);
}
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-md);
}
.banner .icon {
  color: var(--primary);
}
.banner-body {
  margin: 2px 0 0;
  color: var(--on-surface-variant);
}

/* ---------- Copy ---------- */

.copy-box {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.page > .copy-box {
  margin-top: var(--space-sm);
}
.copy-box .hint {
  margin: var(--space-sm) 0 0;
}
/* Shown only when the browser refuses to copy: the user copies by hand. */
.copy-manual {
  width: 100%;
  min-height: 6rem;
  margin: var(--space-sm) 0 0;
  padding: var(--space-md);
  background: var(--surface);
  color: var(--on-surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-md);
  font: 400 0.875rem/1.4 ui-monospace, monospace;
  word-break: break-all;
  resize: vertical;
}

/* ---------- QR codes (laptop view) ---------- */

.qr-area {
  display: flex;
  flex-direction: column;
  align-items: center;
}
/* Always dark on white, in both themes, so every scanner can read it.
   As big as the window allows (a big code is easier to scan), but the heading,
   the code and its buttons still fit on one screen: 17.5rem is the room they need. */
.qr {
  width: min(100%, max(12rem, min(40rem, 100vh - 17.5rem)));
  aspect-ratio: 1 / 1;
  padding: var(--space-sm);
  background: #FFFFFF;
  border: 1px solid var(--surface-variant);
  border-radius: var(--radius-md);
}
.qr svg {
  display: block;
  width: 100%;
  height: 100%;
}
.qr-ink {
  fill: #1F2430;
}
.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm) var(--space-md);
  margin-top: var(--space-lg);
}
.pager-label {
  min-width: 7rem;
  margin: 0;
  font: 500 0.9375rem/1.35 var(--font-body);
  letter-spacing: 0.1px;
}
.qr-area .hint {
  margin: var(--space-md) 0 0;
}
/* Narrow screens. Every phone that is not Android gets this view, and the row
   "Previous / Code 1 of 3 / Next" is wider than such a screen. There the two
   buttons show only their arrow (48px squares) and the label takes the middle.
   The words stay in the page for screen readers. */
@media (max-width: 28rem) {
  .pager {
    display: grid;
    grid-template-columns: auto 1fr auto;
    width: 100%;
  }
  .pager .btn {
    padding: var(--space-sm);
  }
  .pager-label {
    min-width: 0;
    text-align: center;
  }
  .btn-word {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* ---------- Laptop view: everything centred, logo next to the heading ---------- */

.page[data-view="desktop"] {
  max-width: 44rem;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  column-gap: var(--space-md);
  padding-top: clamp(32px, 9vh, 96px);
  text-align: center;
}
.page[data-view="desktop"] > * {
  flex: 0 0 100%;
}
.page[data-view="desktop"] > .logo {
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
}
/* The heading sits in the same row as the logo; the line under it takes the next row. */
.page[data-view="desktop"] > .intro {
  display: contents;
}
.page[data-view="desktop"] .title {
  flex: 0 1 auto;
  min-width: 0;
}
.page[data-view="desktop"] .intro > .lead {
  flex: 0 0 100%;
  margin-top: var(--space-lg);
}
.page[data-view="desktop"] > .qr-area,
.page[data-view="desktop"] > .copy-box {
  margin-top: var(--space-xl);
  align-items: center;
}

/* ---------- Problem view (design: empty state, "Broken link") ---------- */

.page[data-view="error"] > .intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-xxl) var(--space-xl);
  background: var(--surface);
  border: 1px solid var(--surface-variant);
  border-radius: var(--radius-lg);
  text-align: center;
}
/* "subtitle": Readex Pro 500, 17px. */
.page[data-view="error"] .title {
  margin-top: var(--space-xl);
  font: 500 1.0625rem/1.4 var(--font-display);
}
/* A 48px icon over a short marker stroke. */
.mark {
  position: relative;
  isolation: isolate;
  width: 72px;
  height: 56px;
  display: grid;
  place-items: center;
  color: var(--on-surface);
}
.mark::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 0;
  right: 0;
  bottom: 2px;
  height: 16px;
  background: var(--secondary);
}
.mark .icon {
  width: 48px;
  height: 48px;
}

/* ---------- Root page ---------- */

/* "term": Readex Pro 600, 30px, with the marker stroke behind its lower part. */
.brand {
  font: 600 1.875rem/1.25 var(--font-display);
  letter-spacing: -0.2px;
}
.marker {
  margin: 0 -0.12em;
  padding: 0 0.12em;
  background-image: linear-gradient(
    transparent 56%,
    var(--secondary) 56%,
    var(--secondary) 92%,
    transparent 92%
  );
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* No motion when the device asks for none. */
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
