/* 赛音小卡 · 样式
   数值取自设计稿 handoff，尽量保持像素级一致。 */

@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('./fonts/baloo2-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('./fonts/baloo2-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* 纸面 */
  --paper: #FFFBF3;
  --shell: #F3EEE4;
  --card: #fff;
  --slot: #F8F4EA;
  /* 文字 */
  --ink: #2A211A;
  --ink-zh: #5E5348;
  /* 主色 */
  --brand: #E4572E;
  --brand-soft: #FFE9D6;
  --track: #EFE7D9;
  /* 星 */
  --star: #F5A623;
  --star-soft: #FFF2DA;
  /* 绿 */
  --green: #1F8A72;
  --green-soft: #DCF0E9;
  /* 紫 */
  --purple: #5B4BD6;
  --purple-soft: #E7E3F7;
  --divider: #FFD9A0;

  --font-cn: 'Noto Sans SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    system-ui, sans-serif;
  --font-en: 'Baloo 2', var(--font-cn);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--shell);
  font-family: var(--font-cn);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  justify-content: center;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  color: inherit;
}

input { font-family: inherit; }
::-webkit-scrollbar { width: 0; height: 0; }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes toastIn {
  0%   { opacity: 0; transform: translateY(10px); }
  12%  { opacity: 1; transform: none; }
  80%  { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-6px); }
}
@keyframes shake {
  10%, 90% { transform: translateX(-3px); }
  30%, 70% { transform: translateX(5px); }
  50%      { transform: translateX(-6px); }
  100%     { transform: none; }
}

/* App 是全屏网页；桌面上收窄居中，避免大屏拉伸变形 */
#app {
  width: 100%;
  max-width: 460px;
  height: 100dvh;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

[hidden] { display: none !important; }

/* ── 登录 ───────────────────────────────────────── */
#login {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 26px;
  padding: 0 34px 60px;
}
.login-title {
  margin: 0;
  font: 900 28px var(--font-cn);
  color: var(--ink);
  text-align: center;
}
.login-box {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box.shake { animation: shake .4s ease; }
#pw {
  width: 100%;
  height: 60px;
  border-radius: 20px;
  background: #fff;
  border: 2px solid rgba(42, 33, 26, .1);
  padding: 0 20px;
  font: 700 20px var(--font-en);
  color: var(--ink);
  letter-spacing: 6px;
  text-align: center;
  outline: none;
}
#pw.error { border-color: var(--brand); }
#pw::placeholder { color: rgba(42, 33, 26, .3); letter-spacing: 0; }
.btn-primary {
  width: 100%;
  height: 60px;
  border-radius: 20px;
  background: var(--brand);
  color: #fff;
  font: 800 18px var(--font-cn);
  box-shadow: 0 8px 18px -6px rgba(228, 87, 46, .7);
}
.login-error {
  height: 16px;
  font: 600 12px var(--font-cn);
  color: var(--brand);
}

/* ── 主体 ───────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
}

/* ── 背单词 ─────────────────────────────────────── */
.study-head {
  padding: 6px 22px 12px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.study-title-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
}
.study-title { font: 900 20px var(--font-cn); color: var(--ink); }
.study-goal  { font: 700 12px var(--font-cn); color: rgba(42, 33, 26, .45); white-space: nowrap; }
.study-goal.done { color: var(--green); }

.progress {
  height: 8px;
  border-radius: 4px;
  background: var(--track);
  overflow: hidden;
}
.progress > i {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: var(--brand);
  transition: width .4s ease;
}

.seg {
  display: flex;
  gap: 6px;
  background: var(--shell);
  border-radius: 14px;
  padding: 4px;
}
.seg button {
  flex: 1;
  height: 34px;
  border-radius: 11px;
  font: 700 12px var(--font-cn);
  background: transparent;
  color: rgba(42, 33, 26, .5);
}
.seg button.on {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 1px 3px rgba(42, 33, 26, .14);
}

.study-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 22px 20px;
  min-height: 0;
}

