:root {
  --top: #0d2724;
  --hero: #12352f;
  --hero-ink: #eaf3ee;
  --hero-soft: #b9d3c7;
  --mint: #a6e2c3;
  --grid: #7faf9c;

  --bg: #eef4f0;
  --panel: #ffffff;
  --panel-2: #e5efe9;
  --line: #d8e3dd;
  --ink: #142420;
  --muted: #5b6d66;
  --accent: #17574a;
  --accent-ink: #ffffff;

  --up: #1d7a4b;
  --down: #b5372e;

  --tag-us-bg: #e3ecf8;  --tag-us: #2b5a96;
  --tag-tw-bg: #efe5f6;  --tag-tw: #6b3d8e;
  --tag-gl-bg: transparent; --tag-gl: #1d6b4f;
  --tag-ch-bg: #fbeedd;  --tag-ch: #8a5413;

  --serif: Georgia, "Songti TC", "Noto Serif TC", "PMingLiU", serif;
  --sans: system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --top: #08191a;
    --hero: #0d2623;
    --bg: #0f1716;
    --panel: #162220;
    --panel-2: #1c2c29;
    --line: #2a3b37;
    --ink: #e4eee9;
    --muted: #96aaa2;
    --accent: #5fbf98;
    --accent-ink: #08191a;
    --up: #4fc48a;
    --down: #f07a6f;
    --tag-us-bg: #1d2d42;  --tag-us: #9cc0f0;
    --tag-tw-bg: #2d2238;  --tag-tw: #d2b1ee;
    --tag-gl: #7fd3ac;
    --tag-ch-bg: #3a2a16;  --tag-ch: #f0c184;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
}
a { color: inherit; }
button, input { font: inherit; color: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---- top bar ---- */
.top { background: var(--top); color: var(--hero-ink); }
.top .wrap { display: flex; align-items: center; justify-content: space-between; height: 62px; }
.brand { font-weight: 700; letter-spacing: .14em; font-size: 14px; display: flex; gap: 10px; align-items: center; }
.brand span { color: var(--mint); }
.tabs { display: flex; gap: 4px; }
.tabs a {
  display: flex; flex-direction: column; align-items: center; line-height: 1.15;
  padding: 7px 13px; border-radius: 10px; text-decoration: none; color: #cfe2d9;
}
.tabs a b { font-size: 15px; font-weight: 600; }
.tabs a i { font-style: normal; font-size: 11px; opacity: .75; }
.tabs a:hover { background: rgba(255,255,255,.07); }
.tabs a[aria-current="page"] { background: var(--hero-ink); color: var(--top); }

/* ---- hero ---- */
.hero { background: var(--hero); color: var(--hero-ink); overflow: hidden; }
.hero .wrap { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; align-items: center; min-height: 250px; position: relative; }
.hero svg { grid-column: 2; grid-row: 1; width: 100%; height: 100%; max-height: 268px; align-self: end; }
.hero .copy { grid-column: 1; grid-row: 1; padding: 36px 0; }
.kicker { margin: 0 0 6px; font-size: 13px; font-weight: 600; letter-spacing: .08em; color: var(--hero-soft); }
.hero h1 { font-family: var(--serif); font-weight: 400; font-size: clamp(44px, 7vw, 78px); line-height: 1.08; margin: 0 0 14px; letter-spacing: .02em; }
.hero .intro { margin: 0; max-width: 34em; color: #d5e5dd; font-size: 17px; }
.hero .intro.en { font-size: 15px; color: var(--hero-soft); margin-top: 2px; }
.hero .tip { margin: 12px 0 0; font-size: 13.5px; color: var(--hero-soft); }
.term-demo { border-bottom: 1.5px dotted var(--accent); }
.hero .term-demo { border-color: var(--mint); color: var(--hero-ink); }
/* 只有「行情」顯示完整主圖，其他分頁縮成一條標題 */
body:not(.v-market) .hero .wrap { min-height: 0; }
body:not(.v-market) .hero svg, body:not(.v-market) .hero .intro, body:not(.v-market) .hero .tip { display: none; }
body:not(.v-market) .hero .copy { padding: 18px 0 16px; }
body:not(.v-market) .hero h1 { font-size: clamp(30px, 4.4vw, 40px); margin: 0; }

main { padding: 26px 0 40px; }

/* ---- panels ---- */
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px 20px; margin-bottom: 22px;
}
.panel h2 { font-family: var(--serif); font-size: clamp(24px, 3.4vw, 31px); margin: 0 0 4px; font-weight: 700; }
.sub { color: var(--muted); font-size: 13.5px; margin: 0 0 12px; }
.note { color: var(--muted); font-size: 13px; margin: 12px 0 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 14.5px; padding: 9px 6px; border-bottom: 1px solid var(--line); }
td { padding: 11px 6px; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.co { font-weight: 700; }
.sym { color: var(--muted); }
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--muted); }
.session {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--panel-2); color: var(--accent); margin-right: 6px; vertical-align: 1px;
}
.session.live::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--up); margin-right: 5px; vertical-align: 1px; animation: blink 2s infinite; }
@keyframes blink { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .session.live::before { animation: none; } }
.skeleton { color: var(--muted); }

