* { box-sizing: border-box; }

:root{
  --page-bg-1: #F7F9FF;
  --page-bg-2: #E8EBF1; /* Android: page_background */
  --text: #15233F;
  --muted: #56627A;
  --card: #FDFEFE;
  --card-soft: #F9FAFE;
  --line: rgba(21, 35, 63, 0.12);
  --shadow: 0 20px 64px rgba(21, 35, 63, 0.10);
  /* Android-like saturation (still gentle) */
  --blue: #2A57DF;
  --blue-ink: #1F3D6B;
  /* bluer (less purple) accents */
  --accent-soft: rgba(59, 130, 246, 0.20);
  --accent-warm: rgba(255, 180, 105, 0.22);
  --learned-dot: rgba(34, 197, 94, 0.80);
  --chip: rgba(21, 35, 63, 0.08);
  --chip-active: rgba(42, 87, 223, 0.14);
  --chip-text: #8A93A8;
  --chip-text-active: #5C657A;
  --bottom-bar: rgba(255,255,255,0.85);
  --bottom-input: rgba(255,255,255,0.92);
  --bottom-solid: rgba(42, 87, 223, 0.14);
  --writer-stroke: #111111;
  --writer-base: #9CA3AF; /* solid gray so red grid won't show through */
  --writerSize: 220px;
  color-scheme: light;
}

html[data-theme="dark"]{
  --page-bg-1: #0C0E14; /* Android: page_background_dark */
  --page-bg-2: #131826;
  --text: #E8ECF5;
  --muted: #AAB2C3;
  --card: rgba(255,255,255,0.06);
  --card-soft: rgba(255,255,255,0.05);
  --line: rgba(232, 236, 245, 0.10);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  --chip: rgba(255,255,255,0.08);
  --chip-active: rgba(42, 87, 223, 0.26);
  --chip-text: #AAB2C3;
  --chip-text-active: #E8ECF5;
  --bottom-bar: rgba(12,14,20,0.70);
  --bottom-input: rgba(19,24,38,0.88);
  --bottom-solid: rgba(42, 87, 223, 0.22);
  --writer-stroke: #F3F6FF;
  --writer-base: #6B7280;
  --writerSize: 220px;
  --learned-dot: rgba(34, 197, 94, 0.86);
  color-scheme: dark;
}

html, body{
  height: 100%;
}

body{
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background-color: var(--page-bg-2);
  background:
    radial-gradient(1200px 600px at 10% 0%, rgba(59, 130, 246, 0.18) 0%, rgba(59, 130, 246, 0) 60%),
    radial-gradient(900px 520px at 92% 12%, rgba(255, 180, 105, 0.14) 0%, rgba(255, 180, 105, 0) 60%),
    linear-gradient(180deg, var(--page-bg-1) 0%, var(--page-bg-2) 100%);
}

.root{
  min-height: 100vh;
  width: 100%;
  /* Responsive container width */
  max-width: 1040px;
  margin: 0 auto;
  position: relative;
  /* Default: treat header + cards + input as one stack */
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.titleBar{
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 6px;
  background: transparent;
}

.titleBlock{
  flex: 1;
  min-width: 0;
}

.titleRow{
  display: flex;
  align-items: center;
  gap: 10px;
}

.appLogo{
  width: 46px;
  height: 46px;
  margin-top: 4px;
  border-radius: 10px;
  object-fit: cover;
  box-shadow: 0 10px 24px rgba(21, 35, 63, 0.10);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}
html[data-theme="dark"] .appLogo{
  box-shadow: 0 16px 30px rgba(0,0,0,0.55);
}

.titleText{
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 0.2px;
  color: var(--text);
}

.iconBtn{
  width: 48px;
  height: 48px;
  border: 0;
  padding: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.55);
  color: var(--text);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease;
}
.iconBtn:active{ transform: scale(0.98); }
html[data-theme="dark"] .iconBtn{ background: rgba(255,255,255,0.06); }
.iconBtn:hover{
  background: color-mix(in srgb, var(--blue) 10%, rgba(255,255,255,0.55));
}
html[data-theme="dark"] .iconBtn:hover{
  background: color-mix(in srgb, var(--blue) 12%, rgba(255,255,255,0.08));
}

.iconBtn .icon{
  display: inline-block;
  font-size: 18px;
  line-height: 1;
}

