:root {
  --brand: #00612c; --brand-ink: #fff; --brand-soft: #e3efe7; --focus: rgba(0,97,44,.25);
  --ink: #1d2a22; --muted: #5d6b62; --line: #dfe5e0; --panel: #fff; --bg: #f5f7f5;
  --ok: #00612c; --warn: #9a5b00; --bad: #a8261b;
  --ic-ink: #2b3a30; --ic-leaf: #cfe6d4; --ic-petal: #f7d774; --ic-fruit: #d9a066; --ic-wood: #c8a27a; --ic-clear: #dceefa;
  --shadow: 0 2px 10px rgba(0,0,0,.07);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
a { color: var(--brand); }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--brand); color: #fff; padding: 8px 12px; z-index: 99; }
.skip:focus { left: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.pad { padding: 16px; }

/* ---------- header and modes */
header.top { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand img { width: 34px; height: 34px; }
.brand b { display: block; color: var(--brand); font-size: 17px; letter-spacing: .02em; line-height: 1.1; }
.brand small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.hbtn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--ink); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.hbtn:hover { border-color: var(--brand); color: var(--brand); }
.hbtn.pri { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
.hbtn.pri:hover { filter: brightness(1.1); color: var(--brand-ink); }
.hbtn[disabled] { opacity: .45; cursor: default; }
nav.modes { display: flex; gap: 4px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 51px; z-index: 19; scrollbar-width: none; }
nav.modes::-webkit-scrollbar { display: none; }
nav.modes button { border: 0; background: none; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; font-weight: 500; }
nav.modes button[aria-selected="true"] { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
main { max-width: 1240px; margin: 0 auto; padding: 16px; min-height: 60vh; }
main:focus { outline: none; }
h1 { font-size: 22px; margin: 4px 0 6px; }
h2 { font-size: 18px; margin: 18px 0 8px; }
h3 { font-size: 15.5px; margin: 0 0 4px; }
.lede { color: var(--muted); margin: 0 0 14px; max-width: 70ch; }
.foot { max-width: 1240px; margin: 0 auto; padding: 8px 16px 90px; color: var(--muted); font-size: 12.5px; }

/* ---------- icons */
svg.ic { width: 48px; height: 48px; flex: none; color: var(--ic-ink); }
svg.ic .lf { fill: var(--ic-leaf); }
svg.ic .pt { fill: var(--ic-petal); }
svg.ic .pt.pale { fill: #fbeec0; }
svg.ic .lf.pale { fill: #e6f1e8; }
svg.ic .fr { fill: var(--ic-fruit); }
svg.ic .wd { fill: var(--ic-wood); }
svg.ic .wh { fill: #fff; }
svg.ic .cl { fill: var(--ic-clear); }
svg.ic.sm { width: 30px; height: 30px; }
svg.ic.lg { width: 72px; height: 72px; }

/* ---------- multi-access */
.multi { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.focusbar { grid-column: 1 / -1; background: #fff8e1; border: 1px solid #f0d58a; border-radius: 10px; padding: 10px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.focusbar b { font-weight: 650; }
.chargroup h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
.char { min-width: 0; margin: 0 0 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin-bottom: 10px; }
.char.answered { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand) inset; }
.char.hint { box-shadow: 0 0 0 3px #f2c94c; }
.char .chead { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.char .chead h3 { margin: 0; }
.char .chead .q { color: var(--muted); font-size: 13.5px; flex: 1 1 220px; }
.char .tag { font-size: 11.5px; font-weight: 650; color: #7a5600; background: #fff1c2; border-radius: 999px; padding: 1px 8px; }
.states { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.st { display: flex; flex-direction: column; align-items: center; gap: 3px; width: 92px; min-height: 92px; padding: 6px 4px 7px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--panel); cursor: pointer; text-align: center; font-size: 12.5px; line-height: 1.2; position: relative; }
.st:hover { border-color: var(--brand); }
.st[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); font-weight: 650; }
.st[aria-pressed="true"]::after { content: "✓"; position: absolute; top: 3px; right: 6px; color: var(--brand); font-weight: 800; }
.st.dk { justify-content: center; color: var(--muted); border-style: dashed; }
.st.dk[aria-pressed="true"] { background: #f2f4f2; border-color: var(--muted); color: var(--ink); }
.st.dk[aria-pressed="true"]::after { content: ""; }
.st .n { font-size: 11px; color: var(--muted); font-weight: 400; }
details.defs { margin-top: 8px; font-size: 13px; }
details.defs summary { cursor: pointer; color: var(--brand); }
details.defs dl { margin: 6px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 3px 10px; }
details.defs dt { font-weight: 600; }
details.defs dd { margin: 0; color: var(--muted); }
.side { position: sticky; top: 108px; display: flex; flex-direction: column; gap: 12px; max-height: calc(100vh - 120px); overflow: auto; padding-bottom: 6px; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.box h2 { margin: 0 0 8px; font-size: 15.5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 9px; font-size: 12.5px; cursor: pointer; }
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); }
.chip .x { color: var(--muted); font-weight: 700; }
.next button { display: flex; width: 100%; text-align: left; gap: 8px; align-items: center; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); padding: 7px 9px; margin-bottom: 6px; cursor: pointer; }
.next button:hover { border-color: var(--brand); }
.next button b { font-weight: 600; }
.next button small { color: var(--muted); display: block; }
.next .meter { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
ol.res { list-style: none; margin: 0; padding: 0; }
ol.res li { border-top: 1px solid var(--line); }
ol.res li:first-child { border-top: 0; }
ol.res a { display: flex; align-items: center; gap: 8px; padding: 8px 4px; text-decoration: none; color: var(--ink); }
ol.res a:hover { background: var(--brand-soft); }
ol.res .nm { flex: 1; min-width: 0; }
ol.res .nm b { display: block; }
ol.res .nm small { color: var(--muted); }
ol.res li.focus a { background: #fff8e1; }
.pill { font-size: 11.5px; border-radius: 999px; padding: 2px 8px; white-space: nowrap; font-weight: 600; }
.pill.ok { background: var(--brand-soft); color: var(--ok); }
.pill.mid { background: #fff1d6; color: var(--warn); }
.pill.no { background: #fbe4e1; color: var(--bad); }
.score { font-size: 12px; color: var(--muted); white-space: nowrap; }
details.out summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 6px 0; }
.mbar { display: none; }

/* ---------- classic key */
.classic { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.couplet { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.couplet .num { font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.lead { display: flex; gap: 12px; width: 100%; text-align: left; border: 1.5px solid var(--line); background: var(--panel); border-radius: 10px; padding: 12px; margin-top: 10px; cursor: pointer; align-items: flex-start; }
.lead:hover { border-color: var(--brand); background: #fafdfb; }
.lead .lab { font-weight: 800; color: var(--brand); min-width: 2.4em; font-size: 16px; }
.lead .txt { flex: 1; }
.lead .go { color: var(--muted); font-size: 13px; white-space: nowrap; }
.lead.wrong { border-color: var(--bad); background: #fdf3f2; }
.lead.right { border-color: var(--ok); background: var(--brand-soft); }
.crumbs { list-style: none; margin: 0; padding: 0; counter-reset: c; }
.crumbs li { display: flex; gap: 8px; align-items: baseline; padding: 6px 0; border-top: 1px solid var(--line); font-size: 13.5px; }
.crumbs li:first-child { border-top: 0; }
.crumbs button { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 0; font-weight: 700; min-width: 2.6em; text-align: left; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.result { border: 2px solid var(--brand); border-radius: 12px; background: var(--panel); padding: 14px; }
.result h2 { margin: 0 0 4px; }
.fullkey { font-size: 13.5px; }
.fullkey p { margin: 5px 0; padding-left: 3.2em; text-indent: -3.2em; }
.fullkey b { color: var(--brand); }
.fullkey .dots { color: var(--muted); }

/* ---------- families and cards */
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.fcard { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; text-decoration: none; color: var(--ink); }
.fcard:hover { border-color: var(--brand); }
.fcard b { display: block; }
.fcard small { color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.card .ctop { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.card .ctop .t { flex: 1 1 260px; }
.card h1 { margin: 0; }
.badge { display: inline-block; font-size: 12px; border-radius: 999px; padding: 2px 9px; background: var(--brand-soft); color: var(--brand); font-weight: 600; margin-top: 4px; }
.cgrid { display: grid; grid-template-columns: 1.1fr 1fr; gap: 22px; margin-top: 8px; }
.card ul { padding-left: 1.2em; margin: 6px 0; }
.card li { margin: 4px 0; }
.ex li i { font-style: italic; }
.profile { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.prof { border: 1px solid var(--line); border-radius: 10px; padding: 7px 8px; font-size: 12.5px; }
.prof .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.prof .v { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-top: 3px; }
.prof .v span { display: inline-flex; align-items: center; gap: 3px; }
.prof.flag { border-style: dashed; }
.cite { font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 16px; padding-top: 10px; }
.note { background: #f3f7f4; border-left: 3px solid var(--brand); padding: 8px 10px; border-radius: 0 8px 8px 0; font-size: 13.5px; margin: 8px 0; }
.warnbox { background: #fff8e1; border-left: 3px solid #d9a400; padding: 10px 12px; border-radius: 0 8px 8px 0; margin: 0 0 12px; }

/* ---------- glossary */
.gsearch { width: 100%; max-width: 420px; font: inherit; font-size: 16px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.gsearch:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px var(--focus); }
.gloss { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.term { display: flex; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; align-items: flex-start; }
.term b { display: block; }
.term .c { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.term p { margin: 2px 0 0; font-size: 13.5px; color: var(--ink); }

/* ---------- quiz */
.quiz { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; }
.prompt { background: #fffdf3; border: 1px solid #efe2b0; border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.prompt ul { margin: 6px 0 0; padding-left: 1.2em; }
.fb { border-radius: 10px; padding: 10px 12px; margin-top: 10px; font-size: 14px; }
.fb.bad { background: #fdf0ee; border: 1px solid #f1c3bd; }
.fb.good { background: var(--brand-soft); border: 1px solid #b6d6c0; }
.qscore { font-size: 28px; font-weight: 750; color: var(--brand); }

/* ---------- phones */
@media (max-width: 900px) {
  .multi, .classic, .quiz { grid-template-columns: 1fr; }
  .side { position: static; max-height: none; overflow: visible; }
  .cgrid { grid-template-columns: 1fr; }
  .mbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--panel); border-top: 1px solid var(--line);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); gap: 10px; align-items: center; box-shadow: 0 -4px 14px rgba(0,0,0,.08); }
  .mbar .t { flex: 1; min-width: 0; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
@media (max-width: 520px) {
  main { padding: 12px; }
  header.top { padding: 6px 12px; }
  nav.modes { top: 47px; padding: 5px 8px; }
  nav.modes button { padding: 7px 10px; font-size: 14px; }
  h1 { font-size: 20px; }
  .st { width: calc((100% - 24px) / 4); min-width: 0; min-height: 86px; font-size: 11.5px; }
  svg.ic { width: 40px; height: 40px; }
  .card { padding: 14px; }
  .lead { padding: 10px; }
  .gloss { grid-template-columns: 1fr; }
}
@media print {
  header.top, nav.modes, .mbar, .side, .foot { display: none; }
  body { background: #fff; }
}

/* location filter */
.locbar{display:flex;flex-wrap:wrap;gap:8px 12px;align-items:center;justify-content:space-between;margin:0 0 14px;padding:10px 12px;border:1px solid var(--line,#d9e2d6);border-radius:10px;background:var(--panel,#f4f8f2);font-size:14px}
.locbar span{flex:1 1 260px;min-width:0}
.res li.away{opacity:.75}

/* iPhone app 1.1+ (html.edge, edge to edge): keep the sticky header and mode tabs below the status bar */
.edge header.top { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
.edge nav.modes { top: calc(51px + env(safe-area-inset-top, 0px)); }
@media (max-width: 520px) {
  .edge header.top { padding-top: calc(6px + env(safe-area-inset-top, 0px)); }
  .edge nav.modes { top: calc(47px + env(safe-area-inset-top, 0px)); }
}
