:root {
  --ink: #102a46;
  --navy: #173f73;
  --blue: #2368a8;
  --cyan: #69d9d7;
  --paper: #f7fbff;
  --line: #cfe0ed;
  --muted: #65788a;
  --yellow: #ffd46a;
  --coral: #ff8d72;
  --white: #fff;
  --shadow: 0 20px 50px rgba(31, 69, 105, .12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(rgba(32, 97, 153, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 97, 153, .035) 1px, transparent 1px),
    #eff7fc;
  background-size: 28px 28px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

button, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { max-width: 1580px; margin: 0 auto; min-height: 100vh; padding: 0 32px 40px; }
.topbar { height: 86px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(23, 63, 115, .15); }
.brand { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand strong { display: block; font-size: 1.08rem; letter-spacing: .02em; }
.brand small { display: block; margin-top: 2px; color: var(--muted); font-size: .76rem; letter-spacing: .08em; }
.brand-mark { position: relative; width: 42px; height: 42px; border-radius: 12px; background: var(--navy); box-shadow: 4px 4px 0 var(--cyan); }
.brand-mark span, .brand-mark b { position: absolute; left: 11px; width: 20px; height: 8px; border: 2px solid white; }
.brand-mark span { top: 8px; }
.brand-mark b { bottom: 7px; width: 13px; left: 14.5px; }
.brand-mark i { position: absolute; left: 20px; top: 18px; height: 8px; border-left: 2px solid var(--yellow); }
.rule-badge { display: flex; align-items: center; gap: 9px; padding: 9px 14px; background: #e0f8f7; color: #17605f; border-radius: 999px; font-weight: 700; font-size: .86rem; }
.rule-badge span { width: 8px; height: 8px; border-radius: 50%; background: #1aa6a3; box-shadow: 0 0 0 4px rgba(26, 166, 163, .14); }

main { padding-top: 32px; }
.intro-row { display: flex; justify-content: space-between; gap: 40px; align-items: end; margin-bottom: 26px; }
.eyebrow, .panel-label { margin: 0 0 7px; color: var(--blue); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: 0; max-width: 720px; font-size: clamp(2rem, 4vw, 3.6rem); line-height: 1.04; letter-spacing: -.045em; }
h1 em { color: var(--blue); font-style: normal; position: relative; white-space: nowrap; }
h1 em::after { content: ""; position: absolute; height: 9px; left: 0; right: 0; bottom: -2px; background: var(--yellow); opacity: .75; z-index: -1; border-radius: 50%; transform: rotate(-1deg); }
.intro-copy { max-width: 390px; margin: 0 0 3px; color: var(--muted); line-height: 1.7; font-size: .96rem; }

.challenge-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.challenge-tab { display: grid; grid-template-columns: auto 1fr; grid-template-rows: 1fr 1fr; column-gap: 12px; text-align: left; border: 1px solid var(--line); background: rgba(255,255,255,.78); color: var(--ink); border-radius: 14px; padding: 14px 16px; transition: .18s ease; }
.challenge-tab > span { grid-row: 1 / 3; align-self: center; color: #87a0b5; font: 800 .82rem/1 ui-monospace, monospace; }
.challenge-tab strong { font-size: .98rem; }
.challenge-tab small { color: var(--muted); margin-top: 2px; }
.challenge-tab:hover { transform: translateY(-2px); border-color: #8bb7d6; }
.challenge-tab.active { background: var(--navy); color: white; border-color: var(--navy); box-shadow: 0 10px 22px rgba(23, 63, 115, .2); }
.challenge-tab.active small, .challenge-tab.active > span { color: #bfe7f3; }

.workspace { display: grid; grid-template-columns: minmax(230px, .82fr) minmax(360px, 1.25fr) minmax(320px, 1fr); gap: 16px; align-items: stretch; }
.panel { background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); min-height: 610px; overflow: hidden; }
.problem-panel { padding: 25px; display: flex; flex-direction: column; position: relative; }
.problem-panel::before { content: ""; position: absolute; width: 110px; height: 110px; border: 1px solid var(--cyan); border-radius: 50%; right: -58px; top: 90px; box-shadow: 0 0 0 16px rgba(105,217,215,.09), 0 0 0 34px rgba(105,217,215,.05); }
.problem-number { margin-top: 18px; color: var(--blue); font: 700 .8rem/1 ui-monospace, monospace; }
.problem-number span { font-size: 2.2rem; color: var(--ink); }
.problem-panel h2 { margin: 10px 0 15px; font-size: 1.75rem; }
.problem-verse { min-height: 112px; margin: 0; white-space: pre-line; line-height: 1.8; font-family: STKaiti, KaiTi, serif; font-size: 1.05rem; color: #334c63; }
.translation { margin-top: 18px; padding: 16px 15px; border-left: 4px solid var(--yellow); background: #fff9e6; border-radius: 0 12px 12px 0; }
.translation span { font-size: .74rem; font-weight: 800; color: #8a6412; }
.translation p { margin: 6px 0 0; line-height: 1.65; font-size: .9rem; }
.goal-box { display: flex; align-items: flex-start; gap: 10px; margin-top: auto; padding-top: 22px; }
.goal-box svg { width: 23px; fill: none; stroke: var(--blue); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.goal-box b { font-size: .85rem; }
.goal-box p { margin: 4px 0 0; color: var(--muted); font-size: .84rem; line-height: 1.55; }
.secondary-btn { margin-top: 18px; padding: 11px; border-radius: 10px; color: var(--navy); font-weight: 700; border: 1px solid #bdd4e5; background: white; }
.secondary-btn:hover { background: #edf7fc; }

.board-panel { padding: 25px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; }
.panel-heading h2 { margin: 0; font-size: 1.25rem; }
.progress-text { color: var(--blue); font: 800 .83rem/1 ui-monospace, monospace; padding-top: 17px; }
.progress-track { height: 5px; margin: 17px 0 22px; background: #e7eff5; overflow: hidden; border-radius: 9px; }
.progress-track span { display: block; width: 0; height: 100%; background: linear-gradient(90deg, var(--blue), var(--cyan)); transition: width .3s ease; }
.step-list { display: grid; gap: 11px; }
.step-card { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px; min-height: 62px; border: 1px dashed #ccdbe6; border-radius: 13px; padding: 10px 12px; background: #fbfdff; transition: .25s ease; }
.step-card .step-index { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px; background: #eaf1f6; color: #7890a4; font: 800 .75rem/1 ui-monospace, monospace; }
.step-card b { font-size: .9rem; }
.step-card p { margin: 3px 0 0; color: var(--muted); font-size: .79rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.step-card .state { color: #9aabba; font-size: .75rem; font-weight: 700; }
.step-card.active { border-style: solid; border-color: #69a7d1; box-shadow: 0 0 0 3px rgba(72,147,197,.1); background: #f5fbff; }
.step-card.active .step-index { background: var(--blue); color: white; }
.step-card.active .state { color: var(--blue); }
.step-card.done { border-style: solid; border-color: #b4e4dc; background: #f1fbf8; }
.step-card.done .step-index { background: #29a98e; color: white; }
.step-card.done .state { color: #18826d; }
.step-card.locked { opacity: .58; }
.final-flow { margin-top: 5px; }
.success-banner { display: flex; align-items: center; gap: 12px; background: #e7faf5; border: 1px solid #aae1d4; padding: 13px; border-radius: 13px; }
.success-banner > span { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 50%; color: white; background: #22a185; font-weight: 900; }
.success-banner b, .success-banner small { display: block; }
.success-banner small { margin-top: 2px; color: #397465; }
.flowchart-canvas { margin-top: 16px; overflow: auto; background: #f8fbfd; border: 1px solid #d9e6ef; border-radius: 14px; padding: 12px; }
.flowchart-canvas svg { display: block; width: 100%; min-width: 380px; height: auto; }
.scratch-card { display: flex; gap: 11px; align-items: center; margin-top: 14px; padding: 13px; border-radius: 13px; background: #fff7e4; border: 1px solid #f1d992; }
.scratch-icon { font-size: 1.8rem; }
.scratch-card b { font-size: .9rem; }
.scratch-card p { margin: 2px 0 0; font-size: .79rem; color: #725e2d; line-height: 1.45; }

.coach-panel { display: flex; flex-direction: column; }
.coach-head { display: flex; align-items: center; gap: 12px; padding: 22px 23px 17px; border-bottom: 1px solid #e2ebf2; }
.coach-avatar { width: 43px; height: 43px; display: grid; place-items: center; background: var(--navy); color: white; border-radius: 14px 14px 14px 4px; font-weight: 900; box-shadow: 4px 4px 0 var(--yellow); }
.coach-head h2 { margin: 3px 0 0; font-size: 1.05rem; }
.online { color: #308172; font-size: .72rem; }
.online i { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #27b495; }
.chat { flex: 1; max-height: 410px; min-height: 260px; overflow-y: auto; padding: 19px 20px; background: linear-gradient(180deg, #fbfdff, #f6fafd); }
.message { margin-bottom: 14px; animation: pop .22s ease; }
.message small { display: block; color: #91a1af; margin: 0 0 5px 5px; font-size: .7rem; }
.bubble { width: fit-content; max-width: 92%; padding: 11px 13px; border-radius: 5px 15px 15px 15px; background: white; border: 1px solid #dce7ef; box-shadow: 0 5px 16px rgba(30,69,104,.06); font-size: .88rem; line-height: 1.62; white-space: pre-line; }
.message.student { display: flex; align-items: flex-end; flex-direction: column; }
.message.student .bubble { color: white; background: var(--blue); border: 0; border-radius: 15px 5px 15px 15px; }
.message.student small { margin-right: 5px; }
.bubble.good { border-color: #a7ded3; background: #ecfaf6; }
.bubble.notice { border-color: #f2d78d; background: #fff9e9; }
.answer-form { padding: 17px 20px 20px; border-top: 1px solid #e2ebf2; }
.choice-fieldset { min-width: 0; margin: 0 0 15px; padding: 0; border: 0; }
.choice-fieldset legend, .text-label { display: flex; align-items: center; gap: 7px; width: 100%; margin: 0 0 9px; color: var(--blue); font-size: .86rem; font-weight: 800; }
.choice-fieldset legend span, .text-label span { display: inline-grid; place-items: center; width: 21px; height: 21px; border-radius: 7px; color: white; background: var(--blue); font: 800 .72rem/1 ui-monospace, monospace; }
.shape-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.choice-btn { min-height: 42px; border: 1px solid #c9dbe8; border-radius: 10px; color: #37536b; background: #f9fcfe; font-size: .82rem; font-weight: 700; transition: .16s ease; }
.choice-btn:hover { border-color: #76a9cc; background: #f0f8fd; }
.choice-btn:focus-visible { outline: 3px solid rgba(35,104,168,.2); outline-offset: 2px; }
.choice-btn.selected { border-color: var(--blue); color: var(--navy); background: #e8f4fc; box-shadow: inset 0 0 0 1px var(--blue); }
.shape-choice { display: flex; align-items: center; justify-content: flex-start; gap: 10px; padding: 8px 10px; text-align: left; }
.shape-choice .mini-shape { grid-row: auto; width: 31px; height: 20px; flex: 0 0 auto; }
.shape-choice .mini-shape.diamond { width: 22px; height: 22px; margin: 0 5px; }
.text-label { margin-top: 1px; }
.answer-form input { width: 100%; min-height: 46px; margin-bottom: 15px; border: 1px solid #bfd2e1; border-radius: 12px; padding: 11px 12px; color: var(--ink); background: #fbfdff; outline: none; line-height: 1.5; font-size: .9rem; }
.answer-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(35,104,168,.11); }
.arrow-fieldset { margin-bottom: 4px; }
.arrow-options { display: grid; gap: 9px; }
.arrow-group > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .76rem; font-weight: 700; }
.arrow-group > div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.arrow-group .arrow-choice { min-height: 38px; padding: 7px 6px; line-height: 1.25; }
.input-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 11px; }
.hint-btn { border: 0; background: transparent; color: #647d91; font-weight: 700; font-size: .78rem; padding: 7px 0; }
.hint-btn:hover { color: var(--blue); }
.send-btn { border: 0; background: var(--navy); color: white; padding: 10px 14px; border-radius: 10px; font-weight: 800; font-size: .82rem; box-shadow: 0 7px 16px rgba(23,63,115,.2); }
.send-btn:hover { background: #0f315d; transform: translateY(-1px); }
.send-btn span { color: var(--yellow); font-size: 1rem; }
.send-btn:disabled, .hint-btn:disabled, .choice-btn:disabled, input:disabled { cursor: not-allowed; opacity: .62; }
.send-btn.loading { min-width: 132px; animation: thinking 1.1s ease-in-out infinite; }

.shape-key { display: grid; grid-template-columns: repeat(4, 1fr) 1.25fr; gap: 12px; margin-top: 16px; }
.shape-key > div { min-height: 72px; display: grid; grid-template-columns: 43px 1fr; grid-template-rows: 1fr 1fr; align-items: center; column-gap: 12px; padding: 12px 16px; background: rgba(255,255,255,.78); border: 1px solid var(--line); border-radius: 13px; }
.shape-key b { align-self: end; font-size: .82rem; }
.shape-key small { align-self: start; color: var(--muted); font-size: .72rem; }
.mini-shape { grid-row: 1 / 3; width: 39px; height: 24px; border: 2px solid var(--blue); background: #edf7fd; }
.mini-shape.rounded { border-radius: 12px; }
.mini-shape.diamond { width: 29px; height: 29px; transform: rotate(45deg); margin-left: 5px; }
.mini-shape.parallelogram { transform: skew(-16deg); }
.shape-key .branch-rule { background: var(--navy); border-color: var(--navy); color: white; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; }
.shape-key .branch-rule small { color: #c6e6ef; margin-top: 5px; }

@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
@keyframes thinking { 50% { opacity: .65; } }

@media (max-width: 1160px) {
  .workspace { grid-template-columns: .8fr 1.2fr; }
  .coach-panel { grid-column: 1 / -1; min-height: 540px; }
  .chat { max-height: 300px; }
  .shape-key { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  .app-shell { padding: 0 14px 28px; }
  .topbar { height: 74px; }
  .rule-badge { font-size: 0; padding: 11px; }
  .rule-badge span { margin: 0; }
  main { padding-top: 23px; }
  .intro-row { display: block; }
  .intro-copy { margin-top: 16px; }
  .challenge-tabs { grid-template-columns: repeat(2, 1fr); }
  .workspace { grid-template-columns: 1fr; }
  .panel { min-height: auto; }
  .problem-panel { min-height: 520px; }
  .coach-panel { grid-column: auto; }
  .shape-key { grid-template-columns: repeat(2, 1fr); }
  .shape-key .branch-rule { grid-column: 1 / -1; }
}

@media (max-width: 420px) {
  .challenge-tabs { grid-template-columns: 1fr; }
  .challenge-tab { padding: 11px 14px; }
  .shape-key { grid-template-columns: 1fr; }
  .shape-key .branch-rule { grid-column: auto; }
  .input-actions { align-items: stretch; flex-direction: column; }
  .send-btn { width: 100%; }
  .arrow-group > div { grid-template-columns: 1fr; }
}
