/* Shared controls and reading hierarchy. The arena background is unchanged. */
body#top[data-page='play'] {
  --ui-modal-ink:#f6f1fc; --ui-modal-muted:#c9bfd5;
  --ui-modal-surface:linear-gradient(145deg,#261b36,#151020);
  --ui-modal-line:#776387; --ui-modal-accent:#c7ff65;
  --ui-modal-radius:18px; --ui-control-radius:10px;
}
html[data-theme='light'] body#top[data-page='play'] {
  --ui-modal-ink:#30223e; --ui-modal-muted:#62516f;
  --ui-modal-surface:linear-gradient(145deg,#fffdfd,#eee7f3);
  --ui-modal-line:#ad9bb9; --ui-modal-accent:#496d00;
}
body#top[data-page='play'] #match-intro-modal { --ui-modal-accent:var(--match-azure); }
body#top[data-page='play'] #core-modal { --ui-modal-accent:#eac56c; }
html[data-theme='light'] body#top[data-page='play'] #core-modal { --ui-modal-accent:#84600f; }
body#top[data-page='play'] #game-confirm-modal { --ui-modal-accent:#ff628c; }
html[data-theme='light'] body#top[data-page='play'] #game-confirm-modal { --ui-modal-accent:#a62b51; }

/* Stable shells retain their existing dimensions and page/footer positions. */
html[data-theme] body#top[data-page='play'] :is(
  #match-intro-modal>.modal-card,#core-modal>.modal-card,
  #gameover-modal>.modal-card,#ftue-welcome-modal>.modal-card,
  #tut-intro-modal>.tut-intro-card,#tut-completion-modal>.tut-modal-card,
  #game-confirm-modal>.confirm-card,#phone-tutorial-briefing
) {
  border-radius:var(--ui-modal-radius)!important;
  border:1px solid color-mix(in srgb,var(--ui-modal-accent) 35%,var(--ui-modal-line))!important;
  background:var(--ui-modal-surface)!important; color:var(--ui-modal-ink)!important;
  box-shadow:0 14px 48px #0005!important;
}
html[data-theme] body#top[data-page='play'] :is(#match-intro-modal,#core-modal,#gameover-modal,#ftue-welcome-modal)>.modal-card::before {
  content:none!important;
}
/* The viewport guard must not expand reading dialogs to the full desktop width. */
html[data-theme] body#top[data-page='play']:not(.phone-match-active) :is(#gameover-modal,#ftue-welcome-modal)>.modal-card {
  width:min(560px,calc(100vw - 48px))!important; max-width:560px!important;
  padding:28px!important; gap:12px;
}
html[data-theme] body#top[data-page='play']:not(.phone-match-active) #gameover-modal :is(#btn-new-game,#btn-go-exit) {
  width:100%; min-height:44px; margin:0!important;
}
html[data-theme] body#top[data-page='play'] :is(
  #match-intro-modal,#core-modal,#gameover-modal,#ftue-welcome-modal,
  #tut-intro-modal,#tut-completion-modal,#game-confirm-modal,#phone-tutorial-briefing
) .btn {
  min-height:44px; border-radius:var(--ui-control-radius)!important;
  font-family:Inter,sans-serif!important; font-weight:700!important;
  letter-spacing:.3px!important; line-height:1.25!important;
}
html[data-theme] body#top[data-page='play'] :is(
  .phone-rule-close,.phone-match-intro-close
) {
  width:auto!important; min-width:64px!important; min-height:44px!important; height:44px!important;
  padding:8px 12px!important; border-radius:var(--ui-control-radius)!important;
  border:1px solid var(--ui-modal-line)!important; background:transparent!important;
  color:var(--ui-modal-ink)!important; font:600 12px/1.2 Inter,sans-serif!important;
  box-sizing:border-box;
}
html[data-theme] body#top[data-page='play'] :is(
  .tut-modal-title,.phone-briefing-title,#gcm-title
) {
  color:var(--ui-modal-ink)!important;
  font-family:Orbitron,Inter,sans-serif!important;
  font-size:clamp(20px,2.2vw,28px)!important; line-height:1.2!important;
  letter-spacing:.6px!important;
}
html[data-theme] body#top[data-page='play'] #color-select-title {
  color:var(--ui-modal-ink)!important;
  font:700 18px/1.3 Inter,sans-serif!important; letter-spacing:.4px!important;
}
html[data-theme] body#top[data-page='play'] :is(
  #color-select-status,#gcm-desc,.ftue-desc,.phone-briefing-copy,.tut-modal-subtitle
) {
  color:var(--ui-modal-muted)!important; font:500 14px/1.5 Inter,sans-serif!important;
  letter-spacing:0!important;
}
html[data-theme] body#top[data-page='play'] :is(.modal-label,.phone-rule-counter,.phone-briefing-badge,.ftue-eyebrow) {
  font:800 11px/1.3 Inter,sans-serif!important; letter-spacing:1.2px!important;
  color:var(--ui-modal-accent)!important;
}
html[data-theme] body#top[data-page='play'] :is(#tut-intro-modal,#tut-completion-modal,#phone-tutorial-briefing) {
  --phone-tut-ink:var(--ui-modal-ink); --phone-tut-muted:var(--ui-modal-muted);
  --phone-tut-edge:var(--ui-modal-line); --phone-tut-panel:var(--ui-modal-surface);
}
html[data-theme] body#top[data-page='play'] .phone-pagination-active .tut-rule-card h4 {
  font:700 20px/1.25 Orbitron,Inter,sans-serif!important; letter-spacing:.3px!important;
}
html[data-theme] body#top[data-page='play'] .phone-pagination-active .tut-rule-card p {
  font:500 15px/1.5 Inter,sans-serif!important;
}