.topNavFadeOverlay{
  display: none;
}
html[data-theme="dark"] .topNavFadeOverlay{
  display: none;
}

.contentScroll{
  padding: 4px 14px 0;
}

.contentInner{
  padding-bottom: 0;
}

.twoColLayout{
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 12px;
  align-items: stretch;
}

.leftCol, .rightCol{
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.card{
  background: var(--card);
  border-radius: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-top: 10px;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.card:hover{
  transform: translateY(-1px);
  box-shadow: 0 24px 72px rgba(21, 35, 63, 0.12);
}
html[data-theme="dark"] .card:hover{
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.60);
}
.dailyTaskCard{ background: var(--card-soft); }
.dailyHistoryCard{ background: var(--card); }
.dailyHistoryCard{
  /* Keep layout tidy even when empty */
  min-height: 260px;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto; /* grow to match right column height */
}

.rightMainCard{
  /* merged right column card */
  flex: 1 1 auto;
}

.rightMainDivider{
  height: 1px;
  background: var(--line);
  margin: 18px 0;
}

.rightMainBottom .fieldGroup:first-child{
  margin-top: 0;
}

.dailyHistoryCard .cardHeaderRow{
  flex: 0 0 auto;
}

.cardHeaderRow{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 4px 0 14px;
}

.dailyHistoryList{
  flex: 1 1 auto;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.historyRow{
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: start;
}

.historyDate{
  font-size: 12px;
  font-weight: 800;
  color: color-mix(in srgb, var(--muted) 86%, transparent);
  letter-spacing: 0.2px;
  padding-top: 4px;
  white-space: nowrap;
}

.historyToday{
  display: block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 800;
  color: color-mix(in srgb, var(--muted) 74%, transparent);
  letter-spacing: 0.2px;
}

.historyMarks{
  font-size: 14px;
  line-height: 1.4;
  color: color-mix(in srgb, var(--text) 82%, transparent);
}

.historyMarksGrid{
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

/* Reuse today's cell style, but smaller */
.dailyCell.historyCell{
  height: 44px;
  border-radius: 12px;
}

.dailyCell.historyCell .dailyChar{
  font-size: 16px;
}

.dailyCell.historyCell .dailyCheck{
  width: 4px;
  height: 4px;
  bottom: 6px;
}

.cardTitle{
  font-size: 15px;
  color: var(--text);
  opacity: 0.92;
}

.muted{ color: var(--muted); }

.countBtns{
  display: flex;
  gap: 6px;
}

.historyBtn{
  padding: 0 10px;
  width: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.historyIcon{
  width: 16px;
  height: 16px;
  display: block;
  color: color-mix(in srgb, var(--muted) 82%, transparent);
}
.chipBtn.isActive .historyIcon{
  color: color-mix(in srgb, var(--blue-ink) 86%, transparent);
}

.chipBtn{
  width: 34px;
  height: 28px;
  border-radius: 12px;
  border: 0;
  background: var(--chip);
  color: var(--chip-text);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, color 140ms ease;
}
.chipBtn.isActive{
  background: var(--accent-soft);
  color: var(--chip-text-active);
}
.chipBtn:active{ transform: scale(0.98); }

.dailyGrid{
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.dailyCell{
  height: 56px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.48);
  display: grid;
  place-items: center;
  position: relative;
  cursor: pointer;
  user-select: none;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}
html[data-theme="dark"] .dailyCell{
  background: rgba(255,255,255,0.04);
}
.dailyCell:hover{
  border-color: color-mix(in srgb, var(--blue) 28%, var(--line));
  box-shadow: 0 10px 28px rgba(21, 35, 63, 0.08);
}
.dailyCell:active{
  transform: translateY(0.5px) scale(0.99);
}

.dailyChar{
  font-size: 18px;
  font-weight: 800;
  color: var(--blue-ink);
}
html[data-theme="dark"] .dailyChar{ color: #BFD2FF; }

.dailyCheck{
  position: absolute;
  left: 50%;
  bottom: 8px;
  top: auto;
  right: auto;
  transform: translateX(-50%);
  width: 5px;
  height: 5px;
  border-radius: 999px;
  display: block;
  background: var(--learned-dot);
  border: 0;
  box-shadow: none;
  z-index: 2;
  pointer-events: none;
}
html[data-theme="dark"] .dailyCheck{
  box-shadow: none;
}

.panelRow{
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: start;
}

.strokeContainer{
  min-width: 0;
  width: var(--writerSize);
}

.writerFrame{
  position: relative;
  height: 228px;
  width: var(--writerSize);
  border-radius: 18px;
  background: rgba(255,255,255,0.35);
  border: 1px solid var(--line);
  overflow: hidden;
}
html[data-theme="dark"] .writerFrame{
  background: rgba(255,255,255,0.04);
}

.writer{
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--writerSize);
  height: var(--writerSize);
  transform: translate(-50%, -50%);
  z-index: 3;
}

.writerBase{
  z-index: 2;
  pointer-events: none;
  user-select: none;
}

.tianziGrid{
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--writerSize);
  height: var(--writerSize);
  transform: translate(-50%, -50%);
  z-index: 1;
  pointer-events: none;
}
.tianziGrid line{
  stroke: rgba(220, 38, 38, 0.26); /* Android-like red grid */
  stroke-width: 1.15;
}
html[data-theme="dark"] .tianziGrid line{
  stroke: rgba(248, 113, 113, 0.24);
}

.ghostBtn{
  margin-top: 10px;
  width: 100%;
  height: 36px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.infoColumn{
  min-width: 0;
  padding: 6px 2px 0;
}

.fieldLabel{
  font-size: 14px;
  color: var(--muted);
}

.pinyinRow{
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* Avoid crowding on narrow screens: move icon to next line if needed */
.pinyinRow .roundIconBtn{
  flex: 0 0 auto;
}

.bigValue{
  font-size: 32px;
  font-weight: 900;
  color: var(--text);
  line-height: 1.18;
  word-break: break-word;
}

.infoColumn .bigValue + .bigValue{
  margin-top: 10px;
}

.fieldLabel{
  margin-top: 6px;
}

.kaiti{
  font-family: "STKaiti", "Kaiti SC", "KaiTi", "楷体", "Noto Serif SC", serif;
}

.roundIconBtn{
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 140ms ease, filter 140ms ease;
}
.roundIconBtn:active{ transform: scale(0.98); }
.roundIconBtn:hover{ filter: brightness(1.03); }

.iconImg{
  width: 18px;
  height: 18px;
  display: block;
  object-fit: contain;
}

/* Per-button tuning */
#speakBtn .iconImg{
  width: 14px;
  height: 14px;
}

#randomBtn .iconImg{
  width: 36px;
  height: 36px;
}

.spacer{ height: 12px; }

.fieldGroup + .fieldGroup{ margin-top: 26px; }

.wordsValue{
  margin-top: 8px;
  font-size: 18px;
  line-height: 1.35;
  color: var(--text);
}

.bottomSpacer{
  display: none;
}

.bottomInputBar{
  position: static;
  padding: 14px 10px 0;
  z-index: 30;
  backdrop-filter: none;
  background: none;
}

.bottomBarInner{
  max-width: 1040px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bottom-solid);
  box-shadow: 0 18px 70px rgba(21, 35, 63, 0.14);
}
html[data-theme="dark"] .bottomBarInner{
  box-shadow: 0 18px 70px rgba(0,0,0,0.55);
}

.hanziInput{
  flex: 1;
  height: 50px;
  border-radius: 999px;
  border: 0;
  padding: 0 16px;
  font-size: 24px;
  outline: none;
  color: var(--text);
  background: rgba(255,255,255,0.70);
}
html[data-theme="dark"] .hanziInput{
  background: rgba(255,255,255,0.06);
}

.hanziInput::placeholder{
  color: color-mix(in srgb, var(--muted) 72%, transparent);
}

.cameraBtn{
  width: 50px;
  height: 50px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.55);
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--blue);
  font-size: 18px;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
}
html[data-theme="dark"] .cameraBtn{
  background: rgba(255,255,255,0.06);
  color: #9DB7FF;
}
.cameraBtn:hover{
  border-color: color-mix(in srgb, var(--blue) 28%, var(--line));
}
.cameraBtn:active{
  transform: scale(0.98);
}

