/* Pole Pole — paper chart of the Swahili coast.
   Local/system fonts only. No external assets. */

:root {
  --paper: #f4ecdc;
  --paper-2: #ebdfc6;
  --paper-3: #e2d2b2;
  --card: #fbf6ea;
  --ink: #1f2a44;
  --ink-soft: #46506a;
  --ink-faint: #6b6f7d;
  --sea: #2f6f7a;
  --sea-deep: #24555e;
  --sea-light: #b9dbd3;
  --sea-wash: #d7e9e1;
  --sun: #e9a23b;
  --sun-soft: #f6d79a;
  --coral: #c2513a;
  --coral-deep: #9e3d2a;
  --leaf: #4f7a35;
  --leaf-soft: #dce8c9;
  --berry: #8a3a52;
  --sand: #e8d3a6;

  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: ui-rounded, "SF Pro Rounded", "Avenir Next", Avenir, "Segoe UI", "Helvetica Neue", system-ui, sans-serif;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 0 rgba(31, 42, 68, .08), 0 10px 24px -14px rgba(31, 42, 68, .35);
  --shadow-lift: 0 2px 0 rgba(31, 42, 68, .12), 0 18px 34px -16px rgba(31, 42, 68, .45);
  --focus: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t: 220ms;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  background-color: var(--paper);
  background-image:
    radial-gradient(ellipse at 15% -10%, rgba(233, 162, 59, .18), transparent 55%),
    radial-gradient(ellipse at 110% 30%, rgba(47, 111, 122, .12), transparent 50%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .15 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-attachment: fixed;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--sea-deep); text-underline-offset: 3px; }
a:hover { color: var(--coral-deep); }

:focus { outline: none; }
:focus-visible { box-shadow: var(--focus); border-radius: 10px; }
/* Headings receive programmatic focus on screen changes (for screen readers); no ring needed. */
h1[tabindex="-1"]:focus, h2[tabindex="-1"]:focus { box-shadow: none; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.12; letter-spacing: -.01em; margin: 0 0 .4em; }
h1 { font-size: clamp(1.9rem, 4vw + 1rem, 3rem); }
h2 { font-size: clamp(1.4rem, 2vw + 1rem, 2rem); }
h3 { font-size: 1.2rem; }
p { margin: 0 0 .8em; }

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

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 50;
  background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px;
  text-decoration: none; transition: top var(--t);
}
.skip-link:focus { top: 12px; color: var(--paper); }

.sw { font-family: var(--serif); font-style: italic; }
.en { font-family: var(--sans); }
.muted { color: var(--ink-soft); }
.small { font-size: .88rem; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 1180px; margin: 0 auto; padding: 14px clamp(14px, 3vw, 28px) 6px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  border: 0; background: none; padding: 6px 8px 6px 4px; color: var(--ink);
  border-radius: 12px;
}
.brand-mark { display: inline-grid; color: var(--ink); }
.brand-word { font-family: var(--serif); font-style: italic; font-weight: 700; font-size: 1.55rem; letter-spacing: -.02em; }
.topnav { display: flex; gap: 6px; }
.navbtn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid rgba(31, 42, 68, .18); background: rgba(251, 246, 234, .7);
  padding: 7px 12px; border-radius: 999px; font-size: .92rem; font-weight: 600;
  transition: background var(--t), border-color var(--t), transform var(--t) var(--ease);
}
.navbtn:hover { background: var(--card); border-color: var(--ink); }
.navicon { font-family: var(--serif); font-size: 1rem; line-height: 1; }
@media (max-width: 460px) {
  .navlabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .navbtn { width: 40px; height: 40px; justify-content: center; padding: 0; }
  .brand-word { font-size: 1.35rem; }
}

.banner {
  max-width: 1120px; margin: 6px auto 0; padding: 10px 16px;
  background: var(--sun-soft); border: 1.5px dashed var(--sun); border-radius: var(--radius-sm);
  font-size: .92rem; width: calc(100% - 28px);
}

