/*
 * Literate Japanese section (/japanese/...). Pages are written by
 * generate_japanese_pages.py. Class names match css/cantonese.css. Uses the site variables from styles.css, so
 * it follows the visitor's light/dark setting.
 *
 * Reader markup: <p class="yp"><span class="ys"><span class="yw"><ruby>字<rt>じ</rt></ruby>…
 * Hiding furigana uses visibility, so lines keep their height and the text
 * never moves when the reader toggles it.
 */
:root { --ja: #1a41af; --ja-tint: #e7ecfb; --ja-hl: #ffeaa8; }
@media (prefers-color-scheme: dark) { :root { --ja: #8ea7f6; --ja-tint: #18254d; --ja-hl: #4a3f14; } }

.yue-wrap { max-width: 860px; margin: 0 auto; }
.yue-wrap h1 { font-size: clamp(28px, 5vw, 40px); }
.yue-wrap h2 { margin-top: 1.7em; }
.yue-wrap [lang="ja"] { font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", Meiryo, sans-serif; }
.ja-page .logo .app-icon, .ja-page .app-icon-small { border-radius: 22%; }

/* ---------- story reader ---------- */
.ymeta { color: var(--muted); font-size: .95rem; margin-bottom: 14px; }
.yhero { width: 100%; height: auto; max-height: 340px; object-fit: cover; border-radius: var(--radius); margin: 4px 0 16px; outline: 1px solid var(--img-edge); outline-offset: -1px; }
.ytools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 18px 0 14px; position: sticky; top: 64px; z-index: 5; background: var(--bg); padding: 8px 0; }
.ybtn { font: inherit; font-weight: 700; font-size: .92rem; padding: 7px 14px; border-radius: 999px; border: 1.5px solid var(--border); background: var(--card); color: var(--ink); cursor: pointer; }
.ybtn[aria-pressed="true"] { background: var(--ja-tint); border-color: var(--ja); color: var(--ja); }
.yhint { color: var(--muted); font-size: .9rem; }
.yt { font-size: 1.7rem; }
.yp { margin: 0 0 .15em; line-height: 2.5; color: var(--ink); }
.yt ruby { ruby-position: over; ruby-align: center; }
.yt rt { font-size: .46em; color: var(--ja); font-weight: 500; letter-spacing: 0; user-select: none; -webkit-user-select: none; }
.jp-off rt { visibility: hidden; }
.yw { cursor: pointer; border-radius: 6px; padding: 0 1px; }
.yw:hover { background: var(--ja-tint); }
.yw.on { background: var(--ja-hl); }
.yx { display: none; margin: 0 0 1em; color: var(--muted); font-size: 1rem; line-height: 1.5; }
.yx span { display: none; }
.ystory.en-on .yx, .yx.has-on { display: block; }
.ystory.en-on .yx span, .yx span.on { display: inline; }
.ynav { display: flex; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin: 26px 0 8px; font-weight: 700; }
.ynav .ynext { margin-left: auto; }
.ycredit { color: var(--muted); font-size: .9rem; }

/* word card pinned to the bottom of the screen */
#ycard { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--card); border-top: 1px solid var(--border); box-shadow: 0 -8px 30px rgba(20, 40, 30, .16); padding: 14px 18px calc(14px + env(safe-area-inset-bottom)); transform: translateY(110%); transition: transform .18s ease; }
#ycard.open { transform: none; }
#ycard .yci { max-width: 860px; margin: 0 auto; display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: start; }
#ycard .ycw { font-size: 1.9rem; line-height: 1.2; }
#ycard .ycj { color: var(--ja); font-weight: 700; margin-left: 10px; font-size: 1.05rem; }
#ycard .ycd { grid-column: 1 / -1; color: var(--ink); }
#ycard .yce { grid-column: 1 / -1; color: var(--muted); font-size: .95rem; }
#ycard .ycb { display: flex; gap: 8px; align-items: center; }
#ycard button { font: inherit; font-weight: 700; font-size: .9rem; border-radius: 999px; border: 1.5px solid var(--border); background: var(--bg-soft); color: var(--ink); padding: 6px 12px; cursor: pointer; }
#ycard .ycx { border: 0; background: none; font-size: 1.3rem; padding: 2px 8px; color: var(--muted); }
.no-ja-voice .say, .no-ja-voice #ycard .ych { display: none; }
.say { font: inherit; font-size: .8rem; width: 30px; height: 30px; border-radius: 50%; border: 1.5px solid var(--ja); background: var(--ja-tint); color: var(--ja); cursor: pointer; padding: 0; line-height: 1; }
.say.playing { background: var(--ja); color: var(--on-primary); }
.tts-note { color: var(--muted); font-size: .9rem; }

/* ---------- tables ---------- */
.yt-table { width: 100%; border-collapse: collapse; margin: 16px 0 22px; font-size: 1rem; }
.yt-table th, .yt-table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.yt-table thead th { background: var(--bg-soft); font-size: .88rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.yt-table .yc { font-size: 1.45rem; white-space: nowrap; line-height: 1.3; }
.yt-table .yj { color: var(--ja); font-weight: 700; white-space: nowrap; }
.yt-table .yr { color: var(--muted); font-variant-numeric: tabular-nums; width: 3.2em; }
.yt-table .ynumc { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.yt-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ytag { display: inline-block; font-size: .72rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; background: var(--ja-tint); color: var(--ja); border-radius: 999px; padding: 2px 8px; vertical-align: middle; margin-left: 6px; white-space: nowrap; }
.yex { color: var(--muted); font-size: .95rem; }
.yex [lang="ja"] { color: var(--ink); font-size: 1.15rem; }

/* ---------- hub ---------- */
.ylist { list-style: none; margin: 14px 0 26px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.ylist li { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.ylist a { font-weight: 800; }
.ynum { display: inline-block; min-width: 1.7em; color: var(--muted); font-weight: 700; }
.ycount { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.ydesc { color: var(--muted); font-size: .92rem; }
.yzh { font-weight: 600; color: var(--muted); font-size: .8em; margin-left: 8px; }
.ytoc { columns: 2; column-gap: 28px; margin: 10px 0 10px 18px; }
.ysteps { margin: 10px 0 16px 22px; }
.ysteps li { margin-bottom: 6px; }
@media (max-width: 560px) { .ytoc { columns: 1; } .yt { font-size: 1.5rem; } .ytools { top: 56px; } }

/* ---------- reference pages ---------- */
.ychips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 20px; }
.ychip { display: inline-flex; align-items: baseline; gap: 6px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 6px 10px; }
.ychip b { font-size: 1.4rem; font-weight: 500; }
.ychip i { font-style: normal; color: var(--ja); font-weight: 700; font-size: .9rem; }
.ytone { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; margin: 16px 0 22px; }
.ytone div { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; text-align: center; }
.ytone b { display: block; font-size: 2.1rem; font-weight: 500; line-height: 1.2; }
.ytone i { font-style: normal; color: var(--ja); font-weight: 800; }
.ytone small { display: block; color: var(--muted); }
.ytone svg { display: block; margin: 6px auto 2px; }
.ydl { display: inline-block; font-weight: 800; background: var(--primary); color: var(--on-primary); border-radius: 999px; padding: 10px 18px; margin: 4px 8px 4px 0; text-decoration: none; }
.ydl:hover { background: var(--btn-hover); color: var(--on-primary); }

/* ---------- landing page ---------- */
.yland { max-width: 1000px; }
.yhero-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 34px; align-items: center; margin: 6px 0 30px; }
.yhero-grid h1 { font-size: clamp(34px, 6vw, 52px); margin-bottom: .3em; }
.yhero-grid .ysub { font-size: 1.2rem; color: var(--muted); max-width: 520px; }
.yhero-grid .yshot { width: 100%; max-width: 330px; height: auto; justify-self: center; border-radius: 26px; box-shadow: var(--shadow); }
.ylive { display: inline-block; background: var(--ja-tint); color: var(--ja); font-weight: 800; font-size: .9rem; padding: 5px 12px; border-radius: 999px; margin-bottom: 14px; }
.yfree { color: var(--muted); font-size: .95rem; margin-top: 12px; }
.yshots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin: 22px 0 30px; }
.yshots img { width: 100%; height: auto; border-radius: 18px; box-shadow: var(--shadow-sm); }
.ystats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin: 20px 0 28px; }
.ystats div { background: var(--bg-soft); border-radius: var(--radius-sm); padding: 16px; text-align: center; }
.ystats b { display: block; font-size: 1.9rem; color: var(--ja); }
.ystats span { color: var(--muted); font-size: .92rem; }
@media (max-width: 760px) {
  .yhero-grid { grid-template-columns: 1fr; gap: 20px; }
  .yshots { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Japanese additions ---------- */
.ja-page .nav-cta, .ja-page .ydl, .ja-page .cta-box .ydl { background: var(--ja); color: #fff; }
@media (prefers-color-scheme: dark) { .ja-page .nav-cta, .ja-page .ydl { color: #0d1430; } }
.yue-wrap rt { font-size: .5em; color: var(--ja); user-select: none; -webkit-user-select: none; }
.yt-table .yc rt { font-size: .45em; }
#ycard .ycl { grid-column: 1 / -1; color: var(--muted); font-size: .95rem; }
#ycard .ycl b { color: var(--ink); font-weight: 600; font-size: 1.15rem; }
.ylv { display: inline-block; font-size: .72rem; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; background: var(--ja-tint); color: var(--ja); border-radius: 999px; padding: 2px 8px; vertical-align: middle; white-space: nowrap; }
.ysoon { display: inline-block; background: var(--ja-tint); color: var(--ja); font-weight: 800; font-size: .9rem; padding: 5px 12px; border-radius: 999px; margin-bottom: 14px; }

/* kana charts */
.kgrid { display: grid; gap: 8px; margin: 12px 0 22px; }
.kgrid.c5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kgrid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 420px; }
.kcell { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 4px 8px; text-align: center; cursor: pointer; font: inherit; color: var(--ink); }
.kcell:hover, .kcell.playing { border-color: var(--ja); background: var(--ja-tint); }
.kcell b { display: block; font-size: 2rem; font-weight: 500; line-height: 1.25; }
.kcell i { font-style: normal; color: var(--ja); font-weight: 700; font-size: .92rem; }
.kcell.kgap { visibility: hidden; }
.kwords { list-style: none; margin: 10px 0 20px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.kwords li { background: var(--bg-soft); border-radius: 10px; padding: 8px 12px; }
.kwords b { font-size: 1.3rem; font-weight: 500; margin-right: 6px; }
.kwords i { font-style: normal; color: var(--ja); font-weight: 700; margin-right: 6px; }
.kwords span { color: var(--muted); }
.ktips { margin: 8px 0 14px 20px; }
.ktips li { margin-bottom: 4px; }

/* kanji tiles */
.kjgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 14px 0 24px; }
.kj { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; }
.kj b { display: block; font-size: 2.2rem; font-weight: 500; line-height: 1.2; }
.kj .kr { display: block; color: var(--ja); font-weight: 600; font-size: .9rem; }
.kj .km { display: block; color: var(--muted); font-size: .88rem; line-height: 1.35; margin-top: 2px; }

/* grammar */
.gpat { font-size: 1.25rem; background: var(--ja-tint); color: var(--ink); border-radius: 12px; padding: 12px 16px; margin: 10px 0 18px; }
.gex { margin: 0 0 16px; padding: 0; list-style: none; }
.gex li { border-left: 3px solid var(--ja-tint); padding: 4px 0 4px 14px; margin-bottom: 12px; }
.gex .gj { font-size: 1.45rem; line-height: 2.1; display: block; }
.gex .gj mark { background: var(--ja-hl); color: inherit; border-radius: 4px; padding: 0 1px; }
.gex .ge { color: var(--muted); display: block; }
.gbad { color: #b3261e; text-decoration: line-through; text-decoration-thickness: 1px; }
@media (prefers-color-scheme: dark) { .gbad { color: #f2a59f; } }
.glist { list-style: none; margin: 12px 0 26px; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 10px; }
.glist li { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px; }
.glist a { font-weight: 800; }
.glist li > span { display: block; color: var(--muted); font-size: .95rem; }

/* story quiz */
.yquiz { margin: 8px 0 20px; }
.yq { margin: 0 0 18px; }
.yq .yqq { font-size: 1.35rem; line-height: 2.1; margin: 0 0 6px; }
.yq button { display: block; width: 100%; text-align: left; font: inherit; font-size: 1.2rem; line-height: 1.9; background: var(--card); color: var(--ink); border: 1.5px solid var(--border); border-radius: 12px; padding: 4px 14px; margin: 0 0 6px; cursor: pointer; }
.yq button.right { border-color: #2e9e5b; background: rgba(46, 158, 91, .14); }
.yq button.wrong { border-color: #c9483f; background: rgba(201, 72, 63, .12); }
.ja-page main a:not(.ydl):not(.ybtn), .ja-page .cta-box a:not(.ydl) { color: var(--ja); }
.ja-page a.category-card h3 { color: var(--ja); }
.ysample { background: var(--bg-soft); border-radius: var(--radius); padding: 14px 20px 6px; margin: 10px 0 26px; }
.ysample .ytools { background: none; }
