/* Learning pages use the same restrained palette as the public site. */
.learning-page { --learning-panel-gap: 10px; }
.learning-page .stat-grid { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.learning-page .stat-card { min-height: 118px; border: 1px solid #e7ddd0; border-radius: 14px; background: #fffdfa; box-shadow: 0 5px 17px rgba(50,35,25,.045); }
.learning-page .stat-card strong { color: #382d26; font-size: clamp(24px,2.3vw,32px); }
.learning-page .stat-action { width: 100%; text-align: left; cursor: pointer; font: inherit; }
.learning-page .stat-action:hover, .learning-page .stat-action:focus-visible { border-color: #b93d33; background: #fff6f1; box-shadow: 0 0 0 3px rgba(185,61,51,.12); }
.learning-page .stat-action:hover strong, .learning-page .stat-action:focus-visible strong { color: #a62c26; }
.learning-page .book-grid { max-height: 560px; overflow: auto; padding: 3px 5px 5px 3px; scrollbar-color: #c6a582 #fbf8f3; }
.learning-page .book-card { transition: border-color .16s ease, box-shadow .16s ease, background .16s ease; }
.learning-page .book-card.has-cover::before { display: none; }
.learning-page .book-cover-image { position: absolute; top: 11px; left: 11px; bottom: 11px; width: 72px; height: calc(100% - 22px); object-fit: cover; border-radius: 7px; box-shadow: 2px 5px 12px rgba(43,28,17,.16); }
.learning-page .book-card.selected { border-color: #b93d33; background: #fff8f5; box-shadow: inset 4px 0 0 #b93d33; }
.search-suggestions { position: relative; z-index: 3; width: min(360px,100%); margin: -1px 0 8px; border: 1px solid #d9cfc2; border-radius: 0 0 10px 10px; background: #fffdfa; box-shadow: 0 8px 20px rgba(42,31,22,.1); }
.search-suggestions[hidden] { display: none; }
.search-suggestions button { display: block; width: 100%; padding: 9px 14px; border: 0; background: none; text-align: left; color: #3f342d; cursor: pointer; }
.search-suggestions button:hover, .search-suggestions button:focus-visible { background: #fff1e8; color: #a62c26; }
.word-book-labels { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 0 !important; }
.word-book-labels span { padding: 3px 7px; border-radius: 5px; background: #f5eee5; color: #6b4d3a; font-size: 11px; }

body:has(.study-shell) { overflow: hidden; }
.study-stage { padding: clamp(8px,1vw,14px); }
.study-stage > .flashcard-landscape { width: min(1180px,100%); height: min(620px,100%); min-height: 0; padding: 0 38px 30px; overflow: auto; }
.flashcard-landscape .card-topline { min-height: 66px; }
.study-card-layout { display: grid; grid-template-columns: minmax(0,1.05fr) minmax(0,.95fr); gap: clamp(20px,3vw,44px); flex: 1; min-height: 0; align-items: stretch; }
.study-card-copy { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 15px; padding: 12px 0; text-align: left; }
.flashcard-landscape .card-word { text-align: left; }
.flashcard-landscape h2 { font-size: clamp(43px,5.5vw,78px); line-height: 1.05; }
.flashcard-landscape .word-gender { font-size: 16px; }
.flashcard-landscape .card-speak { align-self: flex-start; }
.flashcard-landscape .card-answer { width: 100%; margin: 4px 0 0; padding: 17px 0 0; }
.flashcard-landscape .card-answer > strong { font-size: clamp(24px,2.6vw,36px); }
.flashcard-landscape .grammar-row { margin: 12px 0; }
.flashcard-landscape .example-line { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.flashcard-landscape .example-line p { margin: 0; }
.flashcard-landscape .example-zh { margin-top: 8px; }
.flashcard-landscape.is-revealed .card-word { width: 100%; }
.flashcard-landscape .card-word-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 18px; }
.flashcard-landscape .card-word-line h2 { min-width: 0; max-width: 100%; }
.flashcard-landscape .card-meaning { flex: 1 1 100px; min-width: 0; color: #a83229; font-size: clamp(24px,2.6vw,36px); line-height: 1.35; overflow-wrap: anywhere; }
.flashcard-landscape .card-pronunciation-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.flashcard-landscape .card-pronunciation-row .phonetic { min-width: 0; min-height: 0; overflow-wrap: anywhere; }
.flashcard-landscape .card-pronunciation-row .card-speak { flex: 0 1 auto; min-width: 0; align-self: center; white-space: normal; }
.flashcard-landscape.is-revealed .study-card-copy > .grammar-row { margin: 0; }
.flashcard-landscape .card-answer > .card-example-heading { display: block; margin-bottom: 12px; color: var(--ink); font-size: 22px; line-height: 1.3; }
@media (max-width: 900px) {
  .flashcard-landscape .card-word-line,
  .flashcard-landscape .card-pronunciation-row { justify-content: center; }
  .flashcard-landscape .card-meaning { flex: 0 1 auto; }
}
.card-prompt { max-width: 410px; color: #79685b; line-height: 1.65; }
.study-picture { margin: 0; min-width: 0; min-height: 0; display: grid; place-items: center; align-content: center; overflow: hidden; border: 1px solid #e7dbcb; border-radius: 15px; background: #f8f3ec; }
.study-picture img { display: block; width: 100%; height: min(430px,calc(100dvh - 320px)); min-height: 0; max-height: 100%; object-fit: contain; }
.study-picture figcaption { width: 100%; padding: 6px 10px; color: #766657; font-size: 10px; text-align: left; }
.study-picture-empty img { max-width: 58%; max-height: 270px; min-height: 0; object-fit: contain; }
.study-picture-empty span { margin-top: 15px; color: #8b7864; font-size: 13px; }
.card-flip-hint { align-self: flex-end; margin: 0; color: #8c6e56; font-size: 12px; }
.flashcard-landscape .card-flip-hint { position: absolute; right: 38px; bottom: 9px; z-index: 2; }
.study-stage { perspective: 2400px; }
.flashcard-landscape { transform-origin: center; backface-visibility: hidden; }
.flashcard-landscape[data-flipping] { will-change: transform, filter; }
.study-navigation { min-height: 82px; display: grid; grid-template-columns: 1fr auto 1fr; gap: 14px; padding: 11px clamp(16px,3vw,40px); }
.study-navigation > .button:first-child { justify-self: start; }
.study-navigation > .button:last-child { justify-self: end; }
.study-rating-actions { display: flex; align-items: center; justify-content: center; gap: 12px; }
.study-rating-actions .rating-button { min-width: 145px; min-height: 50px; font-size: 16px; }
.study-rating-actions .rating-button.good { background: #a62c26; border-color: #a62c26; }
.study-rating-actions .rating-button.good:hover { background: #84231e; }
.study-rating-actions .rating-button.again { color: #a62c26; }
.study-rated { color: #6b4b3a; font-weight: 750; }
.review-list-modal { width: min(750px,100%); }
.review-word-list { max-height: 50vh; overflow: auto; border: 1px solid #eadfd2; border-radius: 10px; }
.review-word { display: grid; grid-template-columns: minmax(130px,.7fr) minmax(0,1.3fr) auto; align-items: center; gap: 8px; padding: 9px 13px; border-bottom: 1px solid #eee4d9; }
.review-word:last-child { border-bottom: 0; }
.review-word strong, .review-word span { overflow-wrap: anywhere; }
.review-word button { border: 0; background: #fbf3e9; color: #9c342d; border-radius: 50%; width: 32px; height: 32px; cursor: pointer; }
.review-list-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

@media (max-width: 900px) {
  .learning-page .stat-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .study-stage > .flashcard-landscape { height: auto; min-height: 0; }
  .study-card-layout { grid-template-columns: 1fr; }
  .study-card-copy { align-items: center; text-align: center; }
  .flashcard-landscape .card-word { text-align: center; }
  .flashcard-landscape .card-speak { align-self: center; }
  .study-picture { min-height: 180px; }
  .study-picture img { height: 220px; min-height: 0; }
  .study-picture-empty img { height: 130px; }
}
@media (max-width: 600px) {
  .learning-page .book-grid { max-height: 500px; }
  .study-stage { padding: 12px; }
  .study-stage > .flashcard-landscape { padding: 0 18px 20px; }
  .study-navigation { grid-template-columns: 1fr 1fr; }
  .study-rating-actions { grid-column: 1 / -1; grid-row: 1; }
  .study-navigation > .button { grid-row: 2; }
  .study-rating-actions .rating-button { min-width: 120px; }
  .review-word { grid-template-columns: 1fr auto; }
  .review-word span { grid-row: 2; }
}
@media (prefers-reduced-motion: reduce) {
  .learning-page .book-card { transition: none; }
}

/* Vocabulary matching: reuse the proven page/resume design with the site palette. */
body:has(.match-shell) { overflow: hidden; }
.match-shell { position: fixed; inset: 0; z-index: 100; overflow: auto; }
.match-head { display: flex; justify-content: space-between; gap: 20px; }
.match-grid { display: grid; }
.match-shell { background: radial-gradient(circle at 10% 0%,#f7e8c6,#f3eee5 48%,#e9e0d2); color: #332a22; padding: 32px 22px; }
.match-panel { width: min(1100px,100%); margin: auto; overflow: hidden; border: 1px solid #e5d4b9; border-radius: 24px; background: #fffaf2; box-shadow: 0 24px 65px rgba(64,46,24,.15); }
.match-head { max-width: none; min-height: 186px; margin: 0; padding: 28px 38px; align-items: flex-start; background: linear-gradient(90deg,rgba(251,244,231,.98) 0%,rgba(251,244,231,.91) 43%,rgba(251,244,231,.33) 100%),url('/assets/vocabulary-desk.png') center 49% / cover; border-bottom: 1px solid #e5d4b9; }
.match-kicker { display: inline-block; margin-bottom: 4px; color: #ae3429; font-size: 11px; font-weight: 850; letter-spacing: .16em; }
.match-head h2 { color: #2f2923; font-size: clamp(29px,4vw,42px); line-height: 1.2; }
.match-head p { max-width: 560px; margin-top: 8px; color: #695a4b; }
.match-head .button { border-color: #decdb5; background: rgba(255,253,249,.94); color: #463728; }
.match-play-area { padding: 24px 38px 38px; }
.match-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.match-mode { display: inline-flex; align-items: center; gap: 8px; color: #7a4d32; font-size: 13px; font-weight: 850; letter-spacing: .11em; white-space: nowrap; }
.match-mode b { color: #c7342b; font-size: 17px; }
.match-progress, .match-head .match-progress { margin: 0; color: #80522d; font-size: 13px; font-weight: 800; }
.match-steps { display: flex; gap: 7px; margin: 12px 0 25px; }
.match-steps span { flex: 1; height: 7px; border-radius: 99px; background: #e9dcc8; }
.match-steps span.complete { background: linear-gradient(90deg,#bd332a,#e7a93c); }
.match-grid { max-width: none; gap: 13px; }
.match-tile { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 134px; padding: 36px 15px 18px; border: 1px solid #e3d4bd; border-top: 4px solid #be392c; border-bottom: 4px solid #d5c1a2; border-radius: 15px; background: #fffdfa; color: #332920; box-shadow: 0 5px 12px rgba(62,44,25,.08); font-size: 17px; line-height: 1.45; font-weight: 750; text-align: center; overflow-wrap: anywhere; transition: transform .16s,background .16s,border-color .16s,box-shadow .16s; }
.match-tile[data-type="zh"] { border-top-color: #dca941; background: #fff9ee; }
.match-tile[data-type="de"] { flex-direction: column; gap: 8px; }
.match-word { max-width: 100%; }
.match-grammar { max-width: 100%; color: var(--muted); font-size: 11px; font-weight: 500; line-height: 1.45; overflow-wrap: anywhere; }
.match-tile::before { position: absolute; top: 10px; left: 13px; color: #9a4035; font-size: 10px; font-weight: 850; letter-spacing: .11em; }
.match-tile[data-type="de"]::before { content: "DEUTSCH"; }
.match-tile[data-type="zh"]::before { content: "中文释义"; color: #94641e; }
html[data-language="de"] .match-tile[data-type="zh"]::before { content: "CHINESISCH"; }
.match-tile::after { content: ""; position: absolute; top: 13px; right: 13px; width: 18px; height: 4px; background: linear-gradient(90deg,#282320 0 33%,#c83329 33% 66%,#efbf3d 66%); }
.match-tile:hover { transform: translateY(-3px); border-color: #bc8a52; border-top-color: #b9362b; background: #fff4dc; color: #32251d; box-shadow: 0 9px 18px rgba(62,44,25,.12); }
.match-tile.selected, .match-tile.selected:hover { border-color: #a76134; border-top-color: #bc3529; background: #ffe5ad; color: #4b2b1d; box-shadow: 0 0 0 3px rgba(205,145,56,.24),0 6px 14px rgba(62,44,25,.13); }
.match-tile.mismatch, .match-tile.mismatch:hover { border-color: #c83c33; background: #ffe4df; color: #8e2921; box-shadow: 0 0 0 3px rgba(200,60,51,.12); animation: match-nudge .3s ease-out; }
.match-tile:focus-visible { outline: 3px solid #bd352b; outline-offset: 3px; }
.match-tile.matched { visibility: hidden; pointer-events: none; }
.match-complete { max-width: 560px; margin: 6px auto; padding: 8px 10px 20px; color: #46382b; }
.match-complete::before { content: ""; display: block; width: 210px; height: 135px; margin: auto; background: url('/assets/learning-card-illustration.svg') center / contain no-repeat; }
.match-complete strong { display: grid; place-items: center; width: 56px; height: 56px; margin: 0 auto 8px; border-radius: 50%; background: #f3ce6c; color: #663b22; font-size: 35px; }
.match-complete h2 { color: #302820; font-size: clamp(29px,4vw,42px); }
.match-complete .button { border-color: #c9a66a; }
@keyframes match-nudge { 25% { transform: translateX(-4px); } 65% { transform: translateX(4px); } }

/* Word matching now runs through the whole book in ten-pair pages. */
.match-shell { padding: 18px clamp(12px,2vw,28px); }
.match-panel { width: min(1440px,100%); min-height: min(760px,calc(100dvh - 36px)); }
.match-head { min-height: 165px; padding: 24px 32px; }
.match-head .match-level { margin-top: 12px; border-color: #d9b977; background: #fff8e9; box-shadow: 0 2px 8px rgba(70,45,20,.07); }
.match-play-area { position: relative; padding: 20px 32px 32px; }
.match-toolbar { flex-wrap: wrap; justify-content: flex-start; gap: 10px 18px; }
.match-level { display: inline-flex; align-items: center; min-height: 30px; padding: 4px 11px; border: 1px solid #e3cda7; border-radius: 999px; background: #fff2d8; color: #75451f; font-size: 13px; font-weight: 800; }
.match-progress { margin-left: auto; }
.match-overall-progress { margin-top: 8px; color: #756656; font-size: 12px; font-weight: 700; }
.match-steps { margin: 12px 0 18px; }
.match-grid { grid-template-columns: repeat(5,minmax(0,1fr)); gap: 11px; }
.match-tile { min-height: 108px; padding: 30px 11px 13px; font-size: clamp(13px,1.3vw,17px); }
.match-feedback-bubble { position: fixed; top: 35%; left: 50%; z-index: 110; width: max-content; max-width: min(420px,calc(100vw - 30px)); padding: 15px 23px; border: 1px solid #e6c98e; border-radius: 999px; background: #fff8e6; color: #76491c; box-shadow: 0 15px 44px rgba(48,33,15,.19); font-size: 17px; font-weight: 850; line-height: 1.4; text-align: center; pointer-events: none; animation: match-feedback-pop .65s ease-out both; }
.match-feedback-bubble.success::before { content: '✓'; display: inline-grid; place-items: center; width: 25px; height: 25px; margin-right: 9px; border-radius: 50%; background: #488665; color: #fff; }
.match-feedback-bubble.error { border-color: #dfa5a0; background: #fff0eb; color: #8c342c; }
.match-feedback-bubble.error::before { content: '!'; display: inline-grid; place-items: center; width: 25px; height: 25px; margin-right: 9px; border-radius: 50%; background: #b84539; color: #fff; }
/* Keep transient pairing feedback in the illustrated header so it never hides a word tile. */
@media (min-width: 621px) {
  .match-feedback-bubble { position: absolute; top: -82px; left: 60%; }
}
.match-complete { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 370px; max-width: 680px; margin: 0 auto; }
.match-complete h2 { margin: 8px 0; }
.match-page-celebration { animation: match-celebrate .45s cubic-bezier(.18,.8,.22,1.2) both; }
@keyframes match-celebrate { from { opacity: 0; transform: translateY(28px) scale(.88); } 70% { opacity: 1; transform: translateY(-5px) scale(1.04); } to { opacity: 1; transform: translateY(0) scale(1); } }
.match-complete p { margin: 4px 0; line-height: 1.55; }
.match-auto-next { color: #78552d; font-size: 15px; font-weight: 700; }
.match-countdown-number { display: inline-grid; place-items: center; width: 40px; height: 40px; margin-right: 4px; border-radius: 50%; background: #b9362b; color: #fff; font-size: 21px; font-variant-numeric: tabular-nums; }
.match-ready-overlay { position: absolute; inset: 104px 24px 24px; z-index: 2; display: grid; place-items: center; border-radius: 18px; background: rgba(255,250,242,.7); backdrop-filter: blur(3px); }
.match-ready-card { display: flex; flex-direction: column; align-items: center; gap: 10px; min-width: min(340px,100%); padding: 24px; border: 1px solid #dec69f; border-radius: 20px; background: #fffaf2; box-shadow: 0 16px 42px rgba(64,46,24,.18); text-align: center; }
.match-ready-kicker { color: #9b3c30; font-size: 15px; font-weight: 850; letter-spacing: .12em; }
.match-ready-number { display: grid; place-items: center; width: 88px; height: 88px; border-radius: 50%; background: #b9362b; color: #fff; font-size: 48px; font-weight: 850; font-variant-numeric: tabular-nums; }
.match-ready-card p { margin: 0; color: #675343; }
.match-ready-card .button { margin-top: 6px; }
.match-resume-choice, .match-restart-confirm, .match-save-error { max-width: 720px; }
.match-restart-confirm strong, .match-save-error strong { background: #f5d3c0; color: #a52c25; }
.match-complete-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 20px; }
@keyframes match-feedback-pop { from { opacity: 1; transform: translate(-50%,12px) scale(.92); } 25% { opacity: 1; transform: translate(-50%,-3px) scale(1.04); } to { opacity: 1; transform: translate(-50%,0) scale(1); } }
@media (max-width: 1100px) {
  .match-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
}
@media (max-width: 760px) {
  .match-head { min-height: 145px; padding: 18px; }
  .match-play-area { padding: 16px 18px 24px; }
  .match-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .match-tile { min-height: 99px; font-size: 14px; }
}
@media (max-width: 540px) {
  .match-shell { padding: 9px; }
  .match-panel { min-height: calc(100dvh - 18px); border-radius: 14px; }
  .match-head { min-height: 138px; padding: 14px; }
  .match-head h2 { font-size: 26px; }
  .match-head p { font-size: 11px; }
  .match-head .match-level { margin-top: 8px; }
  .match-play-area { padding: 13px 12px 22px; }
  .match-toolbar { gap: 7px; }
  .match-mode, .match-level, .match-progress { font-size: 11px; }
  .match-progress { margin-left: 0; width: 100%; }
  .match-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .match-tile { min-height: 96px; font-size: 13px; }
  .match-feedback-bubble { position: static; align-self: center; top: auto; left: auto; margin: 7px auto; padding: 12px 17px; font-size: 14px; animation: match-feedback-mobile .65s ease-out both; }
  .match-complete { min-height: 340px; padding: 0 7px; }
}
@keyframes match-feedback-mobile { from { opacity: 1; transform: translateY(6px) scale(.96); } 25% { opacity: 1; transform: translateY(-2px) scale(1.02); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .match-feedback-bubble { animation: none; transform: translateX(-50%); }
}
@media (max-width: 540px) and (prefers-reduced-motion: reduce) {
  .match-feedback-bubble { transform: none; }
}

.match-tile.mismatch, .match-tile.mismatch:hover { animation: match-nudge .38s ease-in-out; }
@keyframes match-nudge { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }
@media (prefers-reduced-motion: reduce) { .match-tile.mismatch, .match-tile.mismatch:hover, .match-page-celebration { animation: none; } }
@media (max-width: 620px) { .match-ready-overlay { inset: 96px 10px 10px; } .match-ready-card { padding: 18px; } }

/* Keep the introduction compact so all twenty desktop tiles get the space. */
.match-head { min-height: 0; padding: 15px 25px; }
.match-head > div { display: grid; grid-template-columns: max-content minmax(0,1fr); column-gap: 18px; row-gap: 3px; align-items: center; }
.match-head .match-kicker { grid-column: 1 / -1; margin: 0; }
.match-head h2 { grid-column: 1; grid-row: 2; font-size: clamp(27px,3vw,35px); }
.match-head p { grid-column: 2; grid-row: 2; max-width: 510px; margin: 0; font-size: 12px; line-height: 1.4; }
.match-head .match-level { grid-column: 1 / -1; grid-row: 3; min-height: 25px; margin: 4px 0 0; }
.match-tile { min-height: 92px; padding: 26px 10px 11px; }
@media (max-width: 620px) {
  .match-head { padding: 12px; gap: 8px; }
  .match-head > div { display: block; }
  .match-head h2 { font-size: 25px; }
  .match-head p { margin-top: 4px; font-size: 10px; }
  .match-head .match-level { margin-top: 6px; }
  .match-tile { min-height: 96px; }
}

/* Customer UI review: make the selected book and next action the visual path. */
.learning-page .learning-head {
  min-height: 132px;
  margin-bottom: 14px;
  padding: 18px clamp(20px,2.4vw,34px);
  border: 1px solid #e8dbc6;
  border-radius: var(--surface-radius);
  background: linear-gradient(90deg,rgba(255,253,248,.99) 0%,rgba(255,253,248,.94) 43%,rgba(255,253,248,.20) 100%),url('/assets/vocabulary-desk.png') center 51% / cover;
  box-shadow: none;
}
.learning-page .learning-head h1 { margin-top: 6px; font-size: clamp(29px,3vw,41px); }
.learning-page .learning-auth-status { display: inline-flex; align-items: center; max-width: 100%; margin: 7px 0 0; padding: 5px 9px; border: 1px solid #ead5b7; border-radius: 999px; background: #fffaf0; color: #674a2f; font-size: 12px; line-height: 1.35; }
.learning-page .learning-actions { align-self: center; gap: 8px; }
.learning-page .learning-actions .button { min-height: 44px; border-radius: var(--control-radius); font-size: 14px; font-weight: 700; }
.learning-page .learning-actions .button.primary { background: #aa2e27; border-color: #aa2e27; }
.learning-page .learning-actions .button.primary:hover, .learning-page .learning-actions .button.primary:focus-visible { background: #83251f; border-color: #83251f; }
.learning-page .stat-grid { margin-bottom: 14px; gap: var(--learning-panel-gap); }
.learning-page .stat-card { display: flex; flex-direction: column; justify-content: center; min-height: 105px; padding: 13px 16px; background: #fffdfa; }
.learning-page .stat-card small { color: #765c43; font-size: 12px; }
.learning-page .stat-card strong { margin: 5px 0 2px; font-size: clamp(24px,2.1vw,31px); font-variant-numeric: tabular-nums; }
.learning-page .stat-card span { color: #796d60; font-size: 12px; line-height: 1.35; }
.learning-page .stat-action { position: relative; padding-right: 33px; }
.learning-page .stat-action::after { content: '›'; position: absolute; top: 50%; right: 14px; transform: translateY(-50%); color: #a43229; font-size: 29px; line-height: 1; }
.learning-page .learning-layout { grid-template-columns: repeat(4,minmax(0,1fr)); gap: var(--learning-panel-gap); align-items: start; }
.learning-page .learning-layout > div { grid-column: 1 / span 3; min-width: 0; }
.learning-page .learning-layout > aside { grid-column: 4; min-width: 0; }
.learning-page .learning-layout > .word-search-panel { grid-column: 1 / -1; min-width: 0; margin: 0; padding: 20px; border-radius: var(--surface-radius); box-shadow: none; }
.learning-page .learning-layout > div > .panel, .learning-page .learning-layout aside > .panel, .learning-page .plan-card { border: 1px solid var(--line); border-radius: var(--surface-radius); box-shadow: none; }
.learning-page .learning-layout > div > .panel { padding: 20px; }
.learning-page .panel-head { margin-bottom: 12px; }
.learning-page .book-grid { max-height: min(408px,51vh); gap: 9px; padding: 3px 7px 6px 3px; }
.learning-page .book-card { --book-cover-width: 116px; --book-cover-inset: 5px; min-height: 146px; padding: 13px 10px 20px calc(var(--book-cover-inset) + var(--book-cover-width) + 16px); border-color: var(--line); border-radius: var(--control-radius); background: var(--paper); }
.learning-page .book-card::before { top: var(--book-cover-inset); bottom: var(--book-cover-inset); left: var(--book-cover-inset); width: var(--book-cover-width); border-radius: var(--control-radius); color: #493421; box-shadow: 0 1px 3px rgba(60,38,18,.1); }
.learning-page .book-cover-image { top: var(--book-cover-inset); bottom: var(--book-cover-inset); left: var(--book-cover-inset); width: var(--book-cover-width); height: calc(100% - 2 * var(--book-cover-inset)); border-radius: var(--control-radius); box-shadow: 0 1px 3px rgba(60,38,18,.1); }
.learning-page .book-card h3 { color: #332a23; font-size: 15px; line-height: 1.3; }
.learning-page .book-card p { color: #746456; font-size: 11px; -webkit-line-clamp: 2; }
.learning-page .book-card b { color: #754d24; }
.learning-page .book-card:hover, .learning-page .book-card:focus-visible { border-color: #bd674e; background: #fff9f1; box-shadow: 0 0 0 2px rgba(180,62,45,.11); }
.learning-page .book-card.selected, .learning-page .book-card.selected:hover, .learning-page .book-card.selected:focus-visible { border-color: #bd3d30; background: #fff7ed; box-shadow: 0 0 0 1px rgba(189,61,48,.12); }
.learning-page .book-selection-hint { margin: 10px 0 0; color: #75695d; }
.learning-page .plan-card { padding: 20px; background: #f9f3e8; }
.learning-page .plan-card h2 { margin: 5px 0 7px; }
.learning-page .plan-card .field { margin-bottom: 11px; }
.learning-page .plan-card .field span { color: #594433; font-weight: 700; }
.learning-page .plan-card .field input, .learning-page .plan-card .field select { min-height: 45px; border-color: #d8c5aa; background: #fffdfa; }
.learning-page .plan-card > .button[type='submit'] { min-height: 44px; border-color: #a9382e; color: #8f2d27; font-weight: 750; }
.learning-page .plan-card > .button[type='submit']:hover { background: #fff0e4; }
.learning-page .plan-card .reset-learning-button { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 44px; margin-top: 10px; padding: 10px 14px; border: 1px solid #d8b9ab; border-radius: 9px; background: #fffaf6; color: #8d4136; font: inherit; font-size: 13px; font-weight: 700; line-height: 1.3; text-decoration: none; text-align: center; cursor: pointer; transition: background .16s ease,border-color .16s ease,color .16s ease,box-shadow .16s ease; }
.learning-page .plan-card .reset-learning-button:hover { border-color: #b76553; background: #fff0e9; color: #a02e26; box-shadow: 0 3px 10px rgba(114,53,40,.09); }
.learning-page .plan-card .reset-learning-button:focus-visible { outline: 3px solid #da9a73; outline-offset: 2px; }
.learning-page .plan-card .reset-learning-button:disabled { opacity: .55; cursor: wait; box-shadow: none; }
.learning-page .search-box { align-items: stretch; }
.learning-page .search-input { min-width: 0; }
.learning-page .search-suggestions { width: calc(100% - 94px); max-width: none; margin-top: -1px; }
.learning-page .word-book-labels span { border: 1px solid #e7d4ba; background: #fbf3e6; color: #65452b; font-size: 12px; }

/* Keep word, pronunciation, picture, and scoring visible in one study view. */
.study-bar { min-height: 65px; padding: 9px 24px; }
.study-meta { max-width: min(55vw,580px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.study-book-name { color: #3d3026; font-weight: 800; }
.study-stage > .flashcard-landscape { border-radius: var(--surface-radius); }
.study-card-copy { justify-content: flex-start; gap: 12px; overflow-y: auto; scrollbar-width: thin; padding-top: clamp(26px,5vh,60px); padding-right: 6px; }
.flashcard-landscape .card-answer { margin-top: 0; padding-top: 14px; }
.flashcard-landscape .card-answer > strong { line-height: 1.2; }
.study-picture { background: #faf6ef; }
.study-picture img { border-radius: 8px; }
.study-navigation { min-height: 75px; padding-top: 9px; padding-bottom: 9px; }
.study-navigation > .button { min-height: 44px; }
.study-rating-actions .rating-button { min-height: 48px; }
.study-shell:has(.study-speech-notice) { grid-template-rows: auto 5px auto minmax(0,1fr) auto; }
.study-speech-notice { margin: 0; padding: 6px 24px; border-bottom: 1px solid #e9d3ac; background: #fff6e6; color: #65492d; font-size: 11px; line-height: 1.35; text-align: center; }

/* The game header is supporting context; the twenty cards own the canvas. */
.match-shell { display: flex; align-items: center; padding: 10px clamp(10px,1.1vw,20px); }
.match-panel { display: flex; flex-direction: column; width: min(1760px,100%); min-height: min(860px,calc(100dvh - 20px)); border-radius: var(--surface-radius); }
.match-head { flex: none; min-height: 0; padding: 12px 25px 11px; align-items: center; gap: 15px; background: linear-gradient(90deg,rgba(251,246,237,.98) 0%,rgba(251,246,237,.94) 42%,rgba(251,246,237,.24) 100%),url('/assets/vocabulary-desk.png') center 48% / cover; }
.match-head > div { display: grid; grid-template-columns: max-content max-content minmax(0,1fr); column-gap: 13px; row-gap: 3px; align-items: center; min-width: 0; }
.match-head .match-kicker { grid-column: 1 / -1; grid-row: 1; font-size: 10px; }
.match-head h2 { grid-column: 1; grid-row: 2; font-size: clamp(27px,2.5vw,35px); }
.match-head .match-level { grid-column: 2; grid-row: 2; justify-self: start; width: auto; min-height: 29px; margin: 0; padding: 4px 10px; border-color: #d6b07c; background: #fff8eb; color: #7b3d25; font-size: 12px; }
.match-head .match-book-name { grid-column: 3; grid-row: 2; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #554231; font-size: 13px; font-weight: 750; }
.match-head p { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.match-head > .button { min-height: 39px; padding: 7px 14px; }
.match-play-area { flex: 1; display: flex; flex-direction: column; padding: 12px 25px 21px; }
.match-toolbar { min-height: 22px; }
.match-speech-notice { margin: 5px 0 2px; padding: 6px 10px; border: 1px solid #e9d3ac; border-left: 3px solid #b76a35; border-radius: 6px; background: #fff6e6; color: #65492d; font-size: 11px; line-height: 1.35; }
.match-overall-progress { margin-top: 3px; }
.match-steps { margin: 8px 0 10px; gap: 6px; }
.match-steps span { height: 6px; }
.match-grid { grid-template-columns: repeat(5,minmax(0,1fr)); gap: 10px; }
@media (min-width: 851px) {
  /* A six-pair final page keeps the same tile scale and a content-sized, centered canvas. */
  .match-panel:has(.match-grid > .match-tile:nth-child(12):last-child) { min-height: 0; }
  .match-grid:has(.match-tile:nth-child(2):last-child) { grid-template-columns: repeat(2,minmax(0,260px)); justify-content: center; margin-block: auto; }
  .match-grid:has(.match-tile:nth-child(4):last-child) { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .match-grid:has(.match-tile:nth-child(6):last-child) { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .match-grid:has(.match-tile:nth-child(8):last-child) { grid-template-columns: repeat(4,minmax(0,1fr)); }
  /* Keep the final six- or eight-pair page in complete rows. Full 20-card pages remain five columns. */
  .match-grid:has(.match-tile:nth-child(12):last-child),
  .match-grid:has(.match-tile:nth-child(16):last-child) { grid-template-columns: repeat(4,minmax(0,1fr)); }
}
.match-tile { min-height: clamp(118px,14.2dvh,154px); padding: 25px 10px 10px; font-size: clamp(14px,1.15vw,18px); }
@media (min-width: 621px) { .match-panel:has(.match-speech-notice) .match-tile { min-height: clamp(113px,13.1dvh,144px); } }
.match-tile:disabled:not(.matched):hover { transform: none; }
.match-complete { flex: 1; min-height: 0; margin: auto; padding-top: 12px; padding-bottom: 18px; }
.match-complete::before { width: 190px; height: 118px; margin: 0 auto 10px; }
.match-ready-overlay { inset: 69px 13px 13px; }
.match-ready-card { min-width: min(310px,100%); padding: 19px 23px; }

/* Transient messages must not cover study navigation or game controls. */
body:has(.study-shell) #toast-root, body:has(.match-shell) #toast-root { top: 73px; right: auto; bottom: auto; left: 50%; width: min(290px,calc(100vw - 32px)); transform: translateX(-50%); pointer-events: none; }
body:has(.match-shell) #toast-root { top: 18px; }

@media (max-width: 1100px) {
  .learning-page .book-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .match-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
}
@media (max-width: 900px) {
  .learning-page .learning-layout { grid-template-columns: 1fr; }
  .learning-page .learning-layout > div,
  .learning-page .learning-layout > aside { grid-column: 1; }
  .learning-page .learning-layout > aside { order: -1; }
}
@media (max-width: 850px) {
  .learning-page .learning-head { min-height: 0; gap: 13px; }
  .learning-page .learning-layout { grid-template-columns: 1fr; }
  .learning-page .learning-layout aside { order: -1; }
  .learning-page .book-grid { max-height: 380px; }
  .match-grid { grid-template-columns: repeat(3,minmax(0,1fr)); }
}
@media (max-width: 620px) {
  .learning-page .learning-head { display: block; padding: 17px; }
  .learning-page .learning-head h1 { margin: 5px 0 14px; font-size: 28px; }
  .learning-page .learning-auth-status { margin: -7px 0 10px; font-size: 11px; }
  .learning-page .learning-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .learning-page .learning-actions .button { min-height: 42px; padding: 9px; font-size: 12px; }
  .learning-page { --learning-panel-gap: 8px; }
  .learning-page .stat-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: var(--learning-panel-gap); }
  .learning-page .stat-card { min-height: 98px; padding: 12px; }
  .learning-page .stat-card span { font-size: 11px; }
  .learning-page .book-grid { grid-template-columns: 1fr; max-height: 370px; }
  .learning-page .book-card { min-height: 146px; }
  .learning-page .plan-card .reset-learning-button { min-height: 46px; }
  .learning-page .search-suggestions { width: 100%; }
  .study-bar { min-height: 59px; padding: 8px 12px; gap: 7px; }
  .study-meta { max-width: 49vw; font-size: 11px; }
  .study-speech-notice { padding: 6px 8px; font-size: 10.5px; }
  /* A single stage scrollbar makes long meanings and examples discoverable. */
  .study-stage { overflow-y: auto; overscroll-behavior: contain; scrollbar-color: #b28b62 #f2e8d8; scrollbar-width: auto; padding-bottom: 30px; }
  .study-stage::-webkit-scrollbar { width: 10px; }
  .study-stage::-webkit-scrollbar-thumb { border: 2px solid #f2e8d8; border-radius: 99px; background: #b28b62; }
  .study-stage > .flashcard-landscape { height: auto; overflow: visible; margin: 8px auto 0; }
  .study-card-copy { max-height: none; overflow: visible; padding-top: 14px; }
  .flashcard-landscape .example-line { align-items: flex-start; }
  .flashcard-landscape .example-line [data-speak-example] { order: -1; }
  .flashcard-landscape .card-flip-hint { display: none; }
  .study-navigation { min-height: 93px; }
  .match-shell { padding: 7px; }
  .match-panel { min-height: calc(100dvh - 14px); border-radius: var(--surface-radius); }
  .match-head { padding: 11px 13px; }
  .match-head > .button { flex: none; min-width: 54px; padding-inline: 9px; white-space: nowrap; }
  .match-head > div { display: grid; grid-template-columns: max-content 1fr; gap: 3px 8px; }
  .match-head h2 { grid-column: 1 / -1; grid-row: 2; font-size: 24px; }
  .match-head .match-level { grid-column: 1; grid-row: 3; min-height: 25px; font-size: 10px; }
  .match-head .match-book-name { grid-column: 2; grid-row: 3; font-size: 11px; }
  .match-head p { position: absolute; }
  .match-play-area { padding: 12px 12px 20px; }
  .match-speech-notice { margin: 6px 0 4px; padding: 7px 9px; font-size: 10px; }
  .match-grid { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .match-tile { min-height: 94px; font-size: 13px; }
  .match-ready-overlay { position: fixed; inset: 129px 7px 7px; z-index: 120; padding: 12px; background: rgba(255,250,242,.8); }
  .match-complete::before { width: 155px; height: 95px; }
  body:has(.study-shell) #toast-root, body:has(.match-shell) #toast-root { top: 63px; right: auto; left: 50%; width: min(270px,calc(100vw - 16px)); }
  body:has(.match-shell) #toast-root { top: 116px; }
}
@media (max-width: 360px) {
  .flashcard-landscape .card-topline { min-height: 54px; }
  .study-card-layout { gap: 10px; }
  .study-card-copy { gap: 8px; padding-top: 8px; padding-bottom: 4px; }
  .study-picture { min-height: 0; }
  .study-picture img { height: 150px; }
}

/* Shared reference surfaces apply to all learning states, including overlays. */
.learning-page :is(.stat-card,.search-suggestions,.review-word-list) {
  border-color: var(--line); border-radius: var(--surface-radius);
  background: var(--paper); box-shadow: none;
}
.learning-page :is(input,select,.reset-learning-button,.learning-auth-status) { border-radius: var(--control-radius); }
.learning-page .plan-card { background: var(--pale); }
.learning-page .learning-actions .button.primary { background: var(--red); border-color: var(--red); }
:is(.study-shell,.match-shell) :is(.button,.rating-button,.match-level) { border-radius: var(--control-radius); box-shadow: none; }
.study-stage > .flashcard-landscape { border-color: var(--line); background: var(--paper); box-shadow: none; }
.flashcard-landscape::before { border-radius: var(--control-radius) var(--control-radius) 0 0; }
.study-picture, .study-picture img, .study-finished { border-radius: var(--surface-radius); }
.study-rating-actions .rating-button.good { background: var(--red); border-color: var(--red); }
.study-rating-actions .rating-button.again { color: var(--red); }
.match-panel, .match-ready-card { border-color: var(--line); background: var(--paper); box-shadow: none; }
.match-ready-card, .match-ready-overlay { border-radius: var(--surface-radius); }
.match-tile { border-radius: var(--surface-radius); border-bottom-width: 1px; box-shadow: none; color: var(--ink); background: var(--paper); }
.match-tile:hover { transform: none; box-shadow: none; }
.match-tile.selected, .match-tile.selected:hover { box-shadow: 0 0 0 2px rgba(168,59,50,.18); }
@media (max-width: 850px) {
  html[data-language="both"] .match-head > div { flex: 1; grid-template-columns: minmax(0,1fr); }
  html[data-language="both"] .match-head h2 { grid-column: 1; overflow-wrap: anywhere; }
  html[data-language="both"] .match-head .match-level { grid-column: 1; grid-row: 3; max-width: 100%; white-space: normal; overflow-wrap: anywhere; }
  html[data-language="both"] .match-head .match-book-name { grid-column: 1; grid-row: 4; }
  html[data-language="both"] .match-head > .button { flex: none; max-width: 90px; white-space: normal; }
  html[data-language="both"] .match-toolbar { flex-wrap: wrap; gap: 6px; }
}
