/* ===== 多邻国风格设计系统 =====
   核心特征：纯白背景大量留白 / 扁平明快色块 / 粗圆角
   按钮与卡片带“厚底边”(hard bottom edge) 的按压感 / 选中态浅蓝填充 */

:root {
  --blue: #1cb0f6;        /* 主色（多邻国的 macaw blue） */
  --blue-edge: #1899d6;   /* 按钮厚底边 */
  --blue-light: #ddf4ff;  /* 选中态浅蓝填充 */
  --blue-border: #84d8ff; /* 选中态描边 */
  --green: #58cc02;
  --green-edge: #58a700;
  --green-light: #d7ffb8;
  --red: #ff4b4b;
  --red-light: #ffdfe0;
  --red-border: #ffb2b2;
  --yellow: #ffc800;
  --text: #3c3c3c;
  --muted: #afafaf;
  --border: #e5e5e5;
  --bg: #ffffff;
  --radius: 16px;
  --font: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  width: 100%;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
}
body:has(#screen-loading.active) { overflow: hidden; }

.screen {
  display: none;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
  padding: 0 0 max(36px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; animation: screenIn .35s ease both; }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- 加载页 ---------- */
#screen-loading {
  align-items: center;
  justify-content: center;
  background: var(--blue);
  max-width: none;
  min-height: 100vh;
  min-height: 100svh;
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
  overflow: hidden;
  transition: opacity .45s ease;
}
#screen-loading.fade-out { opacity: 0; }
#screen-loading.screen.active { animation: none; }

.loading-scene {
  display: flex;
  flex-direction: column;
  align-items: center;
  perspective: 1100px;
  perspective-origin: 50% 46%;
  transform-origin: center center;
}

.book-holder {
  width: 228px;
  height: 148px;
  margin-bottom: 18px;
}
.book {
  position: relative;
  width: 228px;
  height: 140px;
  transform-style: preserve-3d;
  transform-origin: 50% 62%;
  transform: rotateX(18deg);
}
.book-resting-shadow {
  position: absolute;
  z-index: 0;
  left: 8px;
  top: 105px;
  width: 212px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(12,75,126,.34) 0%, rgba(12,75,126,.13) 52%, transparent 73%);
  transform: translateZ(-12px);
}
.book-right-cover {
  position: absolute;
  z-index: 1;
  left: 112px;
  top: 12px;
  width: 110px;
  height: 122px;
  border-radius: 5px 15px 15px 6px;
  background: linear-gradient(145deg, #55d4ee, #28b9e2);
  box-shadow: 0 8px 0 #147ebd, 0 12px 12px rgba(15,83,136,.22);
  transform: translateZ(-2px);
}
.book-spine {
  position: absolute;
  z-index: 7;
  left: 110px;
  top: 10px;
  width: 7px;
  height: 120px;
  background: linear-gradient(90deg, rgba(173,166,207,.18), #d7d2e8 50%, rgba(255,255,255,.92));
  border-radius: 0 0 8px 8px;
  box-shadow: 0 4px 0 rgba(20,126,189,.7);
  opacity: 0;
  transform: translateZ(7px);
  animation: fadeIn .3s ease 1.82s forwards;
}
.page {
  position: absolute;
  top: 8px;
  width: 108px;
  height: 120px;
  background: linear-gradient(90deg, #fff 0%, #f9f7ff 82%, #eeebfa 100%);
  border: 1px solid rgba(218,214,237,.9);
  box-shadow: 0 5px 0 #d9d5e7, inset 0 0 15px rgba(120,105,180,.08);
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
}
.page-char {
  font-size: 34px;
  font-weight: 800;
  color: var(--blue);
  opacity: 0;
  animation: popIn .38s cubic-bezier(.2,1.35,.45,1) 1.94s forwards;
}
.page-right {
  z-index: 3;
  left: 114px;
  border-radius: 4px 13px 13px 6px;
  transform: translateZ(4px);
}
.page-right::after {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 13px;
  pointer-events: none;
}
.page-right::after {
  left: 0;
  background: linear-gradient(90deg, rgba(117,101,169,.12), transparent);
}

.book-turn {
  position: absolute;
  z-index: 6;
  left: 114px;
  top: 8px;
  width: 108px;
  height: 120px;
  transform-origin: left center;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
  will-change: transform;
  transform: translate3d(0,0,8px) rotateY(0deg);
  animation: turnCover 1.5s cubic-bezier(.4,0,.2,1) .38s forwards;
}
.book-face {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.book-face-front {
  border: 6px solid #36c5e9;
  border-left-width: 7px;
  border-radius: 6px 15px 14px 5px;
  background: linear-gradient(145deg, #ffffff, #f2effa);
  box-shadow: 0 7px 0 #147ebd, inset -8px 0 14px rgba(125,108,184,.1);
  transform: translateZ(.1px);
}
.book-face-back {
  border: 1px solid rgba(218,214,237,.95);
  border-radius: 13px 4px 6px 13px;
  background: linear-gradient(90deg, #f0edf9 0%, #faf8ff 18%, #fff 100%);
  box-shadow:
    0 5px 0 #d9d5e7,
    -4px 9px 0 #36c5e9,
    -4px 14px 0 #147ebd,
    inset 0 0 15px rgba(120,105,180,.08);
  transform: rotateY(180deg) translateZ(.1px);
}
.book-face-back::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 0;
  bottom: 8px;
  width: 13px;
  background: linear-gradient(90deg, transparent, rgba(117,101,169,.12));
}
@keyframes turnCover {
  from { transform: translate3d(0,0,8px) rotateY(0deg); }
  to { transform: translate3d(0,0,8px) rotateY(-180deg); }
}
@keyframes popIn { from { opacity:0; transform: scale(.4);} to { opacity:1; transform: scale(1);} }
@keyframes fadeIn { to { opacity: 1; } }

.loading-title {
  color: #fff;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 6px;
  opacity: 0;
  animation: textUp .5s ease 2.28s forwards;
}
.loading-sub {
  color: rgba(255,255,255,0.9);
  font-size: 15px;
  font-weight: 600;
  margin-top: 10px;
  letter-spacing: 1px;
  opacity: 0;
  animation: textUp .5s ease 2.48s forwards;
}
@keyframes textUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Header ---------- */
.app-header {
  padding: 34px 20px 18px;
  text-align: center;
}
.app-header h1 {
  margin: 8px 0 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--text);
}
.app-logo {
  font-size: 46px;
  display: inline-block;
  animation: bookBob 3.5s ease-in-out infinite;
}
.app-tagline { margin: 8px 0 0; font-size: 15px; color: var(--muted); font-weight: 600; }

/* ---------- 首页面板 ---------- */
.panel {
  margin: 10px 20px 0;
  padding: 4px 0 0;
}
.field { margin-bottom: 22px; }
.field label {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}
.field-row { display: flex; align-items: center; justify-content: space-between; }
.field-row label:first-child { margin-bottom: 0; }

select {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-family: var(--font);
  font-weight: 700;
  color: var(--text);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  background: #fff;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' stroke='%23afafaf' stroke-width='2.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
select:focus { outline: none; border-color: var(--blue-border); }

.segmented { display: flex; gap: 10px; }
.seg-btn {
  flex: 1;
  padding: 13px 8px;
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  background: #fff;
  font-size: 14px;
  font-family: var(--font);
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--muted);
  transition: all .12s;
}
.seg-btn[hidden] { display: none; }
.seg-btn.active {
  background: var(--blue-light);
  border-color: var(--blue-border);
  color: var(--blue);
}

.switch { position: relative; display: inline-block; width: 52px; height: 30px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 30px; transition: .18s;
}
.slider::before {
  content: "";
  position: absolute; height: 22px; width: 22px;
  left: 4px; bottom: 4px;
  background: #fff; border-radius: 50%; transition: .18s;
  box-shadow: 0 2px 0 rgba(0,0,0,0.1);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(22px); }

.range-summary { font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 22px; }

/* ---------- 按钮（厚底边按压感） ---------- */
.btn-primary {
  width: 100%;
  padding: 15px;
  font-size: 16px;
  font-weight: 800;
  font-family: var(--font);
  letter-spacing: 2px;
  color: #fff;
  background: var(--blue);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  box-shadow: 0 4px 0 var(--blue-edge);
  transition: filter .12s;
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--blue-edge);
}

.btn-secondary {
  padding: 13px 22px;
  font-size: 15px;
  font-weight: 800;
  font-family: var(--font);
  letter-spacing: 1px;
  color: var(--blue);
  background: #fff;
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}
.btn-secondary:hover { background: #f7f7f7; }
.btn-secondary:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}

/* ---------- 检测页 ---------- */
.app-header-test { padding-top: 26px; }
.progress-track {
  height: 16px;
  background: var(--border);
  border-radius: 8px;
  margin: 0 4px 12px;
  overflow: hidden;
}
.progress-fill {
  position: relative;
  height: 100%;
  width: 0%;
  border-radius: 8px;
  background: var(--green);
  transition: width .4s cubic-bezier(.4,1.3,.6,1);
}
.progress-shine {
  position: absolute;
  top: 4px; left: 8px; right: 8px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,0.35);
}
#test-progress { font-size: 15px; color: var(--muted); font-weight: 700; }

.test-instructions {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  padding: 0 20px;
}
.test-instructions b { color: var(--blue); }

.char-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 0 20px;
  margin-bottom: 24px;
}
@media (min-width: 480px) {
  .char-grid { grid-template-columns: repeat(5, 1fr); }
}

/* 字卡：多邻国选项卡样式 */
.char-tile {
  aspect-ratio: 1;
  background: #fff;
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  transition: all .1s;
  animation: tileIn .3s cubic-bezier(.3,1.4,.5,1) both;
}
.char-tile:nth-child(1)  { animation-delay: .02s; }
.char-tile:nth-child(2)  { animation-delay: .05s; }
.char-tile:nth-child(3)  { animation-delay: .08s; }
.char-tile:nth-child(4)  { animation-delay: .11s; }
.char-tile:nth-child(5)  { animation-delay: .14s; }
.char-tile:nth-child(6)  { animation-delay: .17s; }
.char-tile:nth-child(7)  { animation-delay: .20s; }
.char-tile:nth-child(8)  { animation-delay: .23s; }
.char-tile:nth-child(9)  { animation-delay: .26s; }
.char-tile:nth-child(10) { animation-delay: .29s; }
@keyframes tileIn {
  from { opacity: 0; transform: scale(.85); }
  to { opacity: 1; transform: scale(1); }
}
.char-tile:hover { background: #f7f7f7; }
.char-tile:active {
  transform: translateY(2px);
  border-bottom-width: 2px;
}
.char-tile .tile-pinyin {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 4px;
  height: 18px;
}
.char-tile .tile-char {
  font-size: 38px;
  font-weight: 700;
  color: var(--text);
}
.char-tile.known {
  background: var(--blue-light);
  border-color: var(--blue-border);
}
.char-tile.known:hover { background: var(--blue-light); }
.char-tile.known .tile-char,
.char-tile.known .tile-pinyin { color: var(--blue); }

#btn-next { margin: 0 20px; width: auto; }

/* ---------- 结果页 ---------- */
.result-trophy {
  font-size: 52px;
  animation: trophyPop .6s cubic-bezier(.3,1.6,.5,1) both;
}
@keyframes trophyPop {
  0% { transform: scale(0); }
  70% { transform: scale(1.2); }
  100% { transform: scale(1); }
}

.result-summary {
  display: flex;
  gap: 12px;
  padding: 0 20px;
  margin-bottom: 26px;
}
.result-card {
  flex: 1;
  border-radius: var(--radius);
  text-align: center;
  padding: 14px 8px 16px;
  background: #fff;
  border: 2px solid var(--border);
  border-bottom-width: 4px;
}
.card-known   { border-color: #a5e878; }
.card-unknown { border-color: var(--red-border); }
.card-rate {
  background: var(--blue);
  border-color: var(--blue-edge);
}
.result-number { font-size: 28px; font-weight: 800; margin-top: 2px; }
.result-label { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: 1px; }
.card-known .result-number { color: var(--green); }
.card-unknown .result-number { color: var(--red); }
.card-rate .result-number { color: #fff; }
.card-rate .result-label { color: rgba(255,255,255,0.85); }

.result-section { padding: 0 20px; margin-bottom: 22px; }
.result-section h3 {
  font-size: 16px;
  color: var(--text);
  margin: 0 0 10px;
  font-weight: 800;
}
.result-section h3 small {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  margin-left: 6px;
}
.char-list { display: flex; flex-wrap: wrap; gap: 9px; }
.char-list .tag {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  border: 2px solid var(--border);
  border-bottom-width: 4px;
  background: #fff;
  transition: all .1s;
}
.char-list .tag:active { transform: translateY(2px); border-bottom-width: 2px; }
.char-list-known .tag { color: var(--green); border-color: #a5e878; }
.char-list-unknown .tag { color: var(--red); border-color: var(--red-border); }

.result-actions { padding: 8px 20px 0; }
.result-actions .btn-secondary { width: 100%; text-align: center; }

/* ---------- 详情弹层 ---------- */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(60,60,60,0.5);
  align-items: center; justify-content: center;
  z-index: 10;
  padding: 20px;
}
.overlay.active { display: flex; }
.overlay.active .detail-card { animation: cardPop .3s cubic-bezier(.3,1.4,.5,1) both; }
@keyframes cardPop {
  from { opacity: 0; transform: scale(.85) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.detail-card {
  background: #fff;
  border-radius: 20px;
  padding: 30px 28px 26px;
  text-align: center;
  min-width: 250px;
  max-width: 330px;
  width: 90vw;
  max-height: 82vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 2px solid var(--border);
  border-bottom-width: 6px;
}
.detail-char-box {
  width: 96px; height: 96px;
  margin: 0 auto 10px;
  background: #fbfdff;
  border: 2px solid var(--blue-border);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.detail-char-box::before, .detail-char-box::after {
  content: "";
  position: absolute;
  background: var(--blue-light);
}
.detail-char-box::before { left: 50%; top: 7%; width: 2px; height: 86%; }
.detail-char-box::after { top: 50%; left: 7%; height: 2px; width: 86%; }
.detail-char {
  font-size: 58px;
  font-weight: 700;
  color: var(--text);
  position: relative;
  z-index: 1;
}
.detail-pinyin { font-size: 22px; color: var(--blue); font-weight: 800; margin-bottom: 10px; }
.detail-meta {
  display: flex;
  justify-content: center;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 18px;
}
.detail-meta span {
  background: #f7f7f7;
  color: var(--text);
  padding: 5px 12px;
  border-radius: 999px;
  font-weight: 700;
}
.detail-meta span:empty { display: none; }
.detail-block { text-align: left; margin-bottom: 16px; }
.detail-block-title {
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 7px;
}
.detail-meaning {
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.6;
  background: #fffbeb;
  border: 2px solid #ffe9a8;
  border-radius: 12px;
  padding: 10px 12px;
}
.detail-words { display: flex; flex-wrap: wrap; gap: 8px; }
.word-chip {
  background: var(--blue-light);
  color: var(--blue);
  border: 2px solid var(--blue-border);
  padding: 7px 11px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
}
.word-chip-py { font-size: 12px; color: #6ab7e0; margin-left: 3px; font-weight: 600; }

/* ---------- 响应式协调：手机 / 平板 / 电脑 ---------- */
@media (max-width: 479px) {
  .app-header {
    padding: 28px 16px 16px;
  }
  .app-header-test {
    padding-top: 20px;
  }
  .panel {
    margin-left: 16px;
    margin-right: 16px;
  }
  .char-grid {
    gap: 10px;
    padding-left: 16px;
    padding-right: 16px;
  }
  #btn-next {
    margin-left: 16px;
    margin-right: 16px;
  }
  .result-summary,
  .result-section,
  .result-actions {
    padding-left: 16px;
    padding-right: 16px;
  }
  .seg-btn {
    min-height: 52px;
    line-height: 1.25;
  }
}

@media (max-width: 359px) {
  .loading-scene {
    transform: scale(.9);
  }
  .app-header h1 {
    font-size: 23px;
  }
  .app-logo {
    font-size: 40px;
  }
  .panel {
    margin-left: 12px;
    margin-right: 12px;
  }
  .segmented {
    gap: 7px;
  }
  .seg-btn {
    padding-left: 5px;
    padding-right: 5px;
    font-size: 13px;
  }
  .char-grid {
    gap: 8px;
    padding-left: 12px;
    padding-right: 12px;
  }
  #btn-next {
    margin-left: 12px;
    margin-right: 12px;
  }
  .char-tile .tile-char {
    font-size: 34px;
  }
  .result-summary {
    gap: 6px;
    padding-left: 12px;
    padding-right: 12px;
  }
  .result-card {
    padding-left: 4px;
    padding-right: 4px;
  }
  .result-number {
    font-size: 24px;
  }
  .result-section,
  .result-actions {
    padding-left: 12px;
    padding-right: 12px;
  }
  .overlay {
    padding: 12px;
  }
  .detail-card {
    min-width: 0;
    width: 100%;
    padding: 24px 18px 22px;
  }
}

@media (min-width: 480px) and (max-width: 767px) {
  .screen:not(#screen-loading) {
    max-width: 600px;
  }
  .char-grid {
    gap: 10px;
  }
}

@media (min-width: 768px) {
  .screen:not(#screen-loading) {
    max-width: 640px;
  }
  .panel {
    margin-left: 28px;
    margin-right: 28px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .loading-scene {
    transform: scale(.76);
  }
  .app-header {
    padding-top: 16px;
    padding-bottom: 10px;
  }
  .app-header-test {
    padding-top: 12px;
  }
  .test-instructions {
    margin-bottom: 8px;
  }
  .char-grid {
    gap: 8px;
    margin-bottom: 12px;
  }
}

@media (orientation: landscape) and (max-height: 380px) {
  .loading-scene {
    transform: scale(.66);
  }
}

@media (hover: none) {
  .char-tile:hover,
  .btn-secondary:hover {
    background: #fff;
  }
  .char-tile.known:hover {
    background: var(--blue-light);
  }
  .btn-primary:hover {
    filter: none;
  }
}
