/* ====================================================================
   Twiga — styles
   Warm savanna theme, large touch targets, responsive for phone /
   tablet / desktop. No external fonts or images (fast on slow networks).
   ==================================================================== */

:root {
  --bg: #FFF7E8;
  --bg2: #FFEAC9;
  --ink: #3A2A1A;
  --ink-soft: #7A6450;
  --card: #FFFFFF;
  --line: #F0E2C8;
  --brand: #FF9A3C;
  --brand-d: #F1771C;
  --green: #5BBF6A;
  --green-d: #3E9E50;
  --red: #E4572E;
  --red-soft: #FCE9E2;
  --star: #FFC93C;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 12px 30px rgba(120, 80, 20, .13);
  --shadow-sm: 0 4px 14px rgba(120, 80, 20, .10);
  --tap: 52px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink);
  background:
    radial-gradient(120% 60% at 50% 0%, #FFF8EC 0%, var(--bg) 45%, var(--bg2) 100%) fixed;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow-wrap: break-word;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 12px 0;
  z-index: 50;
}
.skip-link:focus { left: 0; }

button { font-family: inherit; }
:focus-visible { outline: 3px solid var(--brand-d); outline-offset: 2px; border-radius: 12px; }

/* --------------------------------------------------------------- HEADER */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px clamp(12px, 4vw, 28px);
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(255, 247, 232, .86);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 2px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  padding: 4px 6px;
  margin: 0;
  cursor: pointer;
  border-radius: 14px;
  flex: 1 1 auto;
  min-width: 0;
}
.brand .giraffe { width: 42px; height: 42px; flex: 0 0 auto; }
.brand-text { text-align: left; line-height: 1.1; min-width: 0; }
.brand-name { display: block; font-size: 22px; font-weight: 800; color: var(--brand-d); letter-spacing: .3px; }
.brand-tag { display: block; font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.header-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.stars-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  background: #FFF4D2;
  color: #9A6B00;
  border: 2px solid #FAE0A0;
  padding: 8px 12px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
}
.icon-btn:hover { background: #FFF1DC; }
.icon-btn:active { transform: scale(.96); }
.icon-btn[aria-pressed="false"] { opacity: .62; }
.icon-btn .em { font-size: 18px; }
.icon-btn.install { border-color: var(--green); color: var(--green-d); background: #EAF8EC; }

/* language switcher (EN / SW / 中) */
.lang-switch { display: inline-flex; align-items: center; gap: 2px; background: var(--card); border: 2px solid var(--line); border-radius: 999px; padding: 3px; }
.lang-opt { min-width: 40px; min-height: 40px; border: 0; background: transparent; border-radius: 999px; font-weight: 800; font-size: 14px; color: var(--ink-soft); cursor: pointer; padding: 6px 10px; transition: background .12s ease, color .12s ease; }
.lang-opt:hover { background: #FFF1DC; }
.lang-opt.active { background: var(--brand); color: #fff; }

/* ----------------------------------------------------------------- MAIN */
.app-main {
  max-width: 940px;
  margin: 0 auto;
  padding: clamp(14px, 3.5vw, 26px) clamp(12px, 4vw, 26px) 40px;
  outline: none;
}

/* hero ----------------------------------------------------------------- */
.hero {
  position: relative;
  display: flex;
  align-items: center;
  gap: clamp(10px, 3vw, 22px);
  background: linear-gradient(135deg, #FFE39A 0%, #FFB661 60%, #FF9A3C 100%);
  border-radius: 28px;
  padding: clamp(16px, 4vw, 26px);
  color: #4A2C00;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -40px; bottom: -60px;
  width: 180px; height: 180px;
  background: radial-gradient(circle, rgba(255,255,255,.5) 0%, rgba(255,255,255,0) 70%);
}
.hero .giraffe { width: clamp(74px, 20vw, 116px); height: auto; flex: 0 0 auto; filter: drop-shadow(0 6px 8px rgba(120,70,10,.18)); }
.hero-text { position: relative; z-index: 1; }
.hero-hi { font-size: clamp(22px, 5.5vw, 34px); font-weight: 800; margin: 0 0 4px; }
.hero-sub { font-size: clamp(15px, 3.6vw, 19px); margin: 0 0 12px; color: #6A4205; font-weight: 600; }
.hero-listen {
  border: 0;
  background: rgba(255, 255, 255, .85);
  color: #8A4B00;
  font-weight: 800;
  border-radius: 999px;
  padding: 10px 18px;
  min-height: 46px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.hero-listen:active { transform: scale(.97); }

/* section headers ------------------------------------------------------ */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
  margin: 26px 4px 12px;
  color: var(--ink);
}

/* subject grid --------------------------------------------------------- */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(10px, 2.6vw, 16px);
}
@media (min-width: 620px) { .subject-grid { grid-template-columns: repeat(3, 1fr); } }

.subject-card {
  --c: var(--brand);
  position: relative;
  text-align: left;
  border: 0;
  border-top: 7px solid var(--c);
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, box-shadow .15s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 130px;
}
.subject-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.subject-card:active { transform: translateY(0) scale(.99); }
.subject-emoji {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  font-size: 32px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--c) 16%, white);
  margin-bottom: 6px;
}
.subject-name { font-size: 19px; font-weight: 800; }
.subject-blurb { font-size: 13.5px; color: var(--ink-soft); }
.subject-meta { margin-top: auto; font-size: 13px; color: var(--c); font-weight: 800; display: flex; align-items: center; gap: 6px; }
.subject-dots { display: inline-flex; gap: 4px; margin-left: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.dot.done { background: var(--green); }

/* ask CTA -------------------------------------------------------------- */
.ask-cta {
  margin-top: 22px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 2px dashed #F0C98A;
  background: #FFFBF2;
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  text-align: left;
  box-shadow: var(--shadow-sm);
}
.ask-cta:active { transform: scale(.995); }
.ask-cta .giraffe { width: 50px; height: 50px; flex: 0 0 auto; }
.ask-cta-text { font-weight: 800; font-size: 17px; }
.ask-cta-sub { font-weight: 600; font-size: 13.5px; color: var(--ink-soft); }
.ask-cta .arrow { margin-left: auto; font-size: 22px; color: var(--brand-d); }

/* breadcrumb / back ---------------------------------------------------- */
.crumb {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-weight: 800;
  border-radius: 999px;
  padding: 10px 16px 10px 12px;
  min-height: var(--tap);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.crumb:active { transform: scale(.97); }

/* lesson list ---------------------------------------------------------- */
.lesson-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.lesson-row {
  --c: var(--brand);
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .1s ease, border-color .15s ease;
}
.lesson-row:hover { border-color: var(--c); transform: translateX(2px); }
.lesson-row:active { transform: scale(.99); }
.lesson-row .num {
  width: 46px; height: 46px; flex: 0 0 auto;
  display: grid; place-items: center;
  font-size: 26px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--c) 16%, white);
}
.lesson-row .lr-text { min-width: 0; }
.lesson-row .lr-title { font-weight: 800; font-size: 17px; }
.lesson-row .lr-sub { font-size: 13px; color: var(--ink-soft); }
.lesson-row .lr-stars { margin-left: auto; flex: 0 0 auto; font-size: 15px; letter-spacing: 1px; white-space: nowrap; }
.lesson-row .lr-stars .off { opacity: .25; }

/* lesson runtime ------------------------------------------------------- */
.progress {
  height: 12px;
  background: #F1E3C7;
  border-radius: 999px;
  overflow: hidden;
  margin: 14px 0 6px;
}
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--green-d)); border-radius: 999px; transition: width .35s ease; }
.progress-label { font-size: 13px; color: var(--ink-soft); font-weight: 700; margin-bottom: 14px; }

