/* Mahjong Score 15.9: explicit theme wins over device defaults and legacy rules. */
html[data-theme="light"]{--ui-bg:#f3f1e8;--ui-card:#fff;--ui-text:#202a24;--ui-muted:#526158;--ui-line:#bbc4bd;--ui-accent:#866219;--ui-head:#253e32;--glass:#f3f1e8;--cream:#f3f1e8;--ink:#202a24;color-scheme:light}
html[data-theme="dark"]{--ui-bg:#202c25;--ui-card:#324038;--ui-text:#f5f7f3;--ui-muted:#c6d0c8;--ui-line:#718078;--ui-accent:#f4ce72;--ui-head:#17281f;--glass:#202c25;--cream:#202c25;--ink:#f5f7f3;color-scheme:dark}
.theme-setting{display:flex!important;align-items:center;justify-content:space-between;gap:10px;margin:0!important}
#settings .theme-setting select{width:auto;max-width:55%;min-height:36px;border-radius:8px;padding:4px 8px;font:inherit}
html[data-theme] #scorePanel,html[data-theme] .bottom,html[data-theme] .auth-card{background:var(--ui-bg)!important;color:var(--ui-text)!important;border-color:var(--ui-line)!important}
html[data-theme] #scorePanel :is(.step,.label,.preview,.muted,.pattext,.pattext small,.totalbar b){color:var(--ui-text)!important}
html[data-theme] #scorePanel :is(.badge,summary,.totalbar,.quadbox,.quad-wheel,.pat span,.choice button){background:var(--ui-card)!important;color:var(--ui-text)!important;border-color:var(--ui-line)!important}
html[data-theme] #scorePanel :is(.choice button.on,.pat input:checked+span){background:#b48c30!important;color:#fff!important}
html[data-theme] #scorePanel .pat em{color:var(--ui-accent)!important}
html[data-theme] :is(input,select,textarea){color-scheme:inherit}
html[data-theme] .action-menu{background:var(--ui-bg)!important;color:var(--ui-text)!important}
html[data-theme] .action-menu button{color:var(--ui-text)!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal){--ink:var(--ui-text);--cream:var(--ui-bg);--line:var(--ui-line);color:var(--ui-text)!important;color-scheme:inherit!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) .modal{background:var(--ui-bg)!important;color:var(--ui-text)!important;border-color:var(--ui-line)!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) :is(.data-modal-head,.transfer-modal-head,.rules-head,.voice-diag-header){background:var(--ui-head)!important;color:#fff!important;border-color:var(--ui-line)!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) :is(.data-modal-head,.transfer-modal-head,.rules-head,.voice-diag-header) :is(h2,h3,h4,.muted){color:#fff!important;opacity:1!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) :is(.modal-x,.rules-x){background:#50645a!important;color:#fff!important;border:1px solid #a7b5ac!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) :is(.btn:not(.gold):not(.danger),.manual-points-setting,.rules-section,.rules-payment-card,.rules-visual,.rules-set,.user-row,.user-detail-grid,.voice-diag-panel){background:var(--ui-card)!important;color:var(--ui-text)!important;border-color:var(--ui-line)!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) :is(.muted,.rules-caption,.user-row .muted,.rules-section h4){color:var(--ui-muted)!important;opacity:1!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) :is(input:not([type=checkbox]):not([type=radio]),select,textarea){background:var(--ui-card)!important;color:var(--ui-text)!important;border-color:var(--ui-line)!important}
html[data-theme] :is(#gameTransferMenuModal,#receiveQRHelpModal,#qrTransferModal,#liveSharingModal,#groupedMenu,#falseHuModal,#falseHuCorrectionModal,#historyModal,#recapModal,#players,#roundModal,#editScore,#rolePicker,#userManagement,#userDetail,#settings,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rulesGuide,#patternGuide,#new,#localPhotoModal,#photoScoreModal) :is(a,.rules-section h3,.rules-term){color:var(--ui-accent)!important}
/* The standalone reader and its embedded document use the same saved theme. */
html[data-theme] body:has(main #preview){background:var(--ui-bg)!important;color:var(--ui-text)!important}
html[data-theme] body:has(main #preview) :is(small,.reader-detail){color:var(--ui-muted)!important}
html[data-theme] body:has(main #preview) :is(.tile-card,canvas){background:var(--ui-card)!important;color:var(--ui-text)!important}

html[data-theme] #localPhotoModal iframe{background:var(--ui-bg)!important}
/* iPhone's earlier compact winner row also sets text fill explicitly. */
html[data-theme] #scorePanel #winnerStatus,html[data-theme] #scorePanel #winnerStatus *{color:var(--ui-text)!important;-webkit-text-fill-color:var(--ui-text)!important}
html[data-theme="light"]{--ui-hint:#8a391c}
html[data-theme="dark"]{--ui-hint:#ffd178}
html[data-theme] #scorePanel #winnerStatus :is(.winner-next,#winnerText){color:var(--ui-hint)!important;-webkit-text-fill-color:var(--ui-hint)!important;opacity:1!important}
html[data-theme] #scorePanel .muted{color:var(--ui-muted)!important;opacity:1!important}
html[data-theme] #scorePanel .quad-limit-note{color:var(--ui-hint)!important}
html[data-theme] .menu-hongzhong{color:var(--ui-text)!important}
/* Player cards keep their ivory faces in both themes. */
html[data-theme] .table .player{color:#202a24!important}
html[data-theme] body{color:var(--ui-text)}

/* v15.9 r6 — approved Quad and player-card layouts. */
html[data-theme="dark"] .quad-control>.quad-step,
html[data-theme="dark"] .quad-control>input.quad-value{
 background:transparent!important;color:#f5f7f3!important;-webkit-text-fill-color:#f5f7f3!important;
 border:0!important;box-shadow:none!important;backdrop-filter:none!important;-webkit-backdrop-filter:none!important
}
@media(max-width:600px){html[data-theme="dark"] .quad-wheel-guide{border-top:1px solid rgba(255,255,255,.8)!important;border-bottom:1px solid rgba(255,255,255,.8)!important}}
.player:has(.player-photo[hidden]) .handwins{padding-left:0!important;padding-right:0!important;text-align:center!important;justify-content:center!important;width:100%;box-sizing:border-box}
.about-licenses{font-size:11px;line-height:1.5;margin-top:22px;padding-top:12px;border-top:1px solid var(--ui-line)}
.about-licenses p{margin:4px 0}
/* Every dialog separates the full-width fixed header from its scrolling body. */
html[data-theme] :is(#settings,#userManagement,#userDetail,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rolePicker,#historyModal,#recapModal,.overlay)>.modal.unified-modal{
 display:flex!important;flex-direction:column!important;padding:0!important;overflow:hidden!important;
 max-height:calc(92dvh - 16px)!important;scrollbar-gutter:auto!important;box-sizing:border-box!important;
 background:var(--ui-bg)!important;color:var(--ui-text)!important
}
html[data-theme] :is(#settings,#userManagement,#userDetail,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rolePicker,#historyModal,#recapModal,.overlay)>.modal.unified-modal>.unified-modal-head{
 position:relative!important;top:auto!important;flex:0 0 auto!important;align-self:stretch!important;
 display:flex!important;align-items:center!important;justify-content:space-between!important;
 width:100%!important;box-sizing:border-box!important;margin:0!important;padding:16px 18px!important;
 gap:12px!important;border-radius:0!important;background:var(--ui-head)!important;color:#fff!important;
 border-bottom:1px solid var(--ui-line)!important;box-shadow:none!important
}
html[data-theme] :is(#settings,#userManagement,#userDetail,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rolePicker,#historyModal,#recapModal,.overlay)>.modal.unified-modal>.unified-modal-head :is(h2,h3){margin:0!important;color:#fff!important;font-size:clamp(19px,3.5vw,27px)!important;line-height:1.2!important;min-width:0;overflow-wrap:anywhere}
html[data-theme] :is(#settings,#userManagement,#userDetail,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rolePicker,#historyModal,#recapModal,.overlay)>.modal.unified-modal>.unified-modal-head>:is(.modal-x,.rules-x,.guide-x){flex:0 0 38px!important;min-width:38px!important;height:38px!important;margin:0!important;color:#fff!important}
html[data-theme] :is(#settings,#userManagement,#userDetail,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rolePicker,#historyModal,#recapModal,.overlay)>.modal.unified-modal>.modal-scroll-body{
 min-height:0!important;flex:0 1 auto!important;overflow:auto!important;overscroll-behavior:contain;
 -webkit-overflow-scrolling:touch;padding:14px 18px 18px!important;box-sizing:border-box!important;
 width:100%!important;margin:0!important;scrollbar-gutter:stable both-edges
}
html[data-theme] #aboutProgram .unified-modal .about-scroll-body{overflow:visible!important;max-height:none!important;padding:0!important}
@media(max-width:600px){html[data-theme] :is(#settings,#userManagement,#userDetail,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rolePicker,#historyModal,#recapModal,.overlay)>.modal.unified-modal>.unified-modal-head{padding:13px 12px!important}html[data-theme] :is(#settings,#userManagement,#userDetail,#aboutProgram,#aiDiagnostic,#voiceDiagnostic,#rolePicker,#historyModal,#recapModal,.overlay)>.modal.unified-modal>.modal-scroll-body{padding:12px!important}}

/* Secondary instruction shares the Quad hint size in every responsive layout. */
html[data-theme] #scorePanel .pattern-toggle-hint{color:var(--ui-hint)!important;font-size:11px;font-weight:800;white-space:nowrap}
@media(max-width:600px){html[data-theme] #scorePanel .pattern-toggle-hint{font-size:7px!important;line-height:1!important}}
@media(max-width:420px){html[data-theme] #scorePanel .pattern-toggle-hint{font-size:7px!important;line-height:1!important}}

/* Plain scoring instructions; only the expandable combination heading remains a card. */
html[data-theme] #scorePanel .step>.badge{
 background:transparent!important;border:0!important;border-radius:0!important;box-shadow:none!important;
 -webkit-backdrop-filter:none!important;backdrop-filter:none!important
}

html[data-theme="dark"] #editScore :is(.quadbox,.quad-wheel,.seg button){
 background:var(--ui-card)!important;color:var(--ui-text)!important;border-color:var(--ui-line)!important
}
html[data-theme="dark"] #editScore .label{color:var(--ui-muted)!important}
html[data-theme="dark"] #editScore :is(.quad-step,input.quad-value){
 background:var(--ui-bg)!important;border:1px solid var(--ui-line)!important
}
html[data-theme] #editScore .seg button.on{
 background:var(--ui-head)!important;color:#fff!important;border-color:var(--ui-accent)!important
}
html[data-theme="dark"] #editScore .seg button.on{
 background:var(--ui-accent)!important;color:var(--ui-head)!important
}
