/* ═══════════════════════════════════════════════════════════
   Languages (fonts, RTL) and phone / tablet layouts
   ═══════════════════════════════════════════════════════════ */
:root { --chrome: 360px; }
html { overscroll-behavior: none; }
.topbar-right { display: flex; gap: 8px; }
.stage-title { min-width: 0; }

/* ── per-language fonts ─────────────────────────────────── */
html:lang(ja) { --font: "Yu Gothic UI", "Hiragino Sans", "Meiryo", "Noto Sans JP", system-ui, sans-serif; --round: "Yu Gothic UI", "Hiragino Sans", "Meiryo", "Noto Sans JP", sans-serif; }
html:lang(ko) { --font: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif; --round: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; }
html:lang(ar) { --font: "Segoe UI", "Tahoma", "Noto Sans Arabic", "Geeza Pro", system-ui, sans-serif; --round: "Segoe UI", "Tahoma", "Noto Sans Arabic", "Geeza Pro", sans-serif; }
html:lang(ru), html:lang(en), html:lang(es), html:lang(pt), html:lang(fr), html:lang(de), html:lang(ms) { --font: "Segoe UI", "Roboto", "Helvetica Neue", Arial, system-ui, sans-serif; --round: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", Arial, sans-serif; }
/* long Latin / Cyrillic / Arabic names are smaller than the chunky Chinese logo */
html:not(:lang(zh)):not(:lang(ja)):not(:lang(ko)) .title-logo h1 { font-size: clamp(34px, 9vw, 78px); line-height: 1.08; letter-spacing: 0; -webkit-text-stroke-width: 9px; padding: 0 6px; }
html:lang(ar) .title-logo h1 { letter-spacing: 0; }
.hud-label, .modal-kicker, .ribbon { letter-spacing: .08em; }
html:lang(ar) .hud-label, html:lang(ar) .modal-kicker { letter-spacing: 0; }
.mode-card h3, .prompt-main, .btn { overflow-wrap: anywhere; }
.btn { text-align: center; }

/* ── language picker ────────────────────────────────────── */
.lang-btn { position: absolute; top: max(12px, env(safe-area-inset-top)); inset-inline-end: 14px; z-index: 3; }
.lang-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 12px; }
.lang-opt { margin-top: 0 !important; font-size: 15px !important; }
.lang-opt.is-on { background: linear-gradient(180deg, #ffd57a, #ffb02e) !important; }

/* ── right-to-left (Arabic) ─────────────────────────────── */
[dir="rtl"] .board { direction: ltr; }
[dir="rtl"] .combo-card { text-align: left; }
[dir="rtl"] .chev { display: inline-block; transform: scaleX(-1); }
[dir="rtl"] #backBtn svg { transform: scaleX(-1); }
[dir="rtl"] .prompt-time i { transform-origin: right center; }
[dir="rtl"] .lab { left: auto; right: 12px; }
[dir="rtl"] .modal-foot, [dir="rtl"] .field-label { direction: rtl; }
.chev { font-size: 1.3em; line-height: 1; font-weight: 900; }

/* ── safe areas / touch ─────────────────────────────────── */
.app { padding-left: max(clamp(10px, 3vw, 26px), env(safe-area-inset-left)); padding-right: max(clamp(10px, 3vw, 26px), env(safe-area-inset-right)); padding-bottom: max(20px, env(safe-area-inset-bottom)); }
.board, .board-frame { touch-action: none; }
body.is-playing { overflow: hidden; }

/* ── phones, portrait ───────────────────────────────────── */
@media (max-width: 520px) {
  :root { --chrome: 268px; }
  .hint { display: none; }
  .app { padding-top: max(6px, env(safe-area-inset-top)); }
  .icon-btn { width: 42px; height: 42px; border-radius: 13px; border-width: 2.5px; }
  .stage-title b { font-size: 15px; }
  .hud { gap: 6px; margin: 6px 0 9px; }
  .hud-card { padding: 5px 9px 6px; border-width: 2.5px; border-radius: 15px; }
  .hud-label { font-size: 9px; }
  .hud-value { font-size: 23px; }
  .hud-sub { font-size: 9.5px; }
  .timer-wrap { width: 70px; }
  .timer-content span { font-size: 22px; }
  .level-badge { font-size: 9px; padding: 1px 8px; }
  .prompt { min-height: 54px; margin-bottom: 9px; padding: 6px 12px 7px; border-width: 2.5px; border-radius: 18px; }
  .prompt-main { font-size: 17px; gap: 6px; }
  .prompt-main .sample { --sz: 58px !important; }
  .prompt-sub { font-size: 10.5px; }
  .board-frame { padding: 7px; border-width: 3px; border-radius: 22px; }
  .board { padding: 5px; border-width: 2px; border-radius: 16px; }
  .board-flower { display: none; }
  .lab { bottom: 6px; left: 6px; width: 150px; font-size: 10px; padding: 6px 8px 8px; }
  [dir="rtl"] .lab { left: auto; right: 6px; }
  .btn { font-size: 17px; padding: 11px 18px; }
  .title-actions .btn--big { font-size: 22px; padding: 12px 30px; min-height: 60px; }
  .lang-grid { grid-template-columns: 1fr 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
  .panel { padding: 14px 12px; border-radius: 22px; }
  .screen { padding: 12px 10px 28px; }
  .toast { font-size: 11px; padding: 7px 12px; white-space: normal; text-align: center; }
}
@media (max-width: 380px) {
  :root { --chrome: 252px; }
  .hud-value { font-size: 21px; }
  .timer-wrap { width: 64px; }
  .prompt-main { font-size: 15.5px; }
  .world-tab { font-size: 11.5px; padding: 6px 10px; }
  .stage-path { gap: 10px 4px; }
}

/* ── phones, landscape: HUD on the left, board on the right ── */
@media (orientation: landscape) and (max-height: 560px) {
  :root { --chrome: 80px; }
  .hint { display: none; }
  .app { padding: 6px max(12px, env(safe-area-inset-right)) 6px max(12px, env(safe-area-inset-left)); min-height: 100svh; }
  .topbar { position: absolute; z-index: 6; top: max(6px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); width: auto; margin: 0; pointer-events: none; }
  .topbar > * { pointer-events: auto; }
  .stage-title { display: none; }
  .icon-btn { width: 38px; height: 38px; border-radius: 12px; border-width: 2.5px; }
  .game-shell { width: 100%; max-width: none; display: grid; grid-template-columns: minmax(150px, 31%) 1fr; grid-template-rows: auto auto 1fr; column-gap: 14px; align-content: start; align-items: start; padding-top: 46px; min-height: calc(100svh - 12px); }
  .hud { grid-column: 1; grid-row: 1; grid-template-columns: 1fr; gap: 5px; margin: 0 0 7px; }
  .hud-card { padding: 4px 9px 5px; border-width: 2.5px; border-radius: 13px; }
  .hud-value { font-size: 21px; }
  .hud-label, .hud-sub { font-size: 9px; }
  .combo-meter { margin-top: 3px; height: 5px; }
  .timer-wrap { width: 62px; margin: 0 auto; }
  .timer-content span { font-size: 19px; }
  .prompt { grid-column: 1; grid-row: 2; min-height: 0; margin: 4px 0 0; padding: 5px 8px 6px; border-width: 2.5px; border-radius: 15px; }
  .prompt-main { font-size: 14px; }
  .prompt-main .sample { --sz: 48px !important; margin: -4px 1px -6px; }
  .prompt-sub { font-size: 9.5px; }
  .prompt::before, .prompt::after { display: none; }
  .board-shell { grid-column: 2; grid-row: 1 / span 3; align-self: center; justify-self: center; margin: 0; width: min(100%, calc((100svh - 62px) * var(--ar, 1.08))); }
  .board-frame { padding: 6px; border-width: 3px; border-radius: 20px; }
  .board { padding: 4px; }
  .board-flower { display: none; }
  .lab { bottom: 6px; }
  .modal { max-height: calc(100svh - 12px); padding: 16px 16px 14px; }
  .intro-art { height: 62px; } .intro-art .tm { width: 58px; }
  .unlock-burst { width: 90px; height: 90px; }
  .result-stars .result-star { width: 40px; height: 40px; } .result-star:nth-child(2) { width: 50px; height: 50px; margin-top: -8px; }
  .result-score span { font-size: 46px; }
  .title-moles { height: 70px; } .title-moles .tm { width: 52px; }
  .title-logo h1 { font-size: clamp(34px, 8vw, 60px) !important; }
  .title-sub { margin: 6px 0 10px; }
  .screen { padding-top: 10px; }
}

/* ── tablets & big screens keep the roomy layout ─────────── */
@media (min-width: 768px) and (orientation: portrait) {
  :root { --chrome: 330px; }
}
@media (orientation: landscape) and (max-height: 560px) {
  .lab { top: max(6px, env(safe-area-inset-top)); bottom: auto; left: 58px; width: 156px; }
  [dir="rtl"] .lab { left: auto; right: 58px; }
}
