/* Daily K53 — design system. No framework, no build step.
   Everything is driven by the tokens below; change a token, not a component. */

:root {
  color-scheme: light dark;

  /* Brand: indigo, with coral for the one thing on screen we want tapped.
     Green is not a brand colour: it means "correct" and nothing else. */
  --brand-900: #1e1b4b;
  --brand-700: #3730a3;
  --brand-600: #4338ca;
  --brand-500: #6366f1;
  --brand-100: #e0e7ff;
  --brand-050: #eef2ff;
  --accent-500: #ff6b4a;
  --accent-ink: #1e1b4b;
  --ok-600: #15803d;
  --ok-500: #16a34a;
  --ok-100: #dcfce7;

  /* Status hues, validated with the dataviz palette checker rather than chosen
     by eye: the previous red/amber pair sat at deltaE 2.0 under deuteranopia,
     i.e. indistinguishable. Statuses always ship with an icon and a word too. */
  --danger-600: #b21e4b;
  --danger-100: #fde7ee;
  --warn-600:   #c2820a;
  --warn-100:   #fdf3d9;

  --ink:        #1e1b2e;
  --ink-soft:   #45445e;
  --ink-muted:  #6e6d88;
  --line:       #e5e4f2;
  --line-soft:  #efeef8;
  --surface:    #ffffff;
  --surface-2:  #f8f8fd;
  --canvas:     #f1f0fa;

  /* Two shadows only: one for resting cards, one for things that lift. */
  --shadow-sm: 0 1px 2px rgba(30, 27, 75, .05), 0 1px 3px rgba(30, 27, 75, .04);
  --shadow-md: 0 4px 12px rgba(30, 27, 75, .08), 0 2px 4px rgba(30, 27, 75, .04);
  --shadow-lg: 0 18px 40px rgba(30, 27, 75, .14);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-full: 999px;

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --step: 1rem;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --brand-100: #2a2766;
    --brand-050: #1b1940;
    --ok-600: #4ade80;
    --ok-500: #22c55e;
    --ok-100: #14321f;
    --danger-600: #db4a72;
    --danger-100: #3a1a26;
    --warn-600:  #c08a1c;
    --warn-100:  #33280e;
    --ink:       #e8e8f4;
    --ink-soft:  #bdbdd6;
    --ink-muted: #8e8eab;
    --line:      #2a2944;
    --line-soft: #211f38;
    --surface:   #16152a;
    --surface-2: #121124;
    --canvas:    #0c0b1a;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 4px 14px rgba(0,0,0,.45);
    --shadow-lg: 0 18px 40px rgba(0,0,0,.55);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: var(--step);
  line-height: 1.55;
  color: var(--ink);
  background: var(--canvas);
  /* A soft tint behind the app so the chat card has something to sit on,
     instead of white-on-white. */
  background-image:
    radial-gradient(900px 500px at 15% -10%, var(--brand-100), transparent 60%),
    radial-gradient(700px 420px at 105% 0%, var(--brand-050), transparent 55%);
  background-attachment: fixed;
}

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

/* ── App shell ───────────────────────────────────────────────────────────── */
/* On a phone this fills the screen. On a desktop it becomes a centred card
   rather than a stretched phone screen. */
