:root {
  --bg: #fffaf0;
  --card: #ffffff;
  --fg: #2b2622;
  --muted: #6b6159;
  --accent: #d9480f;
  --accent-ink: #ffffff;
  --me: #d9480f;
  --me-ink: #ffffff;
  --good: #2b8a3e;
  --bad: #c92a2a;
  --rule: #efdcbc;
  --idly: #fffdf7;
  --idly-edge: #e0a43a;
  --kofi: #ff5e5b;
  --max: 44rem;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --card: #2c2722;
    --fg: #f3ede4;
    --muted: #bdb2a6;
    --accent: #ff8a4c;
    --accent-ink: #1b1916;
    --me: #ff8a4c;
    --me-ink: #1b1916;
    --good: #69db7c;
    --bad: #ff8787;
    --rule: #3d362e;
    --idly: #f6efe2;
  }
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

a { color: var(--accent); }
.wrap { width: 100%; max-width: var(--max); margin: 0 auto; padding: 0 16px; }
.gc-pixel { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

/* Header */
.site-header { position: sticky; top: 0; z-index: 5; background: var(--bg); border-bottom: 1px solid var(--rule); }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding-top: 0.55rem; padding-bottom: 0.55rem; }
.brand { margin: 0; display: flex; align-items: center; gap: 0.55rem; font-weight: 800; font-size: 1.2rem; line-height: 1.1; }
.brand small { display: block; font-weight: 500; font-size: 0.78rem; color: var(--muted); }
.brand .sub-short { display: none; }
.header-actions { display: flex; align-items: center; gap: 0.5rem; flex: none; }

