:root {
  --bg: #f5f7fb; --panel: #ffffff; --panel-2: #eef2f9; --text: #16202e;
  --muted: #5c6b82; --border: #dbe2ee; --accent: #2563eb; --accent-ink: #fff;
  --ok: #15803d; --err: #b91c1c; --shadow: 0 1px 3px rgba(16,32,60,.08), 0 8px 24px rgba(16,32,60,.06);
  --radius: 14px; --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
[data-theme="dark"] {
  --bg: #0b1220; --panel: #131c2e; --panel-2: #0f1728; --text: #e6ecf5;
  --muted: #93a4bf; --border: #24314a; --accent: #4f8cff; --accent-ink: #06101f;
  --ok: #4ade80; --err: #f87171; --shadow: 0 1px 2px rgba(0,0,0,.4), 0 12px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text); font: 15px/1.55 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overflow-wrap: anywhere;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 12px; border-radius: 8px; z-index: 50; }

.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.brand-mark { color: var(--accent); }
.search-wrap { flex: 1; display: flex; }
#search {
  width: 100%; padding: 10px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 15px; outline: none;
}
#search:focus { border-color: var(--accent); }
.icon-btn {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  width: 40px; height: 40px; border-radius: 10px; font-size: 18px; cursor: pointer; flex: none;
}
.icon-btn:hover { border-color: var(--accent); }
#menuBtn { display: none; }

.layout { display: grid; grid-template-columns: 260px 1fr; gap: 0; min-height: calc(100vh - 120px); }
.sidebar {
  border-right: 1px solid var(--border); padding: 14px; position: sticky; top: 61px;
  align-self: start; max-height: calc(100vh - 61px); overflow: auto;
}
.cat-link {
  display: flex; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 10px;
  color: var(--text); cursor: pointer; font-size: 14px;
}
.cat-link:hover { background: var(--panel-2); text-decoration: none; }
.cat-link.active { background: var(--accent); color: var(--accent-ink); }
.cat-link .count { color: var(--muted); font-size: 12px; }
.cat-link.active .count { color: var(--accent-ink); opacity: .8; }

.main { padding: 20px clamp(14px, 3vw, 32px); }
.hero { margin: 4px 0 22px; }
.hero h1 { font-size: clamp(24px, 4vw, 34px); margin: 0 0 6px; }
.hero p { color: var(--muted); margin: 0; max-width: 60ch; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); cursor: pointer; transition: transform .08s, border-color .15s;
  display: flex; flex-direction: column; gap: 4px;
}
.card:hover { transform: translateY(-2px); border-color: var(--accent); text-decoration: none; }
.card h3 { margin: 0; font-size: 15px; color: var(--text); }
.card p { margin: 0; color: var(--muted); font-size: 13px; }
.card .tag { font-size: 11px; color: var(--accent); }

.cat-title { display: flex; align-items: baseline; gap: 10px; margin: 26px 0 12px; }
.cat-title h2 { margin: 0; font-size: 18px; }
.cat-title span { color: var(--muted); font-size: 13px; }

/* Tool page */
.tool { max-width: 820px; }
.tool-head { margin-bottom: 16px; }
.tool-head h1 { margin: 0 0 4px; font-size: 24px; }
.tool-head p { margin: 0; color: var(--muted); }
.crumb { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.field { margin: 12px 0; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.field .hint { color: var(--muted); font-weight: 400; font-size: 12px; }
input[type=text], input[type=number], input[type=url], input[type=password], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--panel); color: var(--text); font-size: 15px; font-family: inherit;
}
textarea { min-height: 130px; resize: vertical; font-family: var(--mono); }
textarea.mono, input.mono { font-family: var(--mono); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 120px; }
.btn {
  background: var(--accent); color: var(--accent-ink); border: none; padding: 10px 16px;
  border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.out {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  white-space: pre-wrap; font-family: var(--mono); font-size: 14px; min-height: 20px;
}
.out.empty { color: var(--muted); }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border); font-size: 12px; color: var(--muted); margin: 2px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }
.note { color: var(--muted); font-size: 13px; margin-top: 8px; }
.ok { color: var(--ok); } .err { color: var(--err); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.swatch { width: 100%; height: 90px; border-radius: 10px; border: 1px solid var(--border); }
.muted { color: var(--muted); }

.footer { border-top: 1px solid var(--border); padding: 20px; text-align: center; color: var(--muted); font-size: 13px; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.footer a { color: var(--muted); }

.backdrop { display: none; }
@media (max-width: 820px) {
  #menuBtn { display: block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; top: 0; left: 0; height: 100%; width: 82%; max-width: 320px;
    background: var(--panel); transform: translateX(-100%); transition: transform .2s; max-height: none;
    padding-top: max(14px, env(safe-area-inset-top));
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.5); }
  .brand span.brand-txt { display: none; }
}
@media (max-width: 480px) {
  .brand { font-size: 0; } .brand-mark { font-size: 20px; }
}