/* The Core is the active event; reference rails return in their original place. */
body#top[data-page='play']:has(#core-modal.active) :is(#left-sidebar,#rb-sidebar,#rb-hover-overlay,[id^='rb-img-'],[id^='left-img-'],#btn-close-reference) {
  visibility:hidden!important; opacity:0!important; pointer-events:none!important;
}

@media (orientation:landscape) and (max-width:1100px) and (max-height:599px) {
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal>.modal-card {
    grid-template-rows:44px minmax(0,1fr);
  }
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal .modal-label {
    grid-area:1 / 1; align-self:center; padding:0;
  }
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal .phone-match-intro-close {
    position:static; grid-area:1 / 2; justify-self:end; align-self:center;
  }
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal :is(#color-select-section,.modal-card>div:nth-child(4)) {
    grid-row:2;
  }
  html[data-theme] body#top[data-page='play'].phone-match-active .phone-status-title {
    font:800 11px/1.25 Inter,sans-serif;
  }
  body#top[data-page='play'].phone-match-active .player-identity-label { font-size:9px!important; letter-spacing:.5px; }
  body#top[data-page='play'].phone-match-active #game-screen>.row-popup .row-popup-lbl { font-size:10px; line-height:12px; }
  body#top[data-page='play'].phone-match-active #game-screen>.row-popup .popup-roll-note::before { font-size:10px; line-height:12px; }
  body#top[data-page='play'].phone-match-active.combat-active #action-bar #cb-outcome {
    font:800 14px/1.2 Inter,sans-serif!important; letter-spacing:.2px!important;
  }
  html[data-theme] body#top[data-page='play'] #phone-tutorial-briefing .phone-briefing-title { font-size:26px!important; }
  html[data-theme] body#top[data-page='play'] :is(#tut-intro-modal>.tut-intro-card,#tut-completion-modal>.tut-modal-card,#phone-tutorial-briefing) {
    padding:16px 20px!important;
  }
}

/* Keep the introduction readable above its fixed navigation on short phones. */
@media (orientation:landscape) and (max-width:1100px) and (max-height:299px) {
  html[data-theme] body#top[data-page='play'] #tut-intro-modal.phone-pagination-active>.tut-intro-card {
    grid-template-rows:44px 24px minmax(0,1fr) 48px;
    gap:5px; padding:8px 16px!important;
  }
  html[data-theme] body#top[data-page='play'] #tut-intro-modal.phone-pagination-active .tut-modal-title {
    font-size:18px!important; line-height:1.2!important;
  }
  html[data-theme] body#top[data-page='play'] #tut-intro-modal.phone-pagination-active .tut-rule-card {
    padding:0!important; gap:6px;
  }
  html[data-theme] body#top[data-page='play'] #tut-intro-modal.phone-pagination-active .tut-rule-card h4 {
    font-size:17px!important; line-height:1.2!important;
  }
  html[data-theme] body#top[data-page='play'] #tut-intro-modal.phone-pagination-active .tut-rule-card p {
    font:500 13px/1.35 Inter,sans-serif!important;
  }
}

/* Light-mode available units and controls share a restrained surface treatment. */
html[data-theme='light'] body#top[data-page='play'].phone-match-active {
  --phone-reserve-unit-ink:#65470d; --phone-reserve-unit-lost:#716172;
}
html[data-theme='light'] body#top[data-page='play'].phone-match-active .phone-reserve-carousel .die-chip[data-phone-status='available'] .chip-svg g[opacity='0.25'] {
  opacity:.5;
}
html[data-theme='light'] body#top[data-page='play'].phone-match-active :is(#action-bar .act-btn,#phone-reference-toggle,.site-header .menu-toggle,.row-popup .popup-actions .btn) {
  box-shadow:0 2px 8px #38204612!important;
}
html[data-theme='light'] body#top[data-page='play'].phone-match-active #action-bar .act-btn:disabled { box-shadow:none!important; }