.randomBtn{
  width: auto;
  min-width: 86px;
  justify-content: center;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.70);
  border: 0;
  box-shadow: 0 10px 28px rgba(21, 35, 63, 0.10);
}

.randomBtn:hover{
  background: rgba(255,255,255,0.85);
}
html[data-theme="dark"] .randomBtn:hover{
  background: rgba(255,255,255,0.10);
}
html[data-theme="dark"] .randomBtn{
  background: rgba(255,255,255,0.08);
  box-shadow: 0 14px 34px rgba(0,0,0,0.45);
}

/* Keep 1280-ish screens compact ("精致") */
@media (min-width: 900px) and (max-width: 1439px){
  .root{
    max-width: 980px;
  }
  .bottomBarInner{
    max-width: 980px;
  }
  .twoColLayout{
    grid-template-columns: 360px 1fr;
    gap: 12px;
  }
}

@media (max-width: 760px){
  .twoColLayout{ grid-template-columns: 1fr; }
  /* Keep strokes + pinyin side-by-side on phones */
  :root{ --writerSize: 170px; }
  .panelRow{
    grid-template-columns: var(--writerSize) 1fr;
    gap: 12px;
    align-items: start;
  }
  .writerFrame{
    height: calc(var(--writerSize) + 8px);
  }
  .bigValue{
    font-size: 28px;
  }
  .pinyinRow{
    flex-wrap: nowrap;
    gap: 10px;
  }
  #pinyinOut{
    min-width: 0;
    word-break: break-word;
  }
  .topNavFadeOverlay{ display: none; }
  /* Hide inline history on phones (use sheet instead) */
  .dailyHistoryCard{ display: none; }
}