.card {
  background: var(--card);
  border-radius: 26px;
  padding: clamp(18px, 5vw, 34px);
  box-shadow: var(--shadow);
  text-align: center;
  border: 2px solid var(--line);
}
.card-emoji { font-size: clamp(64px, 18vw, 110px); line-height: 1; margin-bottom: 6px; }
.card-title { font-size: clamp(22px, 5.5vw, 30px); font-weight: 800; margin: 6px 0 10px; }
.card-body { font-size: clamp(17px, 4vw, 21px); color: #4A3826; max-width: 30ch; margin: 0 auto; }

.q-text { font-size: clamp(19px, 4.6vw, 25px); font-weight: 800; margin: 6px auto 4px; max-width: 26ch; }

.options { display: grid; gap: 12px; margin-top: 18px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  border: 3px solid var(--line);
  background: #FFFDF8;
  border-radius: 18px;
  padding: 16px 18px;
  font-size: clamp(17px, 4vw, 20px);
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
  min-height: 60px;
  transition: transform .08s ease, border-color .12s ease, background .12s ease;
}
.option:hover:not(:disabled) { border-color: var(--brand); background: #FFF6E8; }
.option:active:not(:disabled) { transform: scale(.99); }
.option .pick { width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%; border: 3px solid var(--line); display: grid; place-items: center; font-weight: 900; color: #fff; }
.option.correct { border-color: var(--green); background: #EAF8EC; }
.option.correct .pick { background: var(--green); border-color: var(--green); }
.option.wrong { border-color: var(--red); background: var(--red-soft); }
.option.wrong .pick { background: var(--red); border-color: var(--red); }
.option:disabled { cursor: default; }

.feedback {
  margin-top: 16px;
  border-radius: 16px;
  padding: 14px 16px;
  font-weight: 700;
  font-size: 16px;
  display: none;
}
.feedback.show { display: block; }
.feedback.ok { background: #EAF8EC; color: var(--green-d); border: 2px solid #BfE8C6; }
.feedback.no { background: var(--red-soft); color: #B23A18; border: 2px solid #F4C9BC; }

/* action bar ----------------------------------------------------------- */
.actions { display: flex; gap: 12px; margin-top: 20px; align-items: stretch; }
.btn {
  flex: 1 1 auto;
  min-height: var(--tap);
  border: 0;
  border-radius: 16px;
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
  padding: 12px 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .08s ease, filter .15s ease;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--brand), var(--brand-d)); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.03); }
.btn-primary:disabled { background: #E7D9C2; color: #9C8B72; cursor: not-allowed; box-shadow: none; }
.btn-ghost { flex: 0 0 auto; background: var(--card); border: 2px solid var(--line); color: var(--ink); }
.btn-ghost:hover { background: #FFF1DC; }
.btn-green { background: linear-gradient(135deg, var(--green), var(--green-d)); color: #fff; box-shadow: var(--shadow-sm); }

/* results -------------------------------------------------------------- */
.result { text-align: center; }
.result .giraffe { width: clamp(110px, 30vw, 160px); height: auto; margin: 0 auto 6px; display: block; }
.result-stars { font-size: clamp(40px, 11vw, 60px); letter-spacing: 6px; margin: 6px 0; }
.result-stars .off { opacity: .22; }
.result-title { font-size: clamp(22px, 5.5vw, 30px); font-weight: 800; }
.result-score { font-size: 18px; color: var(--ink-soft); font-weight: 700; margin-top: 4px; }

/* ask twiga ------------------------------------------------------------ */
.chat { display: flex; flex-direction: column; min-height: 60vh; margin-top: 16px; }
.chat-log { display: flex; flex-direction: column; gap: 12px; padding-bottom: 12px; }
.bubble { max-width: 84%; padding: 12px 16px; border-radius: 20px; font-size: 16.5px; box-shadow: var(--shadow-sm); }
.bubble.twiga { align-self: flex-start; background: #FFFFFF; border: 2px solid var(--line); border-bottom-left-radius: 6px; display: flex; gap: 10px; align-items: flex-start; }
.bubble.twiga .giraffe { width: 30px; height: 30px; flex: 0 0 auto; margin-top: 2px; }
.bubble.me { align-self: flex-end; background: linear-gradient(135deg, var(--brand), var(--brand-d)); color: #fff; border-bottom-right-radius: 6px; }
.bubble .listen-mini { background: none; border: 0; cursor: pointer; font-size: 16px; padding: 0 0 0 4px; opacity: .7; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chip {
  border: 2px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 14.5px;
  font-weight: 700;
  cursor: pointer;
  min-height: 42px;
}
.chip:hover { background: #FFF1DC; border-color: var(--brand); }

.composer { display: flex; gap: 10px; margin-top: auto; position: sticky; bottom: 0; padding: 10px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(0deg, var(--bg) 60%, rgba(255,247,232,0)); }
.composer input {
  flex: 1 1 auto;
  min-height: var(--tap);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 10px 16px;
  font-size: 17px;
  background: #fff;
  color: var(--ink);
}
.composer input:focus { outline: none; border-color: var(--brand); }
.composer .btn { flex: 0 0 auto; }

/* ----------------------------------------------------------------- TOAST */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(30px);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: transform .25s ease, opacity .25s ease;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------------------------------------------------------- FOOTER */
.app-footer {
  max-width: 940px;
  margin: 10px auto 0;
  padding: 22px clamp(12px, 4vw, 26px) calc(28px + env(safe-area-inset-bottom));
  color: var(--ink-soft);
  font-size: 13px;
  text-align: center;
  border-top: 2px solid var(--line);
}
.app-footer .ftag { font-weight: 700; }
.app-footer .ver { opacity: .7; }

/* 星期七 (W7) brand-family badge — deliberately low-key: monochrome mark in the
   muted footer colour, no pill, no border, slightly dimmed until hover. */
.w7-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 14px;
  text-decoration: none;
  color: var(--ink-soft);
  opacity: .68;
  transition: opacity .15s ease;
}
.w7-badge:hover { opacity: 1; }
.w7-mark { width: 18px; height: 18px; flex: 0 0 auto; color: var(--ink-soft); }
.w7-badge-txt { text-align: left; line-height: 1.1; }
.w7-name { display: block; font-weight: 700; font-size: 12px; color: var(--ink-soft); letter-spacing: .2px; }
.w7-cap { display: block; font-size: 10px; color: var(--ink-soft); opacity: .85; }

/* --------------------------------------------------------------- MOTION */
.pop { animation: pop .35s ease; }
@keyframes pop { 0% { transform: scale(.96); opacity: .4; } 100% { transform: scale(1); opacity: 1; } }
.celebrate { animation: bounce .6s ease; }
@keyframes bounce { 0%{transform:translateY(0)} 30%{transform:translateY(-12px)} 55%{transform:translateY(0)} 75%{transform:translateY(-6px)} 100%{transform:translateY(0)} }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
