/*
 * Tounsi design system — mobile first.
 *
 * Written phone-up rather than desktop-down, because the previous stylesheet was
 * built at desktop width and overflowed its viewport on a 390px screen: text was
 * clipped off the edge and inputs were unstyled. Everything here is fluid by
 * default and only gains width at a breakpoint.
 *
 * The look is Duolingo's: heavy rounded type, chunky controls with a solid
 * bottom edge that compresses when pressed, generous spacing, bright accents on
 * a dark surface.
 */

:root {
  --bg: #0e1522;
  --bg-2: #131d2e;
  --surface: #18233a;
  --surface-2: #1e2b45;
  --line: #24314d;

  --text: #f2f6ff;
  --muted: #8fa0c0;

  --green: #58cc02;
  --green-dark: #43a302;
  --blue: #1cb0f6;
  --blue-dark: #1690ca;
  --amber: #ffc800;
  --amber-dark: #d9a600;
  --red: #ff4b4b;
  --red-dark: #c93232;
  --purple: #ce82ff;

  /* Chart series — validated for CVD separation against this dark surface. */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;

  --radius: 18px;
  --radius-lg: 24px;
  --pad: 16px;

  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

html {
  /* A single overflowing child should never shift the whole page sideways. */
  overflow-x: hidden;
}

body {
  margin: 0;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg-2) 0%, var(--bg) 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: "SF Arabic", "Geeza Pro", ui-rounded, -apple-system, system-ui, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.65;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

/* One shell for every page: centred, never wider than the viewport. */
.shell {
  width: 100%;
  max-width: 640px;
  margin-inline: auto;
  padding-inline: var(--pad);
  /* Safe areas so nothing hides under a notch or home indicator. */
  padding-inline-start: max(var(--pad), env(safe-area-inset-left));
  padding-inline-end: max(var(--pad), env(safe-area-inset-right));
}
.shell.wide { max-width: 1080px; }

/* ------------------------------------------------------------------ type -- */

h1, h2, h3 { margin: 0; font-weight: 800; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 20px; }
h3 { font-size: 17px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------------------------------------------------------------- header -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding-block: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 20px; white-space: nowrap; }
.mark {
  /* A span is inline by default, so width/height and `margin: auto` were being
     ignored anywhere it was not a flex child. */
  display: block;
  width: 30px; height: 30px;
  flex: none;
  border-radius: 10px;
  background: linear-gradient(160deg, var(--green), #2fa8a0);
  box-shadow: 0 3px 0 var(--green-dark);
}

/* ----------------------------------------------------------------- cards -- */

.card {
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

/* --------------------------------------------------------------- buttons -- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;          /* comfortable thumb target */
  padding: 12px 22px;
  border: 0;
  border-radius: var(--radius);
  background: var(--green);
  color: #06210f;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--green-dark);
  transition: transform 0.06s ease, box-shadow 0.06s ease, filter 0.15s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.btn:active { transform: translateY(4px); box-shadow: 0 0 0 var(--green-dark); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

.btn.ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 2px solid var(--line);
  box-shadow: 0 4px 0 #0f1727;
}
.btn.ghost:active { box-shadow: 0 0 0 #0f1727; }
.btn.danger { background: var(--red); color: #3d0808; box-shadow: 0 4px 0 var(--red-dark); }
.btn.blue { background: var(--blue); color: #04202e; box-shadow: 0 4px 0 var(--blue-dark); }
.btn.small { min-height: 42px; padding: 8px 16px; font-size: 15px; }
.btn.block { width: 100%; }

/* ------------------------------------------------------------------ form -- */

.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field > span { font-weight: 700; font-size: 15px; }

/* Deny-list, not an allow-list. This used to name the types it styled, so the
   first `type="number"` added to a form rendered as a raw browser box next to
   properly styled neighbours. Only controls whose native rendering we actually
   want are excluded. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]),
select,
textarea {
  width: 100%;
  min-height: 54px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  font-size: 17px;           /* 16px+ stops iOS zooming on focus */
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  appearance: none;
}
input::placeholder, textarea::placeholder { color: #5d6b86; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--blue) 22%, transparent);
}

/* The steppers render as tiny grey arrows that read as an artefact on a dark
   field; the numbers here are typed, not nudged. */
input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* `appearance: none` takes the native arrow with it, so draw one back. */
select {
  padding-inline-end: 42px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' stroke='%238ea0bd' stroke-width='2' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
  cursor: pointer;
}
[dir="rtl"] select { background-position: left 16px center; }

/* --------------------------------------------------------------- banners -- */

.banner {
  padding: 14px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 16px;
  animation: pop 0.25s ease-out;
}
.banner[data-kind="error"] { background: #3a1a1f; border: 2px solid #5c262e; color: #ffb4b4; }
.banner[data-kind="ok"]    { background: #14301a; border: 2px solid #235c2c; color: #b6f0a8; }
.banner[data-kind="warn"]  { background: #33290d; border: 2px solid #5c4a12; color: #ffe08a; }

/* ---------------------------------------------------------------- chips --- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.chip.good { color: var(--green); border-color: #2c5c1c; }
.chip.warn { color: var(--amber); border-color: #5c4a12; }
.chip.bad  { color: var(--red);   border-color: #5c2626; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

/* ----------------------------------------------------------------- bars --- */

.bar {
  height: 14px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 2px solid var(--line);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}

/* --------------------------------------------------------------- motion --- */

@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes ring { 0% { transform: scale(0.9); opacity: 0.65; } 100% { transform: scale(1.3); opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.animate-pop { animation: pop 0.28s cubic-bezier(0.22, 1, 0.36, 1); }
.animate-in { animation: slideIn 0.3s cubic-bezier(0.22, 1, 0.36, 1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ------------------------------------------------------------ breakpoint -- */

@media (min-width: 700px) {
  :root { --pad: 24px; }
  body { font-size: 18px; }
  h1 { font-size: 26px; }
  .card { padding: 22px; }
}