.app {
  flex: 1;
  /* Exactly the screen, so the chat scrolls inside it and the composer stays put. */
  height: 100dvh; max-height: 100dvh;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

@media (min-width: 820px) {
  body { padding: 28px 20px; }
  .app {
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-height: calc(100dvh - 56px);
  }
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 6;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 18px; padding-top: max(12px, env(safe-area-inset-top));
  background: var(--brand-900);
  color: #fff;
}
.mark {
  display: grid; place-items: center; flex: none;
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-500); color: var(--accent-ink);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.22);
  font-weight: 700; font-size: 13px; letter-spacing: .04em;
}
.titles { flex: 1; min-width: 0; }
.topbar h1 { margin: 0; font-size: 16px; font-weight: 640; letter-spacing: -.01em; }
.topbar p  { margin: 0; font-size: 12.5px; color: rgba(255,255,255,.72); }
.topbar a  { color: rgba(255,255,255,.8); font-size: 13px; text-decoration: none; }
.topbar a:hover { color: #fff; text-decoration: underline; }

/* Quiz progress, shown only mid-quiz. */
.progress {
  height: 3px; background: rgba(255,255,255,.16);
  position: sticky; top: 64px; z-index: 6;
}
.progress[hidden] { display: none; }
.progress i {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--brand-500), var(--accent-500));
  transition: width .35s var(--ease);
}

/* ── Banner ──────────────────────────────────────────────────────────────── */
.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 16px;
  background: var(--brand-050); border-bottom: 1px solid var(--line);
  font-size: 14.5px; color: var(--ink-soft);
}
.banner[hidden] { display: none; }
.banner span { flex: 1; }
.banner button {
  padding: 7px 14px; font: inherit; font-size: 13.5px; font-weight: 600;
  border: 0; border-radius: var(--r-full); cursor: pointer;
  background: var(--accent-500); color: var(--accent-ink);
}
/* Three answers do not fit beside the question on a phone, so they wrap below it. */
#followup { flex-wrap: wrap; }
#followup span { flex-basis: 100%; }
#followup button:not(.primary) {
  background: var(--surface); color: var(--ink-soft); border: 1px solid var(--line);
}
.banner #banner-close {
  background: none; color: var(--ink-muted); font-size: 20px; line-height: 1; padding: 0 6px;
}

/* ── Chat ────────────────────────────────────────────────────────────────── */
.chat {
  flex: 1; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 20px 16px 8px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { .chat { scroll-behavior: auto; } }

.msg {
  max-width: 86%;
  animation: rise .22s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .msg { animation: none; } }

/* The learner's own messages: compact, filled, right-aligned. */
.msg.me {
  align-self: flex-end;
  padding: 10px 15px;
  border-radius: var(--r-md) var(--r-md) 4px var(--r-md);
  background: linear-gradient(160deg, var(--brand-600), var(--brand-700));
  color: #fff;
  box-shadow: var(--shadow-sm);
  white-space: pre-wrap; word-wrap: break-word;
}

/* The bot: a surface card, not a bordered rectangle. */
.msg.bot {
  align-self: flex-start;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--r-md) var(--r-md) var(--r-md) 4px;
  box-shadow: var(--shadow-sm);
  padding: 14px 16px;
  white-space: pre-wrap; word-wrap: break-word;
  color: var(--ink-soft);
}
.msg.bot.plain { max-width: 86%; }

/* ── Question card ───────────────────────────────────────────────────────── */
.q-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.chip {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: var(--r-full);
  font-size: 11.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  background: var(--brand-050); color: var(--brand-700);
  border: 1px solid var(--brand-100);
}
.chip.muted { background: var(--surface-2); color: var(--ink-muted); border-color: var(--line); }

.q-text {
  font-size: 18.5px; line-height: 1.4; font-weight: 600; letter-spacing: -.01em;
  color: var(--ink); margin: 0 0 14px;
}
.q-image {
  display: block; width: 132px; height: 132px; margin: 0 auto 14px;
  background: var(--surface-2); border-radius: var(--r-md); padding: 8px;
}