/* Compact phones get their own composition, not a scaled-down wide-phone UI.
   A 102px reserve retains two 44px dice targets. Battle panels share its width,
   and the field reserves the same result/footer clearance in every phase. */
@media (orientation:landscape) and (max-width:620px) and (min-height:300px) and (max-height:350px) {
  body#top[data-page='play'].phone-match-active {
    --phone-reserve-width:102px; --phone-combat-width:102px;
    --phone-action-height:44px; --phone-dock-width:144px;
    --phone-board-clearance:6px;
    --phone-combat-height:min(210px,calc(100dvh - var(--phone-safe-top) - var(--phone-action-bottom) - 86px));
    --hud-w:calc(var(--phone-reserve-width) + 24px);
  }
  body#top[data-page='play'].phone-match-active #main-game-area {
    top:calc(26px + var(--phone-safe-top));
    bottom:calc(var(--phone-action-bottom) + (var(--phone-menu-size) + 76px) / 2 + 8px)!important;
  }
  body#top[data-page='play'].phone-match-active:not(.combat-active) #action-bar .act-btn {
    min-width:44px; font-size:11px;
  }
  body#top[data-page='play'].phone-match-active:not(.combat-active) #action-bar .act-text { font-size:11px; }
  body#top[data-page='play'].phone-match-active #game-screen>.row-popup:not(.popup-observer) {
    --prompt-width:152px; --prompt-height:76px;
    grid-template-columns:32px minmax(0,1fr)!important;
    grid-template-rows:12px minmax(0,1fr)!important; padding:4px!important; gap:4px!important;
  }
  body#top[data-page='play'].phone-match-active #game-screen>.row-popup:not(.popup-observer) .popup-big-val {
    grid-area:2 / 1; padding:0; font-size:25px;
  }
  body#top[data-page='play'].phone-match-active #game-screen>.row-popup:not(.popup-observer) .popup-actions {
    grid-area:2 / 2; align-items:center;
  }
  body#top[data-page='play'].phone-match-active #game-screen>.row-popup:not(.popup-observer) .popup-actions .btn {
    padding:4px 2px!important; font-size:11px;
  }
  body#top[data-page='play'].phone-match-active.combat-active #action-bar #cb-outcome { font-size:12px!important; }
  body#top[data-page='play'].phone-match-active.combat-active #game-screen :is(.cb-role-badge,.csp-unit) {
    left:0!important; right:auto!important; width:100%!important; height:14px!important;
    padding:0 2px!important; font:800 10px/14px Inter,sans-serif!important; letter-spacing:0!important;
  }
  body#top[data-page='play'].phone-match-active.combat-active #game-screen .cb-role-badge { top:0!important; }
  body#top[data-page='play'].phone-match-active.combat-active #game-screen .csp-unit { top:16px!important; }
  body#top[data-page='play'].phone-match-active.combat-active #game-screen .combat-matrix-cell {
    inset:34px 0 0; height:calc(100% - 34px)!important;
  }
  html[data-theme] body#top[data-page='play'] :is(.tut-modal-title,.phone-briefing-title,#gcm-title) { font-size:20px!important; }
  html[data-theme] body#top[data-page='play'] #phone-tutorial-briefing .phone-briefing-title { font-size:22px!important; }
  html[data-theme] body#top[data-page='play'] :is(#tut-intro-modal>.tut-intro-card,#tut-completion-modal>.tut-modal-card,#phone-tutorial-briefing) { padding:10px 16px!important; }
  html[data-theme] body#top[data-page='play'] .phone-pagination-active .tut-rule-card h4 { font-size:17px!important; }
  html[data-theme] body#top[data-page='play'] .phone-pagination-active .tut-rule-card p { font-size:13px!important; }
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal>.modal-card {
    padding:12px 16px!important; gap:8px 16px;
  }
  html[data-theme] body#top[data-page='play'].phone-match-active #color-select-title { font-size:16px!important; line-height:1.25!important; }
  html[data-theme] body#top[data-page='play'].phone-match-active #color-select-status { font-size:12px!important; line-height:1.4!important; }
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal .modal-card>div:nth-child(4) { gap:4px!important; }
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal .ro-val { width:48px!important; height:48px!important; }
  html[data-theme] body#top[data-page='play'].phone-match-active #match-intro-modal .modal-card>div:nth-child(4)>div:nth-child(2)>div:has(.ro-val) { gap:4px!important; }
  html[data-theme] body#top[data-page='play'].phone-match-active #intro-ready-container { padding:2px 8px!important; }
}