#card {
  flex: 1;
  width: 100%;
  background: var(--card);
  border-radius: 32px;
  box-shadow: 0 14px 32px -14px rgba(42, 33, 26, .3), 0 0 0 1px rgba(42, 33, 26, .05);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 26px 24px;
  text-align: center;
  min-height: 0;
  position: relative;
  animation: cardIn .32s cubic-bezier(.2, .8, .3, 1);
}
.card-en {
  font: 800 46px/1.1 var(--font-en);
  color: var(--ink);
  letter-spacing: -.5px;
  word-break: break-word;
}
.card-rule {
  width: 44px;
  height: 3px;
  border-radius: 2px;
  background: var(--divider);
  flex: none;
}
.card-zh { font: 700 25px var(--font-cn); color: var(--ink-zh); }
.card-slot {
  font: 700 17px var(--font-cn);
  color: rgba(42, 33, 26, .32);
  padding: 16px 28px;
  border-radius: 18px;
  background: var(--slot);
  border: 2px dashed rgba(42, 33, 26, .14);
}
.card-hint {
  position: absolute;
  bottom: 16px;
  font: 600 11px var(--font-cn);
  color: rgba(42, 33, 26, .28);
}

/* 例句：翻开后才出现。只给英文，不给中文译文。
   字号压在中文释义（25px）之下、但要够孩子看清 */
#card-sentence {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
}
.sentence-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  flex-wrap: wrap;
}
.sentence-en {
  font: 500 19px/1.4 var(--font-en);
  color: rgba(42, 33, 26, .62);
}
.sentence-speak {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  cursor: pointer;
}
.sentence-speak svg { width: 13px; height: 13px; }
.sentence-speak:active { filter: brightness(.94); }

#toast-layer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 200px;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
#toast-layer > div {
  background: var(--ink);
  color: var(--paper);
  font: 700 13px var(--font-cn);
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 8px 20px -8px rgba(42, 33, 26, .6);
  animation: toastIn 1.4s ease forwards;
}

.study-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 18px;
  flex: none;
}
.mastery-scale {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
  gap: 8px;
}
.mastery-scale .edge { font: 600 11px var(--font-cn); color: rgba(42, 33, 26, .4); }
.mastery-scale .now  { font: 700 11px var(--font-cn); color: rgba(42, 33, 26, .55); }

.stars {
  display: flex;
  gap: 8px;
}
.stars button {
  flex: 1;
  height: 52px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
  color: rgba(42, 33, 26, .18);
  background: var(--shell);
  transition: background .18s ease, color .18s ease;
}
.stars button.on { color: var(--star); background: var(--star-soft); }

.study-buttons { display: flex; gap: 10px; }
.btn-speak {
  width: 72px;
  height: 62px;
  border-radius: 22px;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.btn-speak svg { width: 26px; height: 26px; }
.btn-next {
  flex: 1;
  height: 62px;
  border-radius: 22px;
  background: var(--brand);
  color: #fff;
  font: 800 19px var(--font-cn);
  box-shadow: 0 8px 18px -6px rgba(228, 87, 46, .7);
}
.btn-speak:active, .btn-next:active, .btn-primary:active { filter: brightness(.96); }

/* ── 热度榜 ─────────────────────────────────────── */
#view-stats {
  overflow-y: auto;
  padding: 8px 22px 22px;
}
.stats-title { font: 900 22px var(--font-cn); margin-bottom: 4px; }
.stats-sub {
  font: 500 12px var(--font-cn);
  color: rgba(42, 33, 26, .45);
  margin-bottom: 18px;
}
.stat-cards { display: flex; gap: 10px; margin-bottom: 18px; }
.stat-card { flex: 1; border-radius: 20px; padding: 14px 16px; min-width: 0; }
.stat-card .num { font: 800 28px var(--font-en); line-height: 1; }
.stat-card .lab {
  font: 600 11px var(--font-cn);
  color: rgba(42, 33, 26, .55);
  margin-top: 2px;
}
.stat-today  { background: var(--brand-soft); }
.stat-today .num  { color: var(--brand); }
.stat-streak { background: var(--green-soft); }
.stat-streak .num { color: var(--green); }
.stat-total  { background: var(--purple-soft); }
.stat-total .num  { color: var(--purple); }

.panel {
  background: #fff;
  border-radius: 24px;
  padding: 18px 16px;
  box-shadow: 0 1px 3px rgba(42, 33, 26, .08);
}
/* 月份标签与热力图列共用同一套 flex 列，保证在自适应列宽下始终对齐 */
.heat-months {
  display: flex;
  margin-bottom: 8px;
  padding-left: 24px;
}
.heat-months > div {
  flex: 1;
  min-width: 0;
  font: 600 10px var(--font-cn);
  color: rgba(42, 33, 26, .4);
  white-space: nowrap;
}
.heat-grid { display: flex; gap: 6px; }
.heat-days {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 18px;
  flex: none;
}
.heat-days > div {
  height: 14px;
  font: 600 9px/14px var(--font-cn);
  color: rgba(42, 33, 26, .35);
}
.heat-weeks { display: flex; gap: 4px; flex: 1; min-width: 0; }
.heat-week {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 0;
}
.heat-cell { width: 100%; height: 14px; border-radius: 4px; }
/* 图例：每个色块跟着它代表的词数区间，窄屏放不下时自动换行 */
.heat-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 8px;
  margin-top: 14px;
}
.heat-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: 600 10px var(--font-en);
  color: rgba(42, 33, 26, .5);
  white-space: nowrap;
}
.heat-legend i {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  flex: none;
}
.heat-goal {
  margin-top: 10px;
  font: 600 10px var(--font-cn);
  color: rgba(42, 33, 26, .38);
  text-align: center;
}