main { display: block; max-width: 1180px; margin: 0 auto; padding: 8px clamp(14px, 3vw, 28px) 48px; }
main:focus { box-shadow: none; }

.noscript { max-width: 640px; margin: 40px auto; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 20px; border-radius: 999px;
  border: 2px solid var(--ink); background: var(--card); color: var(--ink);
  font-weight: 700; font-size: 1rem; text-decoration: none;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease), background var(--t);
}
.btn:hover { background: #fff; }
.btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:focus-visible { box-shadow: 0 3px 0 var(--ink), var(--focus); border-radius: 999px; }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:hover { background: #2b3a5e; }
.btn-coral { background: var(--coral); border-color: var(--coral-deep); color: #fff; box-shadow: 0 3px 0 var(--coral-deep); }
.btn-coral:hover { background: #cf5d45; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; text-decoration: underline; text-underline-offset: 4px; font-weight: 600; }
.btn-ghost:hover { background: rgba(31, 42, 68, .06); }
.btn-ghost:active { transform: none; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; transform: none; box-shadow: 0 3px 0 var(--ink); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.btn-block { width: 100%; }

/* ---------- home / chart ---------- */
.home {
  display: grid; gap: clamp(18px, 3vw, 36px);
  grid-template-columns: 1fr;
  align-items: start;
}
@media (min-width: 900px) {
  .home { grid-template-columns: minmax(320px, 1fr) minmax(380px, 470px); }
  .home .panel { position: sticky; top: 16px; }
}

.panel { display: grid; gap: 18px; }
.hello { padding-top: 6px; }
.eyebrow {
  display: inline-block; font-size: .78rem; letter-spacing: .14em; text-transform: uppercase;
  font-weight: 700; color: var(--coral-deep); margin-bottom: 6px;
}
.hello h1 .sw { color: var(--coral); }
.hello p { max-width: 36em; color: var(--ink-soft); }

.next-card {
  position: relative; overflow: hidden;
  background: var(--card); border-radius: var(--radius); padding: 22px 22px 20px;
  box-shadow: var(--shadow); border: 1.5px solid rgba(31, 42, 68, .1);
}
.next-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 10px;
  background: repeating-linear-gradient(90deg, var(--c1, var(--coral)) 0 14px, var(--c2, var(--sun)) 14px 28px);
}
.next-card .port-line { font-size: .82rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; color: var(--ink-soft); margin-top: 6px; }
.next-card h2 { margin-top: 4px; }
.next-card h2 .sw { color: var(--c1, var(--coral)); }
.next-card .btn-row { margin-top: 14px; }

.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
}
.stat {
  background: rgba(251, 246, 234, .65); border: 1.5px dashed rgba(31, 42, 68, .2);
  border-radius: var(--radius-sm); padding: 10px 12px; text-align: center;
}
.stat b { display: block; font-family: var(--serif); font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--ink-soft); }

.side-actions { display: grid; gap: 10px; }
.side-actions .btn { justify-content: flex-start; }

.chart-wrap {
  position: relative;
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1.5px solid rgba(31, 42, 68, .12);
  padding: 12px;
}
.chart-title {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 4px 6px 10px; border-bottom: 1.5px dashed rgba(31, 42, 68, .18); margin-bottom: 10px;
}
.chart-title h2 { font-size: 1.15rem; margin: 0; }
.chart-title span { font-size: .82rem; color: var(--ink-soft); }
.chart {
  position: relative; width: 100%; aspect-ratio: 400 / 760;
  border-radius: 12px; overflow: hidden;
}
.chart svg.chart-art { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ports { list-style: none; margin: 0; padding: 0; }
.port {
  position: absolute; transform: translate(-50%, -50%);
}
.port-btn {
  position: relative; display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  border: 2.5px solid var(--ink); background: var(--card);
  font-family: var(--serif); font-weight: 700; font-size: 1rem;
  box-shadow: 0 2px 0 var(--ink);
  transition: transform var(--t) var(--ease), background var(--t);
}
.port-btn:hover { transform: scale(1.08); }
.port-btn:focus-visible { box-shadow: 0 2px 0 var(--ink), var(--focus); border-radius: 50%; }
.port[data-state="done"] .port-btn { background: var(--sun); }
.port[data-state="next"] .port-btn { background: var(--coral); color: #fff; border-color: var(--coral-deep); box-shadow: 0 2px 0 var(--coral-deep); }
.port[data-state="locked"] .port-btn { background: var(--paper-2); color: var(--ink-faint); border-style: dashed; box-shadow: none; }
.port[data-state="next"] .port-btn::after {
  content: ""; position: absolute; inset: -9px; border-radius: 50%;
  border: 2px solid var(--coral); opacity: .6; animation: ping 2.4s var(--ease) infinite;
}
.port-label {
  position: absolute; top: 50%; transform: translateY(-50%);
  white-space: nowrap; pointer-events: none;
  font-size: .78rem; line-height: 1.15; color: var(--ink);
  background: rgba(251, 246, 234, .85); padding: 3px 7px; border-radius: 8px;
}
.port-label b { display: block; font-family: var(--serif); font-size: .95rem; }
.port-label i { font-family: var(--serif); color: var(--ink-soft); }
.port[data-side="left"] .port-label { right: calc(100% + 6px); text-align: right; }
.port[data-side="right"] .port-label { left: calc(100% + 6px); }
.port[data-state="locked"] .port-label { opacity: .7; }
.port .tick { position: absolute; right: -6px; top: -6px; width: 18px; height: 18px; border-radius: 50%; background: var(--leaf); color: #fff; font-size: 11px; display: grid; place-items: center; border: 2px solid var(--card); }

.dhow { position: absolute; width: 13%; transform: translate(-30%, -105%); pointer-events: none; transition: left 900ms var(--ease), top 900ms var(--ease); }
.dhow svg { width: 100%; height: auto; display: block; animation: bob 3.2s ease-in-out infinite; transform-origin: 50% 90%; }

@keyframes ping { 0% { transform: scale(.85); opacity: .7; } 70%, 100% { transform: scale(1.35); opacity: 0; } }
@keyframes bob { 0%, 100% { transform: rotate(-3deg) translateY(0); } 50% { transform: rotate(3deg) translateY(-3px); } }
@keyframes wave-shift { from { transform: translateX(0); } to { transform: translateX(-40px); } }

/* ---------- lesson stage ---------- */
.stage { max-width: 760px; margin: 0 auto; }
.stage-head {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  margin: 4px 0 18px;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  border: 2px solid rgba(31, 42, 68, .25); background: var(--card); font-size: 1.3rem; line-height: 1;
}
.icon-btn:hover { border-color: var(--ink); }
.icon-btn:focus-visible { border-radius: 50%; }
.stage-title { font-size: .85rem; color: var(--ink-soft); text-align: right; }
.stage-title b { color: var(--ink); font-family: var(--serif); font-size: 1rem; }

.progress { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; }
.progress .dot {
  flex: 1 1 0; min-width: 8px; max-width: 46px; height: 10px; border-radius: 6px;
  background: var(--paper-3); position: relative; overflow: hidden;
}
.progress .dot.done { background: var(--sea); }
.progress .dot.miss { background: var(--sun); }
.progress .dot.current { background: var(--ink); }
.progress .dot.extra { background: repeating-linear-gradient(45deg, var(--paper-3) 0 4px, var(--sand) 4px 8px); }
.progress .dot.extra.done { background: var(--sea); }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1.5px solid rgba(31, 42, 68, .1);
  padding: clamp(18px, 4vw, 30px);
  position: relative;
}
.card + .card { margin-top: 16px; }

.kind {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .76rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--sea-deep); background: var(--sea-wash); padding: 4px 10px; border-radius: 999px; margin-bottom: 12px;
}
.kind.k-learn { color: var(--coral-deep); background: #f6dfd4; }
.prompt { font-size: clamp(1.15rem, 1vw + 1rem, 1.4rem); font-weight: 650; margin-bottom: 12px; }
.prompt-sw {
  display: block; font-family: var(--serif); font-style: italic; font-weight: 600;
  font-size: clamp(2rem, 4vw + 1rem, 3rem); color: var(--ink); margin: 6px 0 14px; line-height: 1.1;
}

/* intro */
.intro-hero { display: grid; gap: 16px; }
.intro-hero .port-line { font-size: .82rem; letter-spacing: .14em; text-transform: uppercase; font-weight: 700; color: var(--ink-soft); }
.intro-hero h1 .sw { color: var(--c1, var(--coral)); }
.learn-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.learn-list li { font-family: var(--serif); font-style: italic; background: var(--paper-2); padding: 4px 12px; border-radius: 999px; font-size: 1.02rem; }

/* teach cards */
.teach h2 { font-size: clamp(1.4rem, 2vw + .9rem, 1.9rem); }
.phrases { list-style: none; padding: 0; margin: 10px 0 14px; display: grid; gap: 8px; }
.phrase {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--paper);
  border-left: 5px solid var(--c1, var(--coral));
}
.phrase .sw { font-size: clamp(1.25rem, 1vw + 1rem, 1.55rem); font-weight: 600; }
.phrase .en { grid-column: 1; color: var(--ink-soft); font-size: .95rem; }
.phrase .say { grid-row: 1 / span 2; grid-column: 2; }
.register {
  display: inline-flex; gap: 6px; align-items: center; font-size: .8rem; font-weight: 700;
  padding: 4px 10px; border-radius: 999px; border: 1.5px solid currentColor; margin-bottom: 10px;
}
.register.r-elders { color: var(--berry); }
.register.r-friends { color: var(--leaf); }
.register.r-polite { color: var(--sea-deep); }
.register.r-anyone { color: var(--ink-soft); }
.note {
  background: var(--sun-soft); border-radius: var(--radius-sm); padding: 12px 14px; margin: 12px 0 0;
  font-size: .97rem; position: relative;
}
.note::before { content: "Kumbuka · Remember"; display: block; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 800; color: var(--coral-deep); margin-bottom: 2px; }

.say-btn {
  border: 1.5px solid var(--sea); color: var(--sea-deep); background: transparent;
  border-radius: 999px; padding: 4px 10px; font-size: .82rem; font-weight: 700; min-height: 34px;
}
.say-btn:hover { background: var(--sea-wash); }

/* chat / dialogue */
.chat { display: grid; gap: 10px; margin: 14px 0 4px; }
.bubble-row { display: flex; gap: 10px; align-items: flex-end; }
.bubble-row.me { flex-direction: row-reverse; }
.avatar { flex: none; width: 52px; height: 52px; }
.avatar svg { width: 100%; height: 100%; display: block; }
.bubble {
  max-width: 78%; padding: 10px 14px; border-radius: 18px 18px 18px 6px;
  background: var(--paper); border: 1.5px solid rgba(31, 42, 68, .14);
}
.bubble-row.me .bubble { border-radius: 18px 18px 6px 18px; background: var(--sea-wash); border-color: rgba(47, 111, 122, .35); }
.bubble .who { display: block; font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); }
.bubble .sw { font-size: 1.22rem; display: block; }
.bubble .en { font-size: .88rem; color: var(--ink-soft); display: block; }
.bubble.gap {
  background: repeating-linear-gradient(-45deg, transparent 0 8px, rgba(31, 42, 68, .05) 8px 16px), var(--card);
  border-style: dashed; border-color: var(--ink-soft); min-width: 120px;
}
.bubble.gap .sw { color: var(--ink-faint); letter-spacing: .2em; }
.you-dot { width: 52px; height: 52px; border-radius: 50%; background: var(--sea); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .8rem; letter-spacing: .04em; border: 3px solid var(--card); box-shadow: 0 0 0 2px var(--sea); }

/* scene */
.scene-head { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; margin-bottom: 8px; }
.scene-head .avatar { width: 76px; height: 76px; }
.scene-head .who-name { font-family: var(--serif); font-weight: 700; font-size: 1.15rem; }
.scene-head .who-role { font-size: .88rem; color: var(--ink-soft); }
.setting { font-family: var(--serif); font-style: italic; font-size: 1.12rem; color: var(--ink); border-left: 3px solid var(--sun); padding: 2px 0 2px 12px; margin: 10px 0 6px; }

/* options */
.options { display: grid; gap: 10px; margin-top: 16px; }
.option {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px;
  text-align: left; width: 100%; min-height: 56px; padding: 10px 14px;
  border: 2px solid rgba(31, 42, 68, .22); border-radius: var(--radius-sm); background: #fffdf7;
  box-shadow: 0 3px 0 rgba(31, 42, 68, .18);
  transition: border-color var(--t), background var(--t), transform 120ms var(--ease), box-shadow 120ms var(--ease);
}
.option:hover:not([disabled]) { border-color: var(--ink); }
.option:active:not([disabled]) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(31, 42, 68, .18); }
.option:focus-visible { box-shadow: var(--focus); border-radius: var(--radius-sm); }
.option .key {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  border: 1.5px solid rgba(31, 42, 68, .3); font-size: .85rem; font-weight: 700; color: var(--ink-soft);
}
.option .text { font-size: 1.08rem; }
.option .text.sw-opt { font-family: var(--serif); font-style: italic; font-size: 1.25rem; }
.option[aria-pressed="true"] { border-color: var(--ink); background: var(--sea-wash); }
.option.correct { border-color: var(--leaf); background: var(--leaf-soft); }
.option.correct .key { background: var(--leaf); color: #fff; border-color: var(--leaf); }
.option.wrong { border-color: var(--coral); background: #f8e3dc; }
.option.wrong .key { background: var(--coral); color: #fff; border-color: var(--coral); }
.option[disabled] { cursor: default; }
.option[disabled]:not(.correct):not(.wrong) { opacity: .6; }

/* match */
.match { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.match-col { display: grid; gap: 10px; align-content: start; }
.match-col h3 { font-family: var(--sans); font-size: .76rem; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); margin: 0; }
.tile {
  width: 100%; min-height: 52px; padding: 8px 12px; border-radius: var(--radius-sm);
  border: 2px solid rgba(31, 42, 68, .22); background: #fffdf7; text-align: center;
  box-shadow: 0 3px 0 rgba(31, 42, 68, .18); font-size: 1rem;
  transition: border-color var(--t), background var(--t), transform 120ms var(--ease), opacity var(--t);
}
.tile.sw-tile { font-family: var(--serif); font-style: italic; font-size: 1.15rem; }
.tile:hover:not([disabled]) { border-color: var(--ink); }
.tile[aria-pressed="true"] { border-color: var(--ink); background: var(--sun-soft); transform: translateY(-2px); }
.tile.paired { background: var(--leaf-soft); border-color: var(--leaf); box-shadow: none; color: var(--ink); }
.tile.nope { border-color: var(--coral); background: #f8e3dc; animation: shake 360ms; }
.tile:focus-visible { box-shadow: var(--focus); }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }

/* build */
.build-target {
  min-height: 72px; margin: 14px 0; padding: 12px; border-radius: var(--radius-sm);
  border: 2px dashed rgba(31, 42, 68, .3); background:
    repeating-linear-gradient(transparent 0 34px, rgba(47, 111, 122, .25) 34px 36px), #fffdf7;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
}
.build-target:empty::before { content: attr(data-empty); color: var(--ink-faint); font-style: italic; font-family: var(--serif); align-self: center; }
.build-bank { display: flex; flex-wrap: wrap; gap: 8px; }
.word {
  font-family: var(--serif); font-style: italic; font-size: 1.2rem;
  padding: 8px 14px; min-height: 46px; border-radius: 10px; border: 2px solid rgba(31, 42, 68, .25);
  background: var(--card); box-shadow: 0 3px 0 rgba(31, 42, 68, .2);
  transition: transform 120ms var(--ease), opacity var(--t);
}
.word:hover:not([disabled]) { border-color: var(--ink); }
.word.used { opacity: .25; box-shadow: none; }
.word.placed { background: var(--sun-soft); }
.word:focus-visible { box-shadow: var(--focus); }
.en-target { font-size: 1.15rem; font-weight: 650; }

/* type */
.type-row { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.type-input {
  flex: 1 1 220px; min-height: 54px; padding: 10px 16px; border-radius: var(--radius-sm);
  border: 2px solid rgba(31, 42, 68, .35); background: #fffdf7;
  font-family: var(--serif); font-style: italic; font-size: 1.35rem;
}
.type-input:focus-visible { border-color: var(--ink); box-shadow: var(--focus); }
.type-input.correct { border-color: var(--leaf); background: var(--leaf-soft); }
.type-input.wrong { border-color: var(--coral); background: #f8e3dc; }
.hint { margin-top: 8px; font-size: .9rem; color: var(--ink-soft); }

/* count */
.count-art {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
  padding: 18px; margin: 8px 0; border-radius: var(--radius-sm);
  background: radial-gradient(circle at 50% 120%, var(--sand), transparent 70%), var(--paper);
}
.count-art svg { width: clamp(48px, 12vw, 84px); height: auto; }

/* route */
.route { position: relative; margin: 10px auto 0; max-width: 460px; aspect-ratio: 1 / 1; }
.route svg { width: 100%; height: 100%; display: block; }
.route .place {
  position: absolute; transform: translate(-50%, -50%);
  display: grid; justify-items: center; gap: 2px; text-align: center;
  padding: 8px 10px 6px; border-radius: 14px; min-width: 92px;
  border: 2px solid var(--ink); background: var(--card); box-shadow: 0 3px 0 var(--ink);
  transition: transform 120ms var(--ease), background var(--t);
}
.route .place:hover:not([disabled]) { background: #fff; }
.route .place .pi { width: 34px; height: 34px; }
.route .place .pn { font-family: var(--serif); font-style: italic; font-weight: 700; font-size: 1rem; line-height: 1.1; }
.route .place .pe { font-size: .72rem; color: var(--ink-soft); }
.route .place.correct { background: var(--leaf-soft); border-color: var(--leaf); box-shadow: 0 3px 0 var(--leaf); }
.route .place.wrong { background: #f8e3dc; border-color: var(--coral); box-shadow: 0 3px 0 var(--coral); }
.route .place:focus-visible { box-shadow: 0 3px 0 var(--ink), var(--focus); border-radius: 14px; }
.route .walker { transition: transform 900ms var(--ease); }
.instruction { font-family: var(--serif); font-style: italic; font-size: clamp(1.4rem, 2vw + 1rem, 1.9rem); font-weight: 600; line-height: 1.2; }

/* feedback & action bar */
.feedback {
  margin-top: 16px; border-radius: var(--radius); padding: 16px 18px;
  border: 2px solid; display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; align-items: start;
}
.feedback:focus-visible { box-shadow: var(--focus); }
.feedback.ok { background: var(--leaf-soft); border-color: var(--leaf); }
.feedback.no { background: #f9e6d8; border-color: var(--sun); }
.feedback .fb-icon { grid-row: span 3; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 1.3rem; font-weight: 800; color: #fff; }
.feedback.ok .fb-icon { background: var(--leaf); }
.feedback.no .fb-icon { background: var(--sun); color: var(--ink); }
.feedback .fb-title { font-family: var(--serif); font-size: 1.3rem; font-weight: 700; }
.feedback .fb-answer { font-size: 1rem; }
.feedback .fb-answer .sw { font-size: 1.15rem; }
.feedback .fb-why { color: var(--ink-soft); font-size: .97rem; }

.actionbar {
  margin: 18px 0 0; padding: 12px 0;
  display: flex; gap: 10px; justify-content: space-between; align-items: center; flex-wrap: wrap;
}
@media (max-width: 700px) {
  /* Keep Check / Continue within thumb reach on phones. */
  .actionbar {
    position: sticky; bottom: 0; z-index: 5;
    margin: 14px calc(-1 * clamp(14px, 3vw, 28px)) 0; padding: 12px clamp(14px, 3vw, 28px) calc(12px + env(safe-area-inset-bottom));
    background: rgba(244, 236, 220, .94); border-top: 1.5px dashed rgba(31, 42, 68, .18);
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  }
  .actionbar:has(> .kbd-hint:only-child) { display: none; }
}
.actionbar .grow { flex: 1; }
.actionbar .btn-primary, .actionbar .btn-coral { min-width: 160px; }
.kbd-hint { font-size: .8rem; color: var(--ink-faint); }
@media (max-width: 600px) { .kbd-hint { display: none; } .actionbar .btn-primary, .actionbar .btn-coral { flex: 1; } }

/* finish */
.finish { text-align: center; display: grid; gap: 18px; justify-items: center; }
.finish h1 .sw { color: var(--c1, var(--coral)); }
.stamp {
  width: 150px; height: 150px; border-radius: 50%; display: grid; place-items: center; text-align: center;
  border: 4px double var(--c1, var(--coral)); color: var(--c1, var(--coral));
  font-family: var(--serif); font-weight: 700; transform: rotate(-8deg);
  background: radial-gradient(circle, rgba(255, 255, 255, .5), transparent 70%);
  animation: stamp 520ms var(--ease) both;
}
.stamp small { display: block; font-size: .7rem; letter-spacing: .18em; text-transform: uppercase; }
.stamp b { display: block; font-size: 1.35rem; line-height: 1.05; }
@keyframes stamp { from { transform: rotate(-8deg) scale(1.6); opacity: 0; } to { transform: rotate(-8deg) scale(1); opacity: 1; } }
.finish-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; width: 100%; max-width: 520px; }
.finish-stats .stat span { display: block; line-height: 1.25; }
.review-list { text-align: left; width: 100%; max-width: 560px; list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.review-list li { background: var(--card); border-radius: var(--radius-sm); padding: 10px 14px; border-left: 4px solid var(--sun); }
.review-list .sw { font-size: 1.1rem; }

/* kanga card */
.kanga {
  --k1: var(--coral); --k2: var(--sun);
  position: relative; width: 100%; max-width: 420px; min-height: 240px;
  border-radius: 10px; padding: 22px; color: var(--ink);
  background:
    radial-gradient(circle, var(--k2) 2.5px, transparent 3px) 0 0 / 16px 16px,
    var(--k1);
  box-shadow: var(--shadow-lift);
  display: grid; grid-template-rows: minmax(110px, 1fr) auto; gap: 8px;
}
.kanga::before {
  content: ""; position: absolute; inset: 10px; border-radius: 6px; pointer-events: none;
  border: 6px solid transparent;
  border-image: repeating-linear-gradient(45deg, var(--k2) 0 6px, var(--card) 6px 12px) 6;
}
.kanga .motif { display: grid; place-items: center; }
.kanga .motif { min-height: 0; background: radial-gradient(circle, var(--card) 0 62px, transparent 63px); }
.kanga.locked .motif { background: none; }
.kanga .motif svg { width: auto; height: 104px; }
.kanga .jina {
  position: relative; z-index: 1;
  background: var(--card); border-radius: 6px; padding: 8px 12px; text-align: center;
  border: 2px solid var(--k2);
}
.kanga .jina .sw { font-size: clamp(1rem, 2.4vw + .5rem, 1.25rem); font-weight: 700; display: block; line-height: 1.2; }
.kanga .jina .en { font-size: .82rem; color: var(--ink-soft); }
.kanga.locked { background: repeating-linear-gradient(45deg, var(--paper-2) 0 10px, var(--paper-3) 10px 20px); box-shadow: none; }
.kanga.locked .jina { border-color: var(--paper-3); }
.kanga.locked::before { border-image: none; border-color: rgba(31, 42, 68, .15); border-style: dashed; }

.kanga-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(250px, 100%), 1fr)); gap: 18px; margin-top: 16px; }
.kanga-grid figure { min-width: 0; }
.kanga-grid figure { margin: 0; display: grid; gap: 8px; }
.kanga-grid figcaption { font-size: .85rem; color: var(--ink-soft); }

/* phrasebook */
.book-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.search {
  min-height: 46px; padding: 8px 14px; border-radius: 999px; border: 2px solid rgba(31, 42, 68, .3);
  background: #fffdf7; min-width: min(320px, 100%);
}
.search:focus-visible { border-color: var(--ink); }
.book-section { margin-top: 18px; }
.book-section h2 { font-size: 1.3rem; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.book-section h2 small { font-family: var(--sans); font-size: .82rem; color: var(--ink-soft); font-weight: 600; }
.book-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.book-list li { background: var(--card); border-radius: 10px; padding: 8px 12px; display: grid; grid-template-columns: 1fr auto; gap: 0 10px; align-items: center; border: 1px solid rgba(31, 42, 68, .08); }
.book-list .sw { font-size: 1.12rem; font-weight: 600; }
.book-list .en { font-size: .9rem; color: var(--ink-soft); grid-column: 1; }
.book-list .say-btn { grid-row: 1 / span 2; grid-column: 2; }
.book-empty { padding: 18px; border: 2px dashed rgba(31, 42, 68, .2); border-radius: var(--radius); color: var(--ink-soft); }

/* dialog */
dialog {
  border: 0; padding: 0; border-radius: var(--radius); background: var(--card); color: var(--ink);
  width: min(680px, calc(100% - 24px)); max-height: min(86vh, 900px);
  box-shadow: 0 30px 80px -20px rgba(31, 42, 68, .55);
}
dialog::backdrop { background: rgba(31, 42, 68, .45); }
.dialog-inner { position: relative; padding: clamp(20px, 4vw, 32px); overflow: auto; max-height: min(86vh, 900px); }
.dialog-close { position: sticky; top: 0; float: right; width: 42px; height: 42px; border-radius: 50%; border: 2px solid rgba(31, 42, 68, .25); background: var(--card); font-size: 1.4rem; line-height: 1; margin: -6px -6px 0 10px; }
.dialog-close:hover { border-color: var(--ink); }
.dialog-close:focus-visible { border-radius: 50%; }
dialog h2 { margin-right: 40px; }
dialog h3 { margin-top: 1.2em; }
dialog ul { padding-left: 1.2em; }
dialog li { margin-bottom: .35em; }
.sources li { font-size: .92rem; }
.danger-zone { margin-top: 18px; padding: 14px; border-radius: var(--radius-sm); border: 2px dashed var(--coral); }
.setting-row { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px dashed rgba(31, 42, 68, .15); }
.switch { appearance: none; width: 50px; height: 30px; border-radius: 999px; background: var(--paper-3); position: relative; border: 2px solid var(--ink-soft); flex: none; cursor: pointer; transition: background var(--t); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform var(--t) var(--ease); }
.switch:checked { background: var(--sea); border-color: var(--sea-deep); }
.switch:checked::after { transform: translateX(20px); }
.switch:focus-visible { box-shadow: var(--focus); }
.pron-table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.pron-table td, .pron-table th { text-align: left; padding: 6px 8px; border-bottom: 1px dashed rgba(31, 42, 68, .15); vertical-align: top; }

.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall 2.4s cubic-bezier(.3, .6, .5, 1) forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); opacity: .8; } }

.fade-in { animation: fade-in 320ms var(--ease) both; }
@keyframes fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Calm mode: honour OS setting, or the in-game switch. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
  .port[data-state="next"] .port-btn::after { display: none; }
  .confetti { display: none; }
}
.calm *, .calm *::before, .calm *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
.calm .port[data-state="next"] .port-btn::after, .calm .confetti { display: none; }

@media (forced-colors: active) {
  .option, .tile, .word, .btn, .port-btn, .place { border: 2px solid ButtonText; }
  .option.correct, .tile.paired, .place.correct { outline: 3px solid Highlight; }
}

@media print {
  .topbar, .actionbar, .chart-wrap, .banner { display: none; }
  body { background: #fff; }
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 14px;
  max-width: min(520px, calc(100% - 32px)); box-shadow: var(--shadow-lift); font-size: .95rem;
  transition: opacity var(--t), transform var(--t) var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