/* The tiffin gang: pure-CSS faces (no images). Each sets its body, edge and accent colour. */
.face {
  --body: #fffdf7; --edge: #e0a43a;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3em;
  width: 2em; height: 1.4em; border-radius: 50%;
  background: var(--body); border: 0.13em solid var(--edge);
  font-size: 1rem; flex: none;
}
.face span { width: 0.22em; height: 0.22em; border-radius: 50%; background: #2b2622; }
/* Idly: soft, round rice cake */
.face-idly { --body: #fffdf7; --edge: #e0a43a; }
/* Dosa: long, thin, golden crepe */
.face-dosa { --body: #f4c66d; --edge: #b7791f; width: 2.6em; height: 1.05em; border-radius: 999px; transform: rotate(-6deg); }
/* Poori: puffed-up golden ball */
.face-poori { --body: #f7c35f; --edge: #c06a12; width: 1.75em; height: 1.75em; box-shadow: inset 0 -0.22em 0 rgba(0, 0, 0, 0.1); }
/* Vada: a doughnut with a hole, eyes above it */
.face-vada {
  --body: #c98a3d; --edge: #8a5a1f; width: 1.8em; height: 1.8em; align-items: flex-start; padding-top: 0.32em;
  background: radial-gradient(circle at 50% 66%, var(--bg) 0 0.2em, var(--body) 0.23em);
}
/* Pongal: a cosy bowl */
.face-pongal { --body: #fff1b8; --edge: #d4a017; width: 2em; height: 1.3em; border-radius: 0.3em 0.3em 1.1em 1.1em; }

.who-idly { --c: #c77d0e; }
.who-dosa { --c: #a5651a; }
.who-poori { --c: #c2410c; }
.who-vada { --c: #7c4a14; }
.who-pongal { --c: #a17a00; }
@media (prefers-color-scheme: dark) {
  .who-idly { --c: #f2b94b; }
  .who-dosa { --c: #f4c66d; }
  .who-poori { --c: #ff9a5c; }
  .who-vada { --c: #e0a865; }
  .who-pongal { --c: #f3d36b; }
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; border: 0; cursor: pointer;
  font: inherit; font-weight: 700; background: var(--accent); color: var(--accent-ink);
  padding: 0.6em 1.2em; border-radius: 999px; min-height: 44px; text-decoration: none;
}
.btn.ghost { background: transparent; color: var(--accent); border: 2px solid var(--accent); }
.btn.small { font-size: 0.9rem; padding: 0.3em 0.9em; min-height: 36px; }

.kofi {
  display: inline-flex; align-items: center; gap: 0.35em; background: var(--kofi); color: #fff;
  font-weight: 700; text-decoration: none; padding: 0.55em 1.1em; border-radius: 999px; min-height: 44px;
}
.kofi-small { font-size: 0.9rem; padding: 0.3em 0.85em; min-height: 36px; }

/* Chat log */
.chat { flex: 1; padding-top: 1rem; padding-bottom: 1rem; }
.log { display: flex; flex-direction: column; gap: 0.5rem; }
.msg { display: flex; align-items: flex-start; gap: 0.5rem; max-width: 100%; animation: rise 0.25s ease-out; }
.msg .bubble { padding: 0.6rem 0.95rem; border-radius: 1.2rem; overflow-wrap: anywhere; }
.msg.bot .stack { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; max-width: 85%; }
.msg.bot .bubble { background: var(--card); border: 1px solid var(--rule); border-left: 4px solid var(--c, var(--rule)); border-top-left-radius: 0.35rem; max-width: 100%; }
.msg.bot .who-name { font-size: 0.78rem; font-weight: 800; color: var(--c, var(--muted)); margin: 0 0 0.15rem 0.3rem; letter-spacing: 0.02em; }
.msg.me { justify-content: flex-end; margin: 0.4rem 0; }
.msg.me .bubble { background: var(--me); color: var(--me-ink); font-weight: 600; border-bottom-right-radius: 0.35rem; max-width: 85%; }
.msg.wide .stack { flex: 1; max-width: 100%; }
.msg.wide .bubble { width: 100%; padding: 0.9rem 1rem; }
.msg .avatar { font-size: 0.85rem; margin-top: 1.1rem; }
/* Consecutive messages from the same friend: one face and one name tag per run. */
.msg.cont { margin-top: -0.25rem; }
.msg.cont .avatar { visibility: hidden; height: 0; margin-top: 0; }
.msg.cont .who-name { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.bubble-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 0.5rem; }

.dots { display: inline-flex; gap: 0.25rem; padding: 0.2rem 0; }
.dots i { width: 0.45rem; height: 0.45rem; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; }
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
@keyframes blink { 50% { opacity: 0.25; } }
@keyframes pop { 40% { transform: scale(1.05); } }

/* Reply chips, pinned to the bottom like a chat composer */
.replies-bar {
  position: sticky; bottom: 0; z-index: 5; background: var(--bg); border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.replies { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.5rem; padding-top: 0.7rem; padding-bottom: 0.8rem; min-height: 3.6rem; }
.chip {
  font: inherit; font-weight: 700; cursor: pointer; border-radius: 999px; min-height: 44px;
  padding: 0.45em 1em; background: var(--card); color: var(--accent); border: 2px solid var(--accent);
}
.chip:hover { background: var(--accent); color: var(--accent-ink); }

/* Game widgets */
.widget h3 { font-size: 1.05rem; margin: 0.2rem 0 0.5rem; }
.widget h3 + .hint { margin-top: -0.3rem; }
.hint { color: var(--muted); font-size: 0.92rem; margin: 0 0 0.6rem; }

.train { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: 0.45rem; }
.train li { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.who { font-size: 1.6rem; width: 2rem; text-align: center; }
.train .name { flex: 1; min-width: 4rem; font-weight: 600; }
.pick { display: flex; gap: 0.35rem; }
.pick button, .test-row button, .choices button {
  font: inherit; cursor: pointer; border-radius: 999px; border: 2px solid var(--rule);
  background: var(--bg); color: var(--fg); padding: 0.3em 0.8em; min-height: 40px;
}
.pick button[aria-pressed="true"].yes { background: var(--good); border-color: var(--good); color: #fff; }
.pick button[aria-pressed="true"].no { background: var(--bad); border-color: var(--bad); color: #fff; }

.test-row { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.test-row button { display: inline-flex; align-items: center; gap: 0.25rem; }
.test-row .who { font-size: 1.35rem; width: auto; }
.test-row button[aria-pressed="true"] { border-color: var(--accent); }

.bot-line { margin: 0.8rem 0; padding: 0.6rem 0.8rem; background: var(--bg); border-radius: 12px; font-weight: 700; }
.bot-line.pop { animation: pop 0.35s ease-out; }

.peek { margin: 0.6rem 0 0.8rem; }
.peek summary { cursor: pointer; font-weight: 700; color: var(--accent); }
.brain { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.3rem; font-size: 0.92rem; }
.brain li { display: grid; grid-template-columns: 7rem 1fr; align-items: center; gap: 0.5rem; }
.brain .legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem; }
.meter { position: relative; height: 0.7rem; background: var(--rule); border-radius: 999px; }
.meter span { position: absolute; top: 0; bottom: 0; border-radius: 999px; }
.meter .pos { left: 50%; background: var(--good); }
.meter .neg { right: 50%; background: var(--bad); }
.meter::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; background: var(--muted); }

.sentence { font-size: clamp(1.3rem, 5vw, 1.7rem); font-weight: 800; margin: 0 0 0.4rem; min-height: 1.5em; }
.sentence .new { color: var(--accent); }
.choices { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.8rem; }
.choices button { font-size: 1.05rem; }
.stars { font-size: 0.75rem; margin-left: 0.3rem; }
.book { font-style: italic; color: var(--muted); margin: 0.5rem 0 0; }

.row-buttons { display: flex; flex-wrap: wrap; gap: 0.45rem; margin: 0.6rem 0; }
.btn:disabled { opacity: 0.45; cursor: default; }

/* Fair or unfair */
.seen { list-style: none; margin: 0 0 0.4rem; padding: 0; display: grid; gap: 0.35rem; }
.seen li { display: flex; align-items: center; gap: 0.5rem; }
.seen .name { flex: 1; font-weight: 600; }
.seen .tag { font-size: 0.8rem; font-weight: 700; border-radius: 999px; padding: 0.1em 0.65em; }
.seen .is-cat .tag { background: var(--good); color: #fff; }
.seen .not-cat .tag { background: var(--bad); color: #fff; }

/* How Idly sees pictures */
.pixels { display: grid; grid-template-columns: repeat(8, 1fr); gap: 3px; width: 100%; max-width: 19rem; margin: 0.3rem 0 0.4rem; }
.px {
  aspect-ratio: 1; min-width: 0; padding: 0; border: 1px solid var(--rule); border-radius: 5px; cursor: pointer;
  background: var(--bg); color: var(--muted); font: inherit; font-size: 0.85rem; font-weight: 700;
}
.px.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pixels.numbers .px { background: var(--bg); color: var(--muted); border-color: var(--rule); }
.pixels.numbers .px.on { color: var(--accent); border-color: var(--accent); }

.noscript { background: var(--card); border: 1px solid var(--rule); border-radius: 14px; padding: 1rem; }

@media (max-width: 30rem) {
  .brand .sub-long { display: none; }
  .brand .sub-short { display: inline; }
  .msg .bubble { max-width: 90%; }
  .replies { gap: 0.4rem; padding-top: 0.55rem; padding-bottom: 0.6rem; }
  .chip { font-size: 0.95rem; padding: 0.35em 0.85em; min-height: 40px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; scroll-behavior: auto !important; }
}

/* Lessons page (site/index.html): no JavaScript. */
a.brand { color: var(--fg); text-decoration: none; }
.hub { padding-top: 1.5rem; padding-bottom: 2.5rem; }
.hub h1 { margin: 0 0 0.4rem; font-size: 1.7rem; }
.hub-lead { margin: 0 0 1.25rem; color: var(--muted); }
.lessons { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 0.85rem; }
.lessons > li { display: flex; }
.lesson { flex: 1; display: flex; flex-direction: column; gap: 0.35rem; padding: 1rem 1.1rem; background: var(--card); border: 2px solid var(--rule); border-radius: 16px; color: var(--fg); text-decoration: none; }
a.lesson { border-color: var(--idly-edge); }
a.lesson:hover { border-color: var(--accent); }
.lesson-num { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.lesson-name { display: flex; align-items: center; gap: 0.5rem; font-size: 1.35rem; font-weight: 800; }
.lesson-desc { color: var(--muted); font-size: 0.95rem; line-height: 1.45; flex: 1; }
.lesson-go { font-weight: 700; color: var(--accent); }
.lesson.soon { border-style: dashed; }
.lesson.soon .lesson-name, .lesson.soon .lesson-go { color: var(--muted); }
.hub-note { margin: 1.5rem 0 0; font-size: 0.9rem; color: var(--muted); }