/* Options are the primary control, so they are full-width rows, not letters. */
.options { display: flex; flex-direction: column; gap: 8px; }
.option {
  display: flex; align-items: flex-start; gap: 12px; width: 100%;
  padding: 13px 14px; text-align: left;
  font: inherit; font-size: 15.5px; line-height: 1.4; color: var(--ink);
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--r-md);
  cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease), transform .08s var(--ease);
}
.option:hover { border-color: var(--brand-500); background: var(--brand-050); }
.option:active { transform: translateY(1px); }
.option:focus-visible { outline: 3px solid var(--brand-500); outline-offset: 2px; }
.option:disabled { opacity: .55; cursor: default; }
.option:disabled:hover { border-color: var(--line); background: var(--surface); }
.option:disabled:hover .letter { background: var(--surface-2); border-color: var(--line); color: var(--ink-muted); }
.option .letter {
  flex: none; display: grid; place-items: center;
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13px; font-weight: 700; color: var(--ink-muted);
}
.option:hover .letter { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }

/* ── Feedback ────────────────────────────────────────────────────────────── */
.feedback { border-left: 4px solid var(--line); padding-left: 13px; }
.feedback.ok   { border-color: var(--ok-500); }
.feedback.bad  { border-color: var(--danger-600); }
.fb-head {
  display: flex; align-items: center; gap: 8px;
  font-weight: 650; font-size: 15px; margin-bottom: 4px; color: var(--ink);
}
.fb-dot { width: 20px; height: 20px; flex: none; }
.fb-answer { font-size: 14.5px; color: var(--ink); margin-bottom: 6px; }
.fb-answer b { font-weight: 640; }
.fb-why { font-size: 14.5px; color: var(--ink-muted); margin: 0; }
.fb-report {
  margin-top: 8px; padding: 0; border: 0; background: none;
  font: inherit; font-size: 12.5px; color: var(--ink-muted); text-decoration: underline;
  cursor: pointer;
}
.fb-report:disabled { opacity: .5; cursor: default; }

/* ── Result card ─────────────────────────────────────────────────────────── */
.result { text-align: center; }
.score-ring { position: relative; width: 132px; height: 132px; margin: 4px auto 10px; }
.score-ring svg { transform: rotate(-90deg); display: block; }
.score-ring .track { stroke: var(--line); }
.score-ring .fill  { stroke: var(--ok-500); stroke-linecap: round;
                     transition: stroke-dashoffset .7s var(--ease); }
.score-ring.bad .fill { stroke: var(--danger-600); }
.score-ring .inner {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 0;
}
.score-ring .pct { font-size: 30px; font-weight: 700; letter-spacing: -.02em; color: var(--ink); line-height: 1.1; }
.score-ring .of  { font-size: 12.5px; color: var(--ink-muted); }

.result > .of {
  font-size: 13.5px; color: var(--ink-muted); margin-top: -4px;
}
.verdict { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.verdict.pass { color: var(--ok-600); }
.verdict.fail { color: var(--danger-600); }

.bars { display: flex; flex-direction: column; gap: 9px; margin: 14px 0 4px; text-align: left; }
.bar-row { font-size: 13.5px; color: var(--ink-soft); }
.bar-label { display: flex; justify-content: space-between; margin-bottom: 4px; }
.bar-label b { font-weight: 640; color: var(--ink); }
.bar { height: 7px; border-radius: var(--r-full); background: var(--line-soft); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: var(--r-full);
         background: linear-gradient(90deg, var(--brand-600), var(--brand-500));
         transition: width .6s var(--ease); }
.bar.weak i { background: linear-gradient(90deg, #d97706, #f59e0b); }

.note {
  margin-top: 12px; padding: 10px 12px; border-radius: var(--r-sm);
  background: var(--surface-2); font-size: 13.5px; color: var(--ink-muted); text-align: left;
}
.note.warn { background: var(--warn-100); color: var(--warn-600); }
.note.sponsor { border: 1px dashed var(--line); }

/* ── Typing ──────────────────────────────────────────────────────────────── */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-muted);
            animation: blink 1.3s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); }
                   30% { opacity: 1; transform: translateY(-2px); } }
@media (prefers-reduced-motion: reduce) { .typing i { animation: none; opacity: .5; } }

/* ── Reply buttons ───────────────────────────────────────────────────────── */
/* Capped, and scrolls: the full menu is nine options, and uncapped it pushed the
   composer off the bottom of a phone screen. */