/* ---- simulator ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 14px 0 16px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 12px 14px; }
.stat b { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
.stat span { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sim input {
  width: 100%; max-width: 130px; text-align: right; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  font-variant-numeric: tabular-nums;
}
.sim input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.sim input.edited { border-color: var(--accent); }
.sim td.pl { min-width: 96px; }
.btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 8px 13px; cursor: pointer; font-size: 14.5px;
}
.btn:hover { border-color: var(--accent); }
.sim .actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- news ---- */
.newsgrid { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 32px; align-items: start; }
.newshead { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.newshead h2 { font-family: var(--serif); font-size: clamp(26px, 3.6vw, 34px); margin: 0; font-weight: 400; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.filters button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 8px;
  padding: 7px 13px; cursor: pointer; font-size: 15px;
}
.filters button[data-cat="us"] { background: var(--tag-us-bg); color: var(--tag-us); border-color: transparent; }
.filters button[data-cat="tw"] { background: var(--tag-tw-bg); color: var(--tag-tw); border-color: transparent; }
.filters button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.search {
  width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); margin-bottom: 8px;
}
.checked { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.list { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.item { padding: 16px 20px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.tags { display: flex; gap: 6px; margin-bottom: 5px; }
.tag { font-size: 12px; font-weight: 600; padding: 1px 7px; border-radius: 5px; }
.tag.us { background: var(--tag-us-bg); color: var(--tag-us); }
.tag.tw { background: var(--tag-tw-bg); color: var(--tag-tw); }
.tag.global { background: var(--tag-gl-bg); color: var(--tag-gl); padding-left: 2px; }
.tag.chips { background: var(--tag-ch-bg); color: var(--tag-ch); }
.item h3 { margin: 0; font-size: 17.5px; line-height: 1.4; font-weight: 700; }
.item h3 a { text-decoration: none; }
.item h3 a:hover { text-decoration: underline; }
.item .tr { margin: 3px 0 0; color: var(--ink); font-size: 15px; }
.item .tr.none { color: var(--muted); font-size: 13px; }
.item .meta { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.empty { padding: 26px 20px; color: var(--muted); }
.more { display: block; width: 100%; border: 0; border-top: 1px solid var(--line); background: var(--panel-2); padding: 12px; cursor: pointer; font-size: 15px; }

aside { position: sticky; top: 16px; }
aside .box { background: var(--panel-2); border-radius: 12px; padding: 18px 20px; }
aside h3 { font-family: var(--serif); margin: 0 0 10px; font-size: 20px; }
aside ul { list-style: none; padding: 0; margin: 0 0 14px; }
aside li { border-bottom: 1px solid var(--line); }
aside li a { display: block; padding: 9px 0; font-weight: 700; color: var(--accent); text-decoration: none; }
aside li a:hover { text-decoration: underline; }
aside p { color: var(--muted); font-size: 13.5px; margin: 0; }

footer { color: var(--muted); font-size: 13px; padding: 10px 0 40px; }

/* ---- login ---- */
.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--hero); color: var(--hero-ink); padding: 20px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card .brand { justify-content: center; margin-bottom: 18px; }
.login-card h1 { font-family: var(--serif); font-weight: 400; font-size: 46px; margin: 0 0 22px; }
.login-card label { display: block; color: var(--hero-soft); margin-bottom: 10px; }
.login-card input {
  width: 100%; padding: 13px 14px; border-radius: 10px; border: 1px solid #4e6f66;
  background: #0d2724; color: var(--hero-ink); font-size: 18px; text-align: center; letter-spacing: .1em;
}
.login-card button {
  margin-top: 14px; width: 100%; padding: 12px; border: 0; border-radius: 999px;
  background: var(--hero-ink); color: var(--top); font-weight: 700; font-size: 16px; cursor: pointer;
}
.login-card .err { min-height: 1.5em; color: #ffb4a8; margin: 10px 0 0; }

/* ---- small screens ---- */
@media (max-width: 860px) {
  .cards { grid-template-columns: 1fr; }
  .newsgrid { grid-template-columns: 1fr; gap: 20px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .top .wrap { flex-direction: column; align-items: stretch; height: auto; padding-top: 10px; padding-bottom: 8px; gap: 8px; }
  .brand { font-size: 12px; }
  .tabs { justify-content: space-between; }
  .tabs a { flex: 1; padding: 6px 4px; }
  .hero .tip, .hero .intro.en { display: none; }
  .lesson .pair { grid-template-columns: 1fr; gap: 4px; }
  .sheet-card { padding: 22px 18px 26px; }
  .hero .wrap { grid-template-columns: 1fr; min-height: 0; }
  .hero svg { grid-column: 1; opacity: .35; position: absolute; inset: auto 0 0 auto; width: 100%; height: 70%; }
  .hero .copy { position: relative; padding: 30px 0 34px; }
  .panel { padding: 18px 14px; }
  .quotes .sym { display: none; }
  .quotes td, .quotes th { padding-left: 4px; padding-right: 4px; }
  .sim .scroll { overflow-x: auto; margin: 0 -14px; padding: 0 14px; }
  .sim table { min-width: 560px; }
  .item { padding: 14px 16px; }
  .stat span { font-size: 18px; }
}

/* ================= 學習版 additions ================= */

i[lang="en"], .bi i { font-style: normal; }
h2 i[lang="en"], h3 i[lang="en"], .btn i, .filters i, .tabs i { color: var(--muted); font-weight: 400; font-size: .72em; margin-left: 4px; }
.filters button[aria-pressed="true"] i { color: inherit; opacity: .8; }

/* bilingual labels */
.bi { display: inline-flex; flex-direction: column; line-height: 1.2; text-align: inherit; }
.num .bi { align-items: flex-end; }
.bi b { font-weight: 600; }
.bi i { font-size: 12px; color: var(--muted); font-weight: 400; }
.stat .bi { margin-bottom: 4px; }
.stat .bi b { font-size: 13px; color: var(--muted); }
.stat > span { display: block; }

/* tappable terms */
button.term {
  font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0;
  cursor: pointer; text-align: inherit; border-bottom: 1.5px dotted var(--accent);
  border-radius: 0; line-height: inherit;
}
button.term:hover, button.term:focus-visible { background: var(--panel-2); outline: none; }
button.term.bi { border-bottom: 0; }
button.term.bi b { border-bottom: 1.5px dotted var(--accent); }
.hero button.term { border-color: var(--mint); }
.say {
  border: 0; background: none; cursor: pointer; font-size: .85em; padding: 0 2px;
  vertical-align: baseline; opacity: .7; line-height: 1;
}
.say:hover { opacity: 1; }
.session.term {
  border: 0; cursor: pointer; font: inherit; font-size: 12px; font-weight: 600;
  background: var(--panel-2); color: var(--accent); padding: 1px 9px; border-radius: 999px; margin-right: 8px;
}
.session i { font-weight: 400; opacity: .8; }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.toolbar .search { flex: 1 1 260px; margin: 0; }
.switch { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); cursor: pointer; user-select: none; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

/* hide Chinese for self-testing */
.hide-zh .zhx:not(.show) {
  color: transparent !important; background: var(--panel-2); border-radius: 5px;
  cursor: pointer; user-select: none; position: relative;
}
.hide-zh .zhx:not(.show) * { visibility: hidden; }
.hide-zh .zhx:not(.show)::after {
  content: "點一下看中文"; position: absolute; left: 8px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 12px; white-space: nowrap; visibility: visible;
}

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: 14px; line-height: 1.3;
}
.chip:hover { border-color: var(--accent); }
.chip .zhx { color: var(--muted); }
.chip small { color: var(--accent); font-weight: 700; }
.today { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.today h3 { margin: 0 0 10px; font-size: 15px; }
.pill { background: var(--panel-2); border-radius: 8px; padding: 8px 12px; font-size: 14px; margin: 0 0 8px; display: flex; gap: 8px; align-items: center; }
.pill[hidden] { display: none; }
.pill button { margin-left: auto; border: 0; background: none; cursor: pointer; font-size: 15px; color: var(--muted); }

/* news items */
.item h3 { font-weight: 700; }
.item h3 .say { font-size: .8em; }
.item .tr .none, .item .tr.none { color: var(--muted); font-size: 13px; }
.item .meta a { color: var(--accent); text-decoration: none; }
.item .meta a:hover { text-decoration: underline; }
aside .box + .box { margin-top: 14px; }
aside .box p a { color: var(--accent); }
.sub a { color: var(--accent); }

/* pop-up term card */
.sheet { position: fixed; inset: 0; z-index: 50; display: grid; place-items: end center; }
.sheet[hidden] { display: none; }
.sheet-bg { position: absolute; inset: 0; background: rgba(5, 20, 18, .45); }
.sheet-card {
  position: relative; width: min(560px, 100%); max-height: 86vh; overflow: auto;
  background: var(--panel); color: var(--ink); border-radius: 18px 18px 0 0;
  padding: 24px 26px 30px; box-shadow: 0 -10px 40px rgba(0,0,0,.25);
}
@media (min-width: 700px) {
  .sheet { place-items: center; }
  .sheet-card { border-radius: 18px; }
}
.sheet-x { position: absolute; right: 12px; top: 10px; border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); padding: 6px 10px; }
.sh-cat { margin: 0 0 4px; font-size: 12.5px; color: var(--muted); }
.sheet h3 { font-family: var(--serif); font-size: 28px; margin: 0; padding-right: 30px; }
.sh-zh { font-size: 19px; font-weight: 700; color: var(--accent); margin: 2px 0 12px; }
.sh-def { margin: 0 0 8px; font-size: 16px; }
.sh-def.en { color: var(--muted); font-size: 15px; }
.sheet blockquote { margin: 14px 0 0; padding: 10px 14px; background: var(--panel-2); border-radius: 10px; }
.sheet blockquote p { margin: 0; }
.sheet blockquote p + p { color: var(--muted); margin-top: 3px; font-size: 14.5px; }
.sh-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.btn { text-decoration: none; display: inline-block; color: var(--ink); }
body.sheet-open { overflow: hidden; }

/* lessons */
.lessons { list-style: none; padding: 0; margin: 10px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.lessons a {
  display: flex; gap: 14px; align-items: flex-start; text-decoration: none; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px; height: 100%;
}
.lessons a:hover { border-color: var(--accent); }
.lessons .n {
  flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700;
}
.lessons b { display: block; font-size: 16.5px; }
.lessons i { display: block; color: var(--muted); font-size: 14px; }
.lessons small { display: block; color: var(--accent); font-size: 13px; margin-top: 3px; }
.crumb { font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.crumb a { color: var(--accent); }
.lesson h2 { font-size: clamp(26px, 4vw, 34px); margin-bottom: 2px; }
.lesson-zh { font-size: 19px; color: var(--accent); font-weight: 700; margin: 0 0 12px; display: inline-block; min-width: 8em; }
.lesson .switch { display: flex; margin: 0 0 14px; }
.lesson .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; padding: 14px 0; border-top: 1px solid var(--line); }
.lesson .pair p { margin: 0; font-size: 16.5px; line-height: 1.7; }
.lesson .pair p[lang="en"] { font-size: 17px; }
.lesson .pair .zhx { color: #33463f; }
@media (prefers-color-scheme: dark) { .lesson .pair .zhx { color: #c3d3cc; } }
.pair-h { margin: 18px 0 0; padding-top: 14px; border-top: 1px solid var(--line); font-size: 17px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.pair-h .zhx { color: var(--muted); }
.lesson-terms { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.lesson-terms h3 { font-size: 15px; margin: 0 0 10px; }
.lesson-nav { display: flex; justify-content: space-between; gap: 10px; margin-top: 20px; }

/* glossary */
.w-group { font-family: var(--serif); font-size: 21px; margin: 26px 0 10px; }
.w-group:first-child { margin-top: 10px; }
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; scroll-margin: 90px; }
.card h4 { margin: 0; font-size: 19px; font-family: var(--serif); }
.c-zh { margin: 1px 0 8px; color: var(--accent); font-weight: 700; display: inline-block; min-width: 5em; }
.c-def { margin: 0 0 6px; font-size: 15px; }
.c-def.en { color: var(--muted); font-size: 14.5px; }
.c-ex { margin: 8px 0 0; padding: 8px 12px; background: var(--panel-2); border-radius: 8px; font-size: 14.5px; }
.c-ex span { display: block; }
.c-ex .zhx { color: var(--muted); margin-top: 2px; }
.card.flash { animation: flash 1.6s ease-out; }
@keyframes flash { 0%, 30% { border-color: var(--accent); box-shadow: 0 0 0 3px var(--panel-2); } 100% { box-shadow: none; } }
#view-words .filters { margin-top: 6px; }

/* phones: English above Chinese, one column (after the base rules so it wins) */
@media (max-width: 640px) {
  .lesson .pair { grid-template-columns: 1fr; gap: 6px; }
  .lesson .pair p, .lesson .pair p[lang="en"] { font-size: 16px; }
  .lessons { grid-template-columns: 1fr; }
}