.recent {
  margin-top: 18px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.recent-title { font: 700 14px var(--font-cn); color: var(--ink); }
.recent-row { display: flex; align-items: center; gap: 10px; }
.recent-row .lab {
  width: 52px;
  flex: none;
  font: 600 11px var(--font-cn);
  color: rgba(42, 33, 26, .5);
}
.recent-row .bar {
  flex: 1;
  height: 12px;
  border-radius: 6px;
  background: var(--shell);
  overflow: hidden;
}
.recent-row .bar > i {
  display: block;
  height: 100%;
  border-radius: 6px;
  background: #3FAE8F;
}
.recent-row .num {
  width: 32px;   /* 目标 30 之后可能出现三位数，比设计稿的 26px 宽一点 */
  flex: none;
  text-align: right;
  font: 700 12px var(--font-en);
  color: var(--ink);
}

/* 今天这一行做出区分：字更大更重、颜色更实，条也略粗 */
.recent-row.today .lab {
  font: 800 13px var(--font-cn);
  color: var(--ink);
}
.recent-row.today .num {
  font: 800 16px var(--font-en);
  color: var(--ink);
}
.recent-row.today .bar {
  height: 15px;
  border-radius: 8px;
}
.recent-row.today .bar > i { border-radius: 8px; }

#btn-lock {
  margin: 18px auto 0;
  display: block;
  font: 600 12px var(--font-cn);
  color: rgba(42, 33, 26, .4);
  padding: 8px 14px;
}

/* ── 生词本 ─────────────────────────────────────── */
.list-head { padding: 8px 22px 12px; flex: none; }
.list-title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.list-title { font: 900 22px var(--font-cn); }
.list-count { font: 600 11px var(--font-cn); color: rgba(42, 33, 26, .45); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters button {
  padding: 8px 13px;
  border-radius: 999px;
  font: 700 12px var(--font-cn);
  background: var(--shell);
  color: rgba(42, 33, 26, .6);
}
.filters button.on { background: var(--ink); color: var(--paper); }

#word-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 22px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.word-row {
  background: #fff;
  border-radius: 20px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 1px 3px rgba(42, 33, 26, .08);
  /* 词库到几千条时，让浏览器跳过屏幕外词条的布局与绘制。
     intrinsic-size 给的是词条高度的估算值，用来撑住滚动条。
     不支持的浏览器会忽略这两行，只是回到全量渲染。 */
  content-visibility: auto;
  contain-intrinsic-size: auto 68px;
}
.word-speak {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.word-speak svg { width: 18px; height: 18px; }
.word-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  text-align: left;
}
.word-en {
  font: 700 19px var(--font-en);
  color: var(--ink);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.word-zh {
  font: 500 12px var(--font-cn);
  color: rgba(42, 33, 26, .5);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.word-stars { display: flex; gap: 2px; flex: none; }
.word-stars button {
  width: 22px;
  height: 28px;
  font-size: 16px;
  line-height: 28px;
  color: rgba(42, 33, 26, .18);
}
.word-stars button.on { color: var(--star); }

.empty {
  padding: 40px 0;
  text-align: center;
  font: 600 13px var(--font-cn);
  color: rgba(42, 33, 26, .35);
}

/* ── 标签栏 ─────────────────────────────────────── */
#tabbar {
  min-height: 76px;
  flex: none;
  border-top: 1px solid rgba(42, 33, 26, .08);
  background: var(--paper);
  display: flex;
  align-items: flex-start;
  padding: 10px 20px 0;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
#tabbar button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: rgba(42, 33, 26, .35);
  padding-top: 2px;
}
#tabbar button.on { color: var(--brand); }
#tabbar svg { width: 20px; height: 20px; }
#tabbar span { font: 700 11px var(--font-cn); }