.choices {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 16px 4px;
  flex-shrink: 0; max-height: 42dvh; overflow-y: auto; overscroll-behavior: contain;
}
/* A menu (list options, with descriptions) goes two to a row. */
.choices.list button { flex: 1 1 calc(50% - 4px); min-width: 0; padding: 9px 12px; border-radius: 14px; }
.choices:empty { padding: 0; }
.choices button {
  flex: 1 1 auto; min-width: 96px;
  padding: 11px 16px; font: inherit; font-size: 14.5px; font-weight: 600;
  border-radius: var(--r-full); cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
  transition: transform .08s var(--ease), border-color .15s var(--ease), background .15s var(--ease);
}
.choices button:hover { border-color: var(--brand-500); color: var(--brand-700); background: var(--brand-050); }
.choices button:active { transform: translateY(1px); }
.choices button:focus-visible { outline: 3px solid var(--brand-500); outline-offset: 2px; }
/* The first option is the expected one, so it carries the weight. */
.choices button.primary {
  background: var(--accent-500);
  border-color: transparent; color: var(--accent-ink);
}
.choices button.primary:hover { filter: brightness(1.05); color: var(--accent-ink); background: var(--accent-500); }
.choices button small { display: block; font-weight: 400; font-size: 12px; opacity: .72; margin-top: 1px; }

/* ── Composer ────────────────────────────────────────────────────────────── */
.composer {
  flex-shrink: 0;
  display: flex; gap: 9px; align-items: center;
  padding: 12px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line-soft);
}
.composer input {
  flex: 1; min-width: 0; padding: 12px 16px; font: inherit; font-size: 15.5px;
  color: var(--ink); background: var(--surface-2);
  border: 1.5px solid var(--line); border-radius: var(--r-full);
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.composer input::placeholder { color: var(--ink-muted); }
.composer input:focus { outline: none; border-color: var(--brand-500); background: var(--surface); }
.composer button {
  display: grid; place-items: center; flex: none; width: 46px; height: 46px;
  color: #fff; border: 0; border-radius: 50%; cursor: pointer;
  background: linear-gradient(160deg, var(--brand-600), var(--brand-700));
  box-shadow: var(--shadow-md);
  transition: transform .08s var(--ease), filter .15s var(--ease);
}
.composer button:hover { filter: brightness(1.08); }
.composer button:active { transform: scale(.94); }
.composer button:disabled { opacity: .4; box-shadow: none; cursor: default; }

.noscript { padding: 16px; text-align: center; }

/* ── Document pages (privacy, share, admin) ──────────────────────────────── */
.page { display: block; background: var(--surface); }
.prose { max-width: 680px; margin: 0 auto; padding: 40px 22px 72px; color: var(--ink-soft); }
.prose h1 { font-size: 28px; letter-spacing: -.02em; color: var(--ink); margin: 0 0 6px; }
.prose h2 { font-size: 17px; margin-top: 30px; color: var(--ink); }
.prose code { background: var(--surface-2); border: 1px solid var(--line);
              border-radius: 5px; padding: 1px 6px; font-size: 13.5px; }
.prose a { color: var(--brand-600); }
.muted { color: var(--ink-muted); font-size: 14px; }

/* Indigo text needs lifting to read on the dark surfaces. */
@media (prefers-color-scheme: dark) {
  .chip, .choices button:hover { color: #c7d2fe; }
  .prose a { color: #a5b4fc; }
}

/* A link a message carries: Open WhatsApp, Get Plus. */
.link-btn {
  display: block; width: fit-content; margin-top: 12px; padding: 10px 18px;
  border-radius: var(--r-full); background: var(--accent-500); color: var(--accent-ink);
  font-weight: 650; font-size: 14.5px; text-decoration: none;
}
.link-btn:hover { filter: brightness(1.05); }