/* Overlay input bar when screen is short or mobile (prevents layout squeeze) */
@media (max-width: 760px), (max-height: 760px){
  .root{
    display: block;
  }
  .contentInner{
    padding-bottom: 168px; /* leave room for fixed input */
  }
  .bottomSpacer{
    display: block;
    height: 120px;
  }
  .bottomInputBar{
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0 10px 24px;
    backdrop-filter: blur(12px);
    /* Use page background tones to avoid visible "color seam" while scrolling */
    background: linear-gradient(
      180deg,
      rgba(0,0,0,0) 0%,
      color-mix(in srgb, var(--page-bg-2) 35%, transparent) 45%,
      color-mix(in srgb, var(--page-bg-2) 88%, transparent) 100%
    );
  }
}

/* Mobile history bottom sheet */
.sheetBackdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.32);
  z-index: 50;
}
html[data-theme="dark"] .sheetBackdrop{
  background: rgba(0,0,0,0.55);
}

.historySheet{
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  height: 56vh;
  max-height: 560px;
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  background: var(--card);
  border: 1px solid var(--line);
  box-shadow: 0 -24px 80px rgba(21, 35, 63, 0.20);
  padding: 10px 14px 14px;
}
html[data-theme="dark"] .historySheet{
  box-shadow: 0 -28px 90px rgba(0,0,0,0.65);
}

.sheetHandle{
  width: 48px;
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 30%, transparent);
  margin: 4px auto 10px;
}

.sheetHeader{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.sheetTitle{
  font-size: 14px;
  font-weight: 900;
  color: var(--text);
}
.sheetCloseBtn{
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.70);
  color: color-mix(in srgb, var(--text) 80%, transparent);
  font-weight: 900;
  cursor: pointer;
}
html[data-theme="dark"] .sheetCloseBtn{
  background: rgba(255,255,255,0.08);
  color: color-mix(in srgb, var(--text) 88%, transparent);
}
.sheetCloseBtn:active{ transform: scale(0.98); }

.sheetBody{
  height: calc(56vh - 110px);
  max-height: 420px;
  overflow: auto;
  padding-right: 2px;
}

@media (min-width: 761px){
  /* On larger screens, keep sheet hidden even if toggled */
  .sheetBackdrop, .historySheet{ display: none !important; }
  .historyBtn{ display: none; }
}

/* Large-screen tuning: keep 1440 still compact; upscale only on very large screens */
@media (min-width: 1680px){
  .root{
    max-width: 1200px;
  }
  .bottomBarInner{
    max-width: 1200px;
  }

  .twoColLayout{
    width: 100%;
    grid-template-columns: 420px 1fr;
    gap: 18px;
  }

  .card{
    padding: 22px;
  }

  :root{
    --writerSize: 260px;
  }
}