/* ============================================================================
   Pandarin (熊猫语 / SiYuu) — Bamboo dark theme
   Palette & motif extend the existing "Bamboo Morse" studio.
   ========================================================================== */
:root {
  --bg:        #0b0f19;
  --bg-deep:   #070a12;
  --panel:     #111827;
  --panel-2:   #161f30;
  --inset:     #030712;
  --border:    #1f2937;
  --border-2:  #374151;
  --text:      #f1f5f9;
  --muted:     #9ca3af;
  --muted-2:   #6b7280;
  --accent:    #10b981;
  --accent-2:  #34d399;
  --accent-3:  #6ee7b7;
  --accent-deep:#047857;
  --danger:    #ef4444;
  --gold:      #fbbf24;
  --radius:    14px;
  --radius-sm: 8px;
  --maxw:      1120px;
  --shadow:    0 10px 30px rgba(0,0,0,.45);
  --bamboo-grad: linear-gradient(180deg, #047857 0%, #059669 30%, #34d399 70%, #047857 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
     radial-gradient(1200px 600px at 80% -10%, rgba(16,185,129,.10), transparent 60%),
     radial-gradient(900px 500px at -10% 10%, rgba(52,211,153,.06), transparent 55%),
     var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { color: var(--accent-3); }
::selection { background: rgba(16,185,129,.35); }

/* ----- Layout ----- */
.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
main { padding: 32px 0 80px; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ----- Header / nav ----- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: rgba(11,15,25,.82);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.site-header .container { display: flex; align-items: center; gap: 18px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.15rem; color: var(--text); }
.brand .panda { font-size: 1.5rem; line-height: 1; }
.brand .zh { color: var(--accent-2); font-weight: 700; }
.brand small { display:block; font-size:.62rem; font-weight:600; letter-spacing:.14em; text-transform:uppercase; color: var(--muted-2); }
.nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  color: var(--muted); font-weight: 600; font-size: .92rem;
  padding: 8px 14px; border-radius: 999px; transition: .15s;
}
.nav a:hover { color: var(--text); background: var(--panel); }
.nav a.active { color: #04150f; background: var(--accent); }

/* language toggle */
.lang-toggle { display: inline-flex; background: var(--bg-deep); border: 1px solid var(--border-2); border-radius: 999px; padding: 3px; }
.lang-toggle button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-weight: 700; font-size: .78rem; padding: 5px 12px; border-radius: 999px; transition: .15s;
}
.lang-toggle button.active { background: var(--accent); color: #04150f; }

/* mobile nav toggle */
.nav-burger { display:none; margin-left:auto; background:var(--panel); border:1px solid var(--border-2); color:var(--text); border-radius:8px; padding:8px 10px; cursor:pointer; font-size:1.1rem; }

/* ----- Typography ----- */
h1 { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 1.45rem; font-weight: 750; margin: 6px 0; }
h3 { font-size: 1.1rem; font-weight: 700; color: var(--accent-2); }
.lead { color: var(--muted); font-size: 1.05rem; max-width: 70ch; }
.muted { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: .72rem; font-weight: 700; color: var(--accent); }
.section-title { display:flex; align-items:center; gap:12px; margin: 36px 0 14px; }
.section-title::after { content:""; flex:1; height:1px; background: var(--border); }
.pandarin { font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; color: var(--accent-3); }

/* ----- Buttons ----- */
.btn { display:inline-flex; align-items:center; gap:8px; cursor:pointer; border:0; font-weight:700;
  font-size:.92rem; padding:11px 18px; border-radius: var(--radius-sm); transition:.15s; }
.btn-primary { background: var(--accent); color:#04150f; }
.btn-primary:hover { background: var(--accent-2); transform: translateY(-1px); }
.btn-ghost { background: var(--panel); color: var(--text); border:1px solid var(--border-2); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-2); }
.btn-lg { padding: 14px 24px; font-size: 1rem; }
.btn:disabled { opacity:.45; cursor:not-allowed; transform:none; }

/* speaker / audio button */
.speak {
  display:inline-flex; align-items:center; justify-content:center;
  width: 34px; height: 34px; border-radius: 50%; cursor:pointer;
  background: var(--bg-deep); border:1px solid var(--border-2); color: var(--accent-2);
  font-size: 1rem; transition:.15s; flex: none;
}
.speak:hover { background: var(--accent); color:#04150f; border-color: var(--accent); }
.speak.lg { width: 46px; height: 46px; font-size: 1.3rem; }
.speak.playing { animation: pulse .6s ease infinite; }
@keyframes pulse { 0%,100%{ box-shadow:0 0 0 0 rgba(16,185,129,.5);} 50%{ box-shadow:0 0 0 8px rgba(16,185,129,0);} }

/* ----- Cards ----- */
.card {
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.card-link { display:block; position:relative; overflow:hidden; transition:.18s; }
.card-link::before { content:""; position:absolute; left:0; top:0; bottom:0; width:4px; background: var(--bamboo-grad); opacity:.0; transition:.18s; }
.card-link:hover { transform: translateY(-3px); border-color: var(--border-2); }
.card-link:hover::before { opacity:1; }
.card-link h3 { color: var(--text); }
.card-link:hover h3 { color: var(--accent-2); }
.grid { display:grid; gap:16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(150px,1fr)); }

.badge { display:inline-block; font-size:.7rem; font-weight:700; letter-spacing:.04em; padding:3px 9px; border-radius:999px; background: rgba(16,185,129,.14); color: var(--accent-2); border:1px solid rgba(16,185,129,.25); }
.badge.soon { background: rgba(148,163,184,.12); color: var(--muted); border-color: var(--border-2); }
.tag { display:inline-block; font-size:.72rem; font-weight:700; padding:2px 8px; border-radius:6px; background: var(--bg-deep); color: var(--muted); border:1px solid var(--border); }

/* ----- Hero ----- */
.hero { text-align:center; padding: 30px 0 10px; }
.hero .panda-big { font-size: 4rem; line-height:1; filter: drop-shadow(0 6px 18px rgba(16,185,129,.25)); }
.hero h1 { font-size: 2.6rem; margin: 14px 0 6px; }
.hero h1 .zh { color: var(--accent-2); }
.hero .names { color: var(--muted); font-size: 1rem; margin-bottom: 8px; }
.hero .cta { display:flex; gap:12px; justify-content:center; flex-wrap:wrap; margin-top: 22px; }
.hero-quote { margin: 26px auto 0; max-width: 640px; padding: 16px 20px; border:1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); }
.hero-quote .pandarin { font-size: 1.15rem; }

/* ----- Letter tiles (alphabet) ----- */
.tiles { display:grid; gap:12px; grid-template-columns: repeat(auto-fill, minmax(130px,1fr)); }
.tile {
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius);
  padding: 14px; text-align:center; position:relative; transition:.15s;
}
.tile:hover { border-color: var(--accent); transform: translateY(-2px); }
.tile .flag { position:absolute; top:8px; right:10px; font-size:1.05rem; }
.tile .glyph { font-size: 2rem; font-weight:800; color: var(--accent-2); font-family:"SF Mono",ui-monospace,Menlo,monospace; }
.tile .ipa { color: var(--muted); font-size:.85rem; margin: 2px 0 8px; }
.tile .desc { font-size:.82rem; color: var(--text); min-height: 2.4em; }
.tile .speak { margin-top: 10px; }

/* ----- Tables ----- */
table.data { width:100%; border-collapse: collapse; background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); overflow:hidden; }
table.data th, table.data td { padding: 10px 14px; text-align:left; border-bottom:1px solid var(--border); font-size:.92rem; }
table.data th { background: var(--bg-deep); color: var(--accent-2); font-size:.78rem; text-transform:uppercase; letter-spacing:.05em; }
table.data tr:last-child td { border-bottom:0; }
table.data tr:hover td { background: var(--panel-2); }
.cell-glyph { font-family:"SF Mono",ui-monospace,Menlo,monospace; color: var(--accent-3); font-weight:700; }

/* ----- Lexicon explorer ----- */
.toolbar { display:flex; gap:10px; flex-wrap:wrap; align-items:center; margin-bottom: 18px; }
.search {
  flex:1; min-width: 220px; background: var(--bg-deep); border:1px solid var(--border-2); color:var(--text);
  padding: 11px 14px; border-radius: var(--radius-sm); font-size:.95rem; outline:none;
}
.search:focus { border-color: var(--accent); }
.seg { display:inline-flex; background: var(--bg-deep); border:1px solid var(--border-2); border-radius: var(--radius-sm); padding:3px; flex-wrap:wrap; }
.seg button { border:0; background:transparent; color:var(--muted); cursor:pointer; font-weight:700; font-size:.82rem; padding:7px 12px; border-radius:6px; }
.seg button.active { background: var(--accent); color:#04150f; }
.count { color: var(--muted); font-size:.85rem; }

.cat-block { margin-bottom: 26px; scroll-margin-top: 80px; }
.cat-head { display:flex; align-items:baseline; gap:10px; margin-bottom:10px; padding-bottom:6px; border-bottom:1px solid var(--border); }
.cat-head .code { font-family:"SF Mono",ui-monospace,monospace; color: var(--accent); font-weight:800; }
.cat-head .cat-name { font-weight:700; }
.cat-head .phon { color: var(--muted-2); font-size:.82rem; }
.entries { display:grid; gap:8px; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); }
.entry { display:flex; align-items:center; gap:10px; background: var(--panel); border:1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; }
.entry .syl { font-family:"SF Mono",ui-monospace,monospace; font-weight:800; color: var(--accent-3); min-width: 44px; }
.entry .gloss { flex:1; font-size:.9rem; }
.entry .gloss .fr-fallback { color: var(--muted-2); font-size:.78rem; font-style:italic; }
.fr-pill { display:inline-block; font-size:.6rem; font-weight:800; letter-spacing:.04em; vertical-align:middle;
  padding:1px 5px; border-radius:4px; background: var(--bg-deep); color: var(--muted-2); border:1px solid var(--border); margin-left:4px; }
.entry .speak { width:30px; height:30px; font-size:.85rem; }

/* ----- Lesson ----- */
.lesson-head { margin-bottom: 18px; }
.callout { border-left:4px solid var(--accent); background: var(--panel); padding: 14px 18px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin: 16px 0; }
.callout.gold { border-color: var(--gold); }
.callout h3 { color: var(--text); margin-bottom: 4px; }
.steps { display:flex; gap:8px; align-items:center; margin: 14px 0 22px; flex-wrap:wrap; }
.step-dot { width:10px; height:10px; border-radius:50%; background: var(--border-2); }
.step-dot.done { background: var(--accent); }
.lesson-nav { display:flex; justify-content:space-between; margin-top: 36px; gap:12px; }

/* ----- Quiz ----- */
.quiz { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.quiz .q { font-size: 1.15rem; font-weight:700; margin-bottom: 16px; }
.quiz .q .pandarin { font-size: 1.4rem; }
.options { display:grid; gap:10px; }
.opt { text-align:left; background: var(--bg-deep); border:1px solid var(--border-2); color:var(--text);
  padding: 13px 16px; border-radius: var(--radius-sm); cursor:pointer; font-size:.95rem; transition:.12s; }
.opt:hover { border-color: var(--accent); }
.opt.correct { background: rgba(16,185,129,.18); border-color: var(--accent); color: var(--accent-3); }
.opt.wrong { background: rgba(239,68,68,.15); border-color: var(--danger); color: #fca5a5; }
.opt:disabled { cursor: default; }
.quiz-progress { color: var(--muted); font-size:.85rem; margin-bottom: 12px; }
.quiz-result { text-align:center; padding: 14px 0; }
.quiz-result .score { font-size: 2.4rem; font-weight:800; color: var(--accent-2); }

/* ----- Flashcards ----- */
.flashcard { background: var(--bg-deep); border:1px solid var(--border-2); border-radius: var(--radius);
  min-height: 170px; display:flex; flex-direction:column; align-items:center; justify-content:center;
  cursor:pointer; padding: 26px; text-align:center; transition:.15s; }
.flashcard:hover { border-color: var(--accent); }
.flashcard.flipped { background: #08120e; border-color: var(--accent-deep); }
.flashcard .fc-term { font-family:"SF Mono",ui-monospace,Menlo,monospace; font-size:2.6rem; font-weight:800; color: var(--accent-3); }
.flashcard .fc-sub { color: var(--muted); margin-top:6px; }
.flashcard .fc-face { font-size:1.3rem; }
.fc-controls { display:flex; gap:10px; justify-content:center; margin-top:16px; }

/* ----- Word builder ----- */
.wb-stage { background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 18px; }
.wb-word { font-family:"SF Mono",ui-monospace,Menlo,monospace; font-size: 2rem; font-weight:800; color: var(--accent-3); min-height: 1.4em; word-break: break-word; }
.wb-gloss { color: var(--muted); margin-top: 6px; min-height: 1.4em; }
.wb-chips { display:flex; gap:8px; flex-wrap:wrap; margin-top: 14px; min-height: 40px; padding: 8px; background: var(--bg-deep); border-radius: var(--radius-sm); border:1px dashed var(--border-2); }
.wb-chip { display:inline-flex; align-items:center; gap:8px; background: var(--panel-2); border:1px solid var(--border-2); border-radius: 999px; padding: 5px 6px 5px 12px; font-weight:700; }
.wb-chip .x { cursor:pointer; width:20px; height:20px; border-radius:50%; background: var(--bg-deep); display:inline-flex; align-items:center; justify-content:center; color: var(--danger); font-size:.8rem; }
.wb-actions { display:flex; gap:10px; margin-top: 14px; flex-wrap:wrap; }
.pick { display:flex; align-items:center; gap:10px; background: var(--panel); border:1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; cursor:pointer; transition:.12s; }
.pick:hover { border-color: var(--accent); transform: translateY(-1px); }
.pick .syl { font-family:"SF Mono",ui-monospace,monospace; font-weight:800; color: var(--accent-3); min-width:42px; }
.pick .g { font-size:.85rem; color: var(--muted); }

/* ----- Dialogue ----- */
.turn { display:flex; gap:12px; margin-bottom: 16px; }
.turn .who { flex:none; width: 44px; height:44px; border-radius:50%; display:flex; align-items:center; justify-content:center;
  font-weight:800; background: var(--bg-deep); border:1px solid var(--border-2); color: var(--accent-2); }
.turn .bubble { background: var(--panel); border:1px solid var(--border); border-radius: 4px 14px 14px 14px; padding: 12px 16px; flex:1; }
.turn.right { flex-direction: row-reverse; }
.turn.right .bubble { border-radius: 14px 4px 14px 14px; }
.turn .pan { font-family:"SF Mono",ui-monospace,Menlo,monospace; color: var(--accent-3); font-size:1.02rem; }
.turn .gloss { color: var(--muted); font-size:.92rem; margin-top:6px; display:none; }
.turn.reveal .gloss { display:block; }
.turn .who-name { font-size:.72rem; color: var(--muted-2); font-weight:700; margin-bottom:4px; }

/* ----- Bamboo calligraphy (ported & extended from the studio) ----- */
.bamboo-output { width:100%; min-height:260px; background: var(--inset); border:2px solid var(--border);
  border-radius:12px; padding:20px; overflow-x:auto; white-space:nowrap; display:flex; align-items:flex-end;
  margin-bottom:14px; --stalk-gap:12px; }
.bamboo-placeholder { color: var(--muted-2); font-style:italic; align-self:center; width:100%; text-align:center; }
.bamboo-space { display:inline-block; width:35px; }
.bamboo-stalk { display:inline-flex; flex-direction:column-reverse; align-items:center; vertical-align:bottom;
  margin-right:var(--stalk-gap); position:relative; }
.bamboo-latin { font-size:11px; color: var(--muted-2); margin-top:12px; font-weight:bold; text-align:center; height:14px; }
.bamboo-output.hide-latin .bamboo-latin { opacity:0; }

/* Calligraphy theme: cane segments + alternating leaves */
.bamboo-output.theme-calligraphy .bamboo-stalk { min-width:45px; padding:0 15px; }
.bamboo-output.theme-calligraphy .dash { width:8px; height:26px; margin-bottom:-1px; border-radius:2px; position:relative; z-index:2;
  background: linear-gradient(90deg,#047857 0%,#059669 30%,#34d399 70%,#047857 100%);
  box-shadow: inset 0 2px 2px rgba(255,255,255,.2), inset 0 -2px 2px rgba(0,0,0,.4); }
.bamboo-output.theme-calligraphy .dot { width:16px; height:6px; margin:8px 0; position:relative; z-index:1;
  background: linear-gradient(135deg,#34d399 0%,#059669 100%); border-radius:100% 0 100% 0; }
.bamboo-output.theme-calligraphy .leaf-left { transform: translateX(-12px) rotate(-25deg); transform-origin:right center; }
.bamboo-output.theme-calligraphy .leaf-right { transform: translateX(12px) rotate(25deg); transform-origin:left center; }

/* Minimalist theme: geometric dots + dashes */
.bamboo-output.theme-minimalist .bamboo-stalk { min-width:18px; }
.bamboo-output.theme-minimalist .dash { width:4px; height:22px; margin:1px 0; border-radius:2px; background: var(--accent); }
.bamboo-output.theme-minimalist .dot { width:6px; height:6px; margin:1px 0; border-radius:50%; background: var(--accent); }

/* On-screen keyboard */
.kbd { display:flex; flex-direction:column; gap:8px; background: var(--bg-deep); padding:14px; border-radius:12px; border:1px solid var(--border); margin-top:14px; }
.kbd-row { display:flex; justify-content:center; gap:6px; }
.kbd-key { background: var(--panel); border:1px solid var(--border-2); border-radius:6px; flex:1; max-width:64px; min-height:50px;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; cursor:pointer; color: var(--text); font-weight:700; transition:.1s; }
.kbd-key:hover { border-color: var(--accent); }
.kbd-key:active { background: var(--accent); color:#04150f; transform: translateY(1px); }
.kbd-key .km { font-size:10px; color: var(--accent-2); font-weight:600; letter-spacing:1px; }
.kbd-key .knum { font-size:9px; color: var(--muted-2); }
.kbd-key.pan { background:#061917; border-color:#0f766e; max-width:72px; }
.kbd-key.pan .kl { color: var(--accent-2); }
.kbd-key.space { max-width:340px; }
.kbd-key.bsp { max-width:80px; color:#f87171; border-color:#7f1d1d; }
.kbd-divider { height:1px; background: var(--border); margin:4px 0; }
@media (max-width:760px){ .kbd-key { min-height:42px; max-width:none; font-size:.85rem; } .kbd-key .km { display:none; } }

/* ----- Reference / grammar ----- */
.ref-section { margin-bottom: 30px; scroll-margin-top: 80px; }
.ref-section p { color: #cbd5e1; margin: 8px 0; }
.kv { display:grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 10px 0; }
.kv .k { font-family:"SF Mono",ui-monospace,monospace; color: var(--accent-2); font-weight:700; }
.ex { background: var(--bg-deep); border-left:3px solid var(--accent-deep); padding: 8px 14px; border-radius: 0 6px 6px 0; margin: 8px 0; }
.ex .pandarin { font-size: 1.05rem; }
.toc { display:flex; gap:8px; flex-wrap:wrap; margin: 14px 0 26px; }
.toc a { font-size:.85rem; padding: 6px 12px; border-radius: 999px; background: var(--panel); border:1px solid var(--border); color: var(--muted); }
.toc a:hover { border-color: var(--accent); color: var(--accent-2); }

/* ----- Footer ----- */
.site-footer { border-top:1px solid var(--border); padding: 26px 0; color: var(--muted-2); font-size:.85rem; }
.site-footer .container { display:flex; justify-content:space-between; flex-wrap:wrap; gap:10px; }

/* ----- Responsive ----- */
@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero h1 { font-size: 2rem; }
  table.data { font-size: .82rem; }
  table.data th, table.data td { padding: 8px 10px; }
  .entries { grid-template-columns: 1fr; }
  .lesson-nav { flex-direction: column; }
  .lesson-nav .btn { width: 100%; justify-content: center; }
  .nav { position:absolute; top:64px; left:0; right:0; flex-direction:column; background: var(--panel);
    border-bottom:1px solid var(--border); padding: 8px 20px; gap:2px; display:none; }
  .nav.open { display:flex; }
  .nav-burger { display:inline-block; }
  .site-header .container { gap: 10px; }
}