/* Language selector + multilingual fonts */
.lang-sel {
  flex: none; height: 40px; padding: 0 8px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text); font-size: 14px; max-width: 120px;
}
.lang-sel:focus { outline: none; border-color: var(--accent); }
html[lang="si"] body { font-family: "Noto Sans Sinhala", system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
html[lang="ta"] body { font-family: "Noto Sans Tamil", system-ui, -apple-system, Segoe UI, Roboto, sans-serif; }
html[lang="si"] .card h3, html[lang="si"] .cat-link, html[lang="si"] .tool-head h1,
html[lang="ta"] .card h3, html[lang="ta"] .cat-link, html[lang="ta"] .tool-head h1 { line-height: 1.5; }
@media (max-width: 480px) { .lang-sel { max-width: 84px; font-size: 13px; } }

/* Education grade badge + quiz/game UI */
.grade-badge {
  display: inline-block; margin-top: 4px; font-size: 11px; font-weight: 600;
  color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); padding: 2px 8px; border-radius: 999px; align-self: flex-start;
}
.tool-head .grade-badge { margin-top: 8px; }
.quiz-q { font-size: 22px; font-weight: 600; margin: 10px 0; line-height: 1.4; }
.quiz-q .big { font-size: 34px; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 10px; margin: 12px 0; }
.opt {
  padding: 16px 10px; border: 2px solid var(--border); border-radius: 12px; background: var(--panel);
  font-size: 20px; font-weight: 600; cursor: pointer; text-align: center; color: var(--text); transition: transform .06s;
}
.opt:hover { border-color: var(--accent); transform: translateY(-2px); }
.opt.right { border-color: var(--ok); background: color-mix(in srgb, var(--ok) 16%, transparent); }
.opt.wrong { border-color: var(--err); background: color-mix(in srgb, var(--err) 16%, transparent); }
.scoreline { display: flex; gap: 14px; align-items: center; font-size: 14px; color: var(--muted); margin: 6px 0; flex-wrap: wrap; }
.scoreline b { color: var(--text); font-size: 18px; }
.feedback { font-size: 18px; font-weight: 600; min-height: 26px; margin: 6px 0; }
.feedback.ok { color: var(--ok); } .feedback.no { color: var(--err); }
.big-emoji { font-size: 44px; }
.memory-grid { display: grid; gap: 8px; margin: 12px 0; }
.mem-card {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center; font-size: 26px;
  border: 2px solid var(--border); border-radius: 10px; background: var(--panel-2); cursor: pointer; user-select: none;
}
.mem-card.flipped { background: var(--panel); border-color: var(--accent); }
.mem-card.matched { background: color-mix(in srgb, var(--ok) 18%, transparent); border-color: var(--ok); cursor: default; }
.flash-card {
  border: 2px solid var(--border); border-radius: 16px; padding: 30px 20px; text-align: center; cursor: pointer;
  background: var(--panel); min-height: 120px; display: flex; align-items: center; justify-content: center; font-size: 26px; margin: 10px 0;
}
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  padding: 8px 14px; border: 2px solid var(--border); border-radius: 999px; background: var(--panel); cursor: pointer; font-size: 18px;
}
.chip.picked { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* Attribution: site owner, creator credit and partner links.
   Rendered quietly in the footer, and as a panel on the About page. */
.owner, .credit, .partners { margin: 6px 0; }
.owner strong, .credit strong { color: var(--text); font-weight: 600; }

/* --- Footer: compact and muted, must not compete with the tool grid --- */
.footer .owner, .footer .partners { margin: 4px 0; }
.footer .partners a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}
.footer .partners a:hover { border-bottom-color: var(--accent); }

/* --- About page: one grouped panel with an accent edge --- */
.attribution {
  margin: 18px 0;
  padding: 14px 16px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
}
.attribution p { margin: 4px 0; font-size: 14px; color: var(--muted); }
.attribution strong { color: var(--text); font-size: 15px; }
.attribution .partners { margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.attribution .partners a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  color: var(--accent);
  font-weight: 600;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  text-decoration: none;
}
.attribution .partners a:hover { border-color: var(--accent); }

/* Keyboard focus must stay clearly visible in both contexts. */
.footer .partners a:focus-visible,
.attribution .partners a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
