/* Phones and tablets. Loaded last; the selectors start with "html body" so they win over the older layered rules
   without touching the desktop layout. Up to 1000px (where the desktop rail takes over) the navigation is a menu
   button in the top bar that opens a drawer from the left; the page tweaks below apply to phone widths. */
.mobile-menu-button,.mobile-wordmark,.mobile-auth,.mobile-drawer,.mobile-drawer-backdrop{display:none}

@media (max-width:1000px){
 /* Top bar: menu button, the site crest and wordmark; Sign Up / Log In while signed out, the WGC balance when linked. */
 html body>header{position:sticky!important;top:0!important;z-index:60!important;display:flex!important;align-items:center!important;justify-content:flex-start!important;gap:10px!important;height:56px!important;min-height:0!important;box-sizing:border-box!important;margin:0!important;padding:0 10px 0 6px!important;padding-top:env(safe-area-inset-top)!important;background:rgba(8,26,30,.98)!important;border:0!important;border-bottom:1px solid rgba(210,183,120,.32)!important;box-shadow:0 4px 14px rgba(0,0,0,.35)!important}
 html body>header #railToggle,html body>header #accountMenu,html body>header>nav{display:none!important}
 html body>header .mobile-menu-button{display:grid!important;place-items:center;flex:none;width:50px;height:44px;min-height:0;margin:0;padding:0 6px 0 0;border:0;border-right:1px solid rgba(255,255,255,.14);border-radius:0;background:none;color:#ece3cc;box-shadow:none;cursor:pointer}
 html body>header .mobile-menu-button svg{width:26px;height:26px;fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
 html body>header .brand{position:static!important;inset:auto!important;order:0;display:flex!important;flex:1 1 auto!important;align-items:center;gap:0!important;min-width:0;max-width:none!important;width:auto!important;height:auto!important;margin:0 auto 0 0!important;padding:0!important;visibility:visible!important;transform:none!important;text-decoration:none!important}
 html body>header .brand img.brand-logo{display:block!important;flex:none;width:42px!important;height:42px!important;max-width:none!important;margin:0 6px 0 0!important;object-fit:contain;visibility:visible!important}
 html body>header .mobile-wordmark{display:flex;align-items:center;gap:5px;min-width:0}
 html body>header .mobile-wordmark-text{overflow:hidden;white-space:nowrap;font:700 19px/1 Georgia,'Noto Serif KR',serif;letter-spacing:.01em;background:linear-gradient(180deg,#f8e2a0,#c9993f);-webkit-background-clip:text;background-clip:text;color:transparent}
 html body>header .mobile-wordmark-text{font-weight:600}html body>header .mobile-wordmark-text em{font-style:italic;font-weight:500;font-size:.8em;letter-spacing:0;padding-right:.12em}
 html body:not([data-authenticated=true])>header .mobile-auth{display:flex;flex:none;gap:6px;order:3}
 html body>header .mobile-auth button{min-height:32px;padding:5px 10px;border-radius:7px;font:700 13px/1 Georgia,'Noto Serif KR',serif;white-space:nowrap;cursor:pointer}
 html body>header .mobile-auth-signup{border:1px solid #d2b778;background:linear-gradient(#1f6a4a,#13503a);color:#fff3cf}
 html body>header .mobile-auth-login{border:1px solid rgba(210,183,120,.6);background:transparent;color:#ece3cc}
 html body>header #wgcBalance{position:static!important;order:2;margin:0!important;min-height:32px!important;padding:4px 10px!important;font-size:13px!important;white-space:nowrap}

 /* The section links live in the drawer instead. */
 html body #sectionNav{display:none!important}
 html body>main{padding-top:12px!important;padding-bottom:calc(24px + env(safe-area-inset-bottom))!important;margin-top:0!important}
 html:has(>body[data-drawer-open]),html body[data-drawer-open]{overflow:hidden!important}

 /* Drawer */
 html body .mobile-drawer-backdrop{display:block;position:fixed;top:56px;right:0;bottom:0;left:0;z-index:58;background:rgba(0,0,0,.55);opacity:0;visibility:hidden;transition:opacity .2s ease,visibility 0s .2s}
 html body .mobile-drawer-backdrop[data-open]{opacity:1;visibility:visible;transition:opacity .2s ease}
 html body .mobile-drawer{display:flex;flex-direction:column;position:fixed;top:56px;bottom:0;left:0;z-index:59;width:min(300px,84vw);box-sizing:border-box;padding:14px 12px calc(18px + env(safe-area-inset-bottom));overflow-y:auto;overscroll-behavior:contain;background:linear-gradient(180deg,#0e272b,#0a1c20);border-right:1px solid rgba(210,183,120,.38);box-shadow:14px 0 34px rgba(0,0,0,.55);color:#efe6cf;transform:translateX(-105%);visibility:hidden;transition:transform .22s ease,visibility 0s .22s}
 html body .mobile-drawer[data-open]{transform:none;visibility:visible;transition:transform .22s ease}
 .mobile-drawer svg{flex:none;width:24px;height:24px;fill:none;stroke:#d7b45a;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}
 .mobile-drawer-me{display:grid;grid-template-columns:62px minmax(0,1fr) 16px;align-items:center;gap:12px;padding:4px 6px 12px;border-radius:12px;color:inherit;text-decoration:none}
 html body .mobile-drawer-me .mobile-drawer-avatar{width:62px!important;height:62px!important;min-width:62px!important;margin:0!important;border:2px solid #d2b778!important;box-shadow:0 0 0 3px rgba(210,183,120,.18)}
 .mobile-drawer-who{display:flex;flex-direction:column;gap:3px;min-width:0}
 .mobile-drawer-who strong{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:600 19px/1.2 Georgia,'Noto Serif KR',serif;color:#f6ecd2}
 .mobile-drawer-who small{font:500 13px/1.3 Georgia,'Noto Serif KR',serif;color:#b9cbc2}
 .mobile-drawer-me>svg,.mobile-drawer-row>svg:last-child:not(:first-child),.mobile-drawer-signup>svg:last-child,.mobile-drawer-login>svg:last-child{width:15px;height:15px;stroke:#c9d4cf;stroke-width:2.2}
 .mobile-drawer-me[data-current] strong{color:#f3d68b}
 .mobile-drawer-ornament{display:flex;align-items:center;gap:8px;margin:2px 10px 10px}
 .mobile-drawer-ornament::before,.mobile-drawer-ornament::after{content:"";flex:1;height:1px;background:linear-gradient(90deg,transparent,rgba(210,183,120,.7),transparent)}
 .mobile-drawer-ornament span{width:7px;height:7px;border:1px solid #d2b778;transform:rotate(45deg)}
 .mobile-drawer-group{display:flex;flex-direction:column}
 .mobile-drawer-group+.mobile-drawer-group{margin-top:8px;padding-top:8px;border-top:1px solid rgba(210,183,120,.3)}
 html body .mobile-drawer-row{display:grid;grid-template-columns:28px minmax(0,1fr) 16px;align-items:center;gap:14px;width:100%;min-height:50px;box-sizing:border-box;margin:0;padding:0 10px 0 12px;border:1px solid transparent;border-bottom-color:rgba(255,255,255,.07);border-radius:0;background:none;box-shadow:none;color:#efe6cf;font:500 17px/1.2 Georgia,'Noto Serif KR',serif;text-align:left;text-decoration:none;cursor:pointer}
 html body .mobile-drawer-row:last-child{border-bottom-color:transparent}
 .mobile-drawer-label{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
 html body .mobile-drawer-row[data-current]{border:1px solid #d2b778;border-radius:10px;background:linear-gradient(90deg,rgba(215,180,90,.2),rgba(215,180,90,.04));box-shadow:inset 4px 0 0 #d7b45a;color:#f3d68b}
 html body .mobile-drawer-row:active,.mobile-drawer-me:active{background:rgba(215,180,90,.1)}
 html body .mobile-drawer-logout{grid-template-columns:28px minmax(0,1fr)}
 .mobile-drawer-languages{display:grid;grid-template-columns:1fr 1fr;gap:8px;padding:6px 10px 10px}
 .mobile-drawer-languages[hidden]{display:none}
 html body .mobile-drawer-languages button{min-height:42px;padding:6px;border:1px solid rgba(255,255,255,.18);border-radius:10px;background:rgba(255,255,255,.05);color:#efe6cf;font:700 14px system-ui,sans-serif}
 html body .mobile-drawer-languages button[aria-pressed=true]{border-color:#d7b45a;background:#d7b45a;color:#13241f}
 html body .mobile-drawer-signup,html body .mobile-drawer-login{display:grid;grid-template-columns:30px minmax(0,1fr) 16px;align-items:center;gap:12px;width:100%;min-height:54px;box-sizing:border-box;margin:14px 0 0;padding:0 14px;border:1px solid #d2b778;border-radius:12px;font:700 19px/1.2 Georgia,'Noto Serif KR',serif;text-align:left;text-decoration:none;cursor:pointer;box-shadow:none}
 html body .mobile-drawer-signup{background:linear-gradient(#1f6a4a,#13503a);color:#fff3cf}
 html body .mobile-drawer-login{margin-top:10px;background:transparent;color:#efe6cf}
 .mobile-drawer-signup>svg:first-child,.mobile-drawer-login>svg:first-child{stroke:#f3d68b}
 .mobile-drawer-status{margin:auto 0 0;padding-top:14px;text-align:center;font-size:12px;color:#8fa79c}
 .mobile-drawer-status:empty{display:none}
}
@media (max-width:1000px) and (prefers-reduced-motion:reduce) and (scripting:none){html body .mobile-drawer,html body .mobile-drawer-backdrop{transition:none!important}}

/* Signed out on a phone the Sign Up / Log In buttons share the bar, so the wordmark drops ".com". */
@media (max-width:420px){html body:not([data-authenticated=true])>header .mobile-wordmark-text{font-size:15px;letter-spacing:0}html body:not([data-authenticated=true])>header .brand img.brand-logo{width:36px!important;height:36px!important;margin-right:4px!important}html body>header .mobile-auth{gap:5px!important}html body>header .mobile-auth button{min-height:30px;padding:4px 8px;font-size:12px}}

@media (max-width:760px){
 /* Home */
 html body .home-welcome>a{display:none!important}
 html body .home-bottom-grid .home-panel>p,html body .home-bottom-grid .home-panel>h2+p{max-width:58%!important}

 /* Play page: full width, roomy cards, the button under the text. */
 html body .play-hub{padding:0!important;gap:0!important}
 html body #playHome .hub-panel{width:100%!important;max-width:none!important;padding:18px 14px!important;gap:14px!important;border-radius:16px!important}
 html body #playHome .hub-time-group{grid-template-columns:52px repeat(4,minmax(0,1fr))!important}
 html body #playHome .hub-mode{grid-template-columns:40px minmax(0,1fr)!important;gap:10px 12px!important}
 html body #playHome .hub-mode>.hub-secondary,html body #playHome .hub-mode-bot>.hub-secondary{grid-column:1/-1!important;grid-row:auto!important;width:100%!important;min-height:46px!important}
 html body #playHome .hub-mode-bot .hub-levels{grid-column:1/-1!important;grid-template-columns:repeat(2,minmax(0,1fr))!important}
 html body #playHome .hub-search p{flex-direction:column!important;gap:6px!important}
 html body #playHome .hub-search strong{white-space:normal!important;overflow:visible!important;text-overflow:clip!important}
 html body #playHome .hub-search-actions{display:grid!important;grid-template-columns:1fr!important}
 html body #playHome .hub-search-actions .hub-secondary{width:100%!important;white-space:normal!important}

 /* Custom game, lobby, puzzles: readable headings and tidy controls. */
 html body #setupView>h1,html body #setupView>h2,html body #setupView .setup-title{color:#fff3cf!important;text-shadow:0 2px 8px rgba(0,0,0,.85),0 0 2px rgba(0,0,0,.9)!important}
 html body #playHome .hub-links{display:grid!important;grid-template-columns:1fr 1fr!important;gap:8px!important}
 html body #playHome .hub-links>a{justify-content:center!important;min-height:38px!important;height:auto!important;margin:0!important;padding:6px 10px!important;text-align:center!important;white-space:normal!important;line-height:1.2!important}

 /* Review: same compact strips; leave room for the a-h letters under the board. */
 html body #reviewView #board{margin-bottom:14px!important}
 html body #reviewView .review-back>#navHistory{display:none!important}
 html body #reviewView .review-back{display:flex!important;flex-wrap:wrap!important;gap:8px!important;margin:0 0 8px!important;padding:0!important}
 html body #reviewView .review-back a,html body #reviewView a.reviewNewGame{display:inline-flex!important;align-items:center!important;min-height:36px!important;padding:6px 14px!important;border:1px solid rgba(215,180,90,.45)!important;border-radius:999px!important;background:rgba(10,36,41,.92)!important;color:#f1e3b8!important;font:700 13px/1.2 system-ui,sans-serif!important;text-decoration:none!important;box-shadow:none!important}

 /* Custom game: links in one row, space under the invite button. */
 html body #setupView .setup-nav{display:flex!important;flex-wrap:wrap!important;justify-content:flex-start!important;gap:8px!important;margin:0 0 12px!important}
 html body #setupView .setup-nav a[href="#cups"]{display:none!important}
 html body #setupView .setup-nav a{min-height:36px!important;padding:6px 14px!important;font-size:13px!important}
 html body #setupView form button,html body #setupView .card>button{margin-bottom:12px!important}

 /* Puzzles: the four buttons as a tidy two-by-two grid. */
 html body .puzzle-controls{display:grid!important;grid-template-columns:1fr 1fr!important;gap:8px!important;align-items:stretch!important}
 html body .puzzle-controls>:not(button){grid-column:1/-1!important}
 html body .puzzle-controls>button{width:100%!important;margin:0!important;min-height:44px!important}
 html body .puzzle-controls input,html body .puzzle-controls select{width:100%!important;box-sizing:border-box!important}

 /* Lobby: labels above their fields. */
 html body #lobby label:has(select),html body #lobby label:has(input:not([type=checkbox]):not([type=radio])){display:grid!important;gap:4px!important;width:100%!important}
 html body #lobby label select,html body #lobby label input:not([type=checkbox]):not([type=radio]){width:100%!important;box-sizing:border-box!important}
}

@media (max-width:1000px){
 /* Game screen: compact player strips, and a board sized so both clocks and the whole board fit on one screen
    below the top bar. */
 html body #playView #play{--board-size:min(calc(100vw - 24px),calc(100dvh - 210px),760px)!important}
 html body #reviewView{--board-size:min(calc(100vw - 44px),calc(100dvh - 250px),760px)!important}
 html body #playView #matchBar{display:none!important}
 html body #playView{margin-left:-8px!important;margin-right:-8px!important}
 html body :is(#playView,#reviewView) #play.play-area{padding:6px!important;gap:6px!important;row-gap:6px!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar{display:grid!important;grid-template-columns:34px minmax(0,1fr) auto!important;grid-template-rows:auto auto!important;column-gap:10px!important;row-gap:0!important;align-items:center!important;min-height:0!important;height:auto!important;margin:0!important;padding:6px 8px!important;border-radius:12px!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar>span:has(>.player-identity),html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .player-identity{display:contents!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .player-portrait{grid-column:1!important;grid-row:1/3!important;width:34px!important;height:34px!important;min-width:34px!important;margin:0!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .player-name{grid-column:2!important;grid-row:1!important;align-self:end!important;font-size:14px!important;line-height:1.2!important;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .player-meta{grid-column:2!important;grid-row:2!important;justify-self:start!important;align-self:start!important;font-size:11px!important;line-height:1.3!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .player-position-info{grid-column:2!important;grid-row:2!important;justify-self:end!important;align-self:start!important;max-width:60%!important;min-height:0!important;padding:0!important;margin:0!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .clock{grid-column:3!important;grid-row:1/3!important;align-self:center!important;min-width:84px!important;padding:6px 10px!important;font-size:22px!important;line-height:1.1!important;text-align:center!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .turn-indicator{display:none!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .capture-group img{width:16px!important;height:16px!important}
 html body :is(#playView,#reviewView) #play:has(>#board[id])>.playerbar .capture-group img+img{margin-left:-8px!important}
}

/* Signed-out phones already have Log In / Sign Up in the top bar. */
@media (max-width:1000px){html body .home-visitor-actions{display:none!important}}
@media (max-width:760px){html body #homeContent .dashboard-play.dashboard-play-login{font-size:21px!important;white-space:nowrap}}
/* Signed in, the WGC balance shares the bar: a smaller wordmark, and no ".com" on the narrowest phones, so it never clips. */
@media (max-width:400px){html body[data-authenticated=true]>header .mobile-wordmark-text{font-size:16px;letter-spacing:0}}

/* The "Realm of Chess" wordmark: a touch smaller beside the Sign up / Log in buttons, and on the narrowest phones the crest
   logo (which carries the name) stands alone. */
@media (max-width:380px){html body:not([data-authenticated=true])>header .mobile-wordmark-text{font-size:13px}}
@media (max-width:340px){html body>header .mobile-wordmark{display:none}}
