/* ================================================================
   mobile.css — RewindClick mobile optimisations
   Loaded after main.css. Consolidates and extends mobile UX.
   ================================================================ */

/* ── 1. TOUCH TARGET IMPROVEMENTS ──────────────────────────────
   All tappable elements get snappier response and 44px min targets
   on touch devices (Apple HIG / WCAG 2.5.5 recommendation).       */

@media (hover: none) and (pointer: coarse) {

  /* Snap tap delay — eliminates the 300ms click delay on iOS/Android */
  a, button, [role="button"], input, select, label,
  .tbtn, .sc, .sl, .add-btn, .tb-btn, .start-btn,
  .top-themes-toggle, .module-head, .taskbar-window-btn,
  .panel-launch-item, .start-menu-nav-btn, .start-menu-item,
  .news-topic-btn, .panel-chip, .stab, .toggle-btn {
    touch-action: manipulation;
  }

  /* Minimum 44×44px tap targets for primary interactive elements */
  .tbtn, .add-btn, .start-btn, .panel-chip,
  .top-themes-toggle, .stab, .start-menu-nav-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Quick-link icons — bigger tap surface */
  .sl {
    min-width: 68px;
    min-height: 64px;
    padding: 10px 8px;
  }

  /* Search go button */
  .si button {
    min-height: 44px;
    padding: 6px 14px;
  }

  /* Remove button touch areas */
  .rm-s, .sl .rm {
    min-width: 32px;
    min-height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  /* Prevent lingering hover styles on touch */
  .sl:hover { background: var(--bg2); }
  .tbtn:hover { background: var(--btn); }
}


/* ── 2. PREVENT iOS AUTO-ZOOM ON INPUTS ────────────────────────
   Any input below 16px triggers zoom on iOS Safari.
   Setting 16px base prevents this without overriding user zoom.   */

@media (max-width: 768px) {

  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="url"],
  input[type="search"],
  input[type="datetime-local"],
  textarea,
  select {
    font-size: 16px !important;
  }
}


/* ── 3. CLOCK ROW — COMPACT ON SMALL SCREENS ───────────────────
   Stack weather widget below clock/date cleanly.                  */

@media (max-width: 480px) {

  .clock-row {
    flex-direction: column;
    gap: 4px;
    align-items: center;
  }

  .weather-widget {
    font-size: 12px;
  }

  #weatherIcon {
    font-size: 16px;
  }
}


/* ── 4. SEARCH BARS — FULL WIDTH + TALLER INPUT ON MOBILE ──────  */

@media (max-width: 768px) {

  .searches {
    grid-template-columns: 1fr;
  }

  .sc {
    padding: 8px 10px;
  }

  .si input {
    padding: 8px 10px;
    min-height: 44px;
  }

  /* Ensure search engine name label wraps, not overflows */
  .ename {
    display: none;
  }
}


/* ── 5. MODULE GRID & CARDS ─────────────────────────────────────
   Already single-column at <980px via main.css; these tweaks
   tighten spacing and improve touch feel at phone widths.         */

@media (max-width: 768px) {

  .module-grid {
    gap: 6px;
    margin-top: 8px;
  }

  .module-body {
    padding: 10px;
  }

  /* Module head — taller tap area on touch phones */
  .module-head {
    min-height: 32px !important;
    padding: 4px 10px !important;
  }

  /* Remove side borders on window for edge-to-edge feel */
  .window {
    border-left: none;
    border-right: none;
    max-width: 100%;
  }
}


/* ── 6. THEME PANEL — HORIZONTAL SCROLL ON MOBILE ──────────────  */

@media (max-width: 768px) {

  /* Each theme row scrolls horizontally instead of wrapping */
  .top-themes-mount .theme-row {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding-bottom: 4px;
  }

  .top-themes-mount .theme-row::-webkit-scrollbar {
    display: none;
  }

  /* Keep category label visible but compact */
  .top-themes-mount .theme-row-lbl {
    flex: 0 0 48px;
    min-width: 48px;
    font-size: 9px !important;
    padding-top: 8px;
  }

  .top-themes-mount .theme-row-buttons {
    flex-wrap: nowrap;
    gap: 5px;
  }

  .top-themes-mount .tbtn {
    flex-shrink: 0;
    white-space: nowrap;
  }
}


/* ── 7. TASKBAR IMPROVEMENTS ON MOBILE ─────────────────────────  */

@media (max-width: 768px) {

  .taskbar {
    gap: 6px;
    padding: 0 8px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    /* Ensure proper height for touch targets */
    height: calc(44px + env(safe-area-inset-bottom, 0px));
  }

  .start-btn {
    padding: 4px 10px;
    min-height: 34px;
  }

  /* Taskbar window buttons — smaller on mobile, show fewer */
  .taskbar-window-btn {
    min-width: 80px;
    max-width: 120px;
  }

  /* Clock / sound icons — bigger tap zones */
  .tb-sound {
    width: 36px;
    height: 36px;
  }

  .tb-clock {
    padding: 4px 8px;
    min-height: 34px;
  }
}


/* ── 8. START MENU / CONTROL CENTRE ON MOBILE ───────────────────
   Full-width slide-up panel at phone sizes.                       */

@media (max-width: 600px) {

  .start-menu-panel {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    bottom: calc(var(--taskbar-height, 44px) + env(safe-area-inset-bottom, 0px)) !important;
    border-left: none !important;
    border-right: none !important;
    border-radius: calc(var(--br) + 10px) calc(var(--br) + 10px) 0 0 !important;
    max-height: calc(100dvh - var(--taskbar-height, 44px) - 8px) !important;
  }

  /* Nav tabs become a horizontal scrollable strip at the top */
  .start-menu-nav {
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    border-right: none;
    border-bottom: 1px solid color-mix(in srgb, var(--accent2) 14%, var(--bd));
    padding: 8px;
    gap: 6px;
  }

  .start-menu-nav::-webkit-scrollbar { display: none; }

  .start-menu-nav-btn {
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 36px;
  }
}


/* ── 9. MODAL IMPROVEMENTS ──────────────────────────────────────
   Modals slide up from the bottom on phones for thumb reachability.  */

@media (max-width: 600px) {

  .modal-bg {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    width: 100% !important;
    max-width: 100% !important;
    border-left: none !important;
    border-right: none !important;
    border-radius: calc(var(--br) + 12px) calc(var(--br) + 12px) 0 0 !important;
    max-height: 90dvh !important;
  }

  .modal-body {
    padding: 12px 14px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }

  /* Drag pill indicator (visual affordance) */
  .modal::before {
    content: "";
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: color-mix(in srgb, var(--bd) 60%, transparent);
    margin: 10px auto 4px;
    flex-shrink: 0;
  }
}


/* ── 10. CALENDAR POPUP ─────────────────────────────────────────
   Keep it on screen on small phones.                              */

@media (max-width: 420px) {

  .clock-calendar-popup {
    right: 4px;
    left: 4px;
    width: auto;
  }

  .clock-calendar-popup.is-expanded {
    width: auto;
  }
}


/* ── 11. SNAKE GAME CONTROLS ─────────────────────────────────────
   On mobile the on-screen d-pad should be well spaced.            */

@media (max-width: 768px) {

  .snake-mobile-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-top: 10px;
  }

  .snake-mobile-controls .tbtn {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .snake-mobile-controls > div {
    display: flex;
    gap: 4px;
  }
}


/* ── 12. RADIO TUNER ────────────────────────────────────────────
   Stack controls vertically on narrow screens.                    */

@media (max-width: 500px) {

  .radio-tuner {
    flex-direction: column;
    gap: 8px;
  }

  .radio-field,
  .radio-actions {
    width: 100%;
  }

  .radio-actions .tbtn {
    flex: 1;
  }
}


/* ── 13. SMALL-SCREEN (< 380px) TIGHTENING ─────────────────────  */

@media (max-width: 380px) {

  .wbody {
    padding: 6px 8px;
  }

  .site-title {
    font-size: 24px !important;
    letter-spacing: 1px !important;
  }

  .clock {
    font-size: 20px !important;
  }

  .sl {
    min-width: 56px;
    padding: 8px 6px;
  }

  .tbtn {
    font-size: 10px;
    padding: 4px 7px;
  }
}


/* ── 14. SAFE AREA / NOTCH SUPPORT ─────────────────────────────
   Already handled for taskbar in main.css; this extends it to
   any fixed elements.                                             */

.clock-calendar-popup,
.start-menu-panel,
.panel-launch-panel {
  /* Prevent content from being hidden under notch */
  padding-top: max(0px, env(safe-area-inset-top));
}


/* ── 15. PERFORMANCE: REDUCE ANIMATIONS ON LOW-POWER DEVICES ───  */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .news-banner.ready {
    animation: none;
    /* Show static text instead */
    white-space: normal;
    overflow: visible;
  }
}


/* ── 16. OVERSCROLL: PREVENT PAGE BOUNCE BEHIND MENUS ──────────  */

.start-menu-panel,
.panel-launch-panel,
.modal-bg.open {
  overscroll-behavior: contain;
}


/* ===== Mobile header controls ===== */
@media (max-width: 640px) {
  .site-hdr .top-controls-row {
    width: 100%;
    max-width: 100vw;
    margin: 8px auto 0;
    padding: 0 10px;
    box-sizing: border-box;
    overflow: visible;
  }

  .site-hdr .top-themes-panel {
    width: min(360px, 94vw);
    max-width: 94vw;
    margin: 0 auto;
    box-sizing: border-box;
    overflow: visible;
  }

  .site-hdr .top-controls-buttons {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin: 0 auto;
    box-sizing: border-box;
  }

  .site-hdr .top-themes-toggle,
  .site-hdr .top-desktop-mode-panel {
    pointer-events: auto;
    touch-action: manipulation;
  }

  .site-hdr .top-themes-content {
    width: 100%;
    max-width: 100%;
    margin: 5px auto 0;
    padding: 0;
    box-sizing: border-box;
    overflow: visible;
    text-align: left;
  }

  .site-hdr .top-themes-mount {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    box-sizing: border-box;
    overflow: visible;
  }

  .site-hdr .top-themes-mount .theme-row {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 3px 5px;
    margin-bottom: 5px;
  }

  .site-hdr .top-themes-mount .theme-row-lbl {
    width: 48px;
    min-width: 48px;
    font-size: 9px;
  }

  .site-hdr .top-themes-mount .theme-row-buttons {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    justify-content: center;
    gap: 3px;
    box-sizing: border-box;
    overflow: visible;
  }

  .site-hdr .top-themes-mount .tbtn {
    flex: 0 1 auto;
    max-width: 100%;
    min-width: 0;
    min-height: 19px;
    padding: 2px 5px;
    font-size: 9px;
    white-space: nowrap;
    overflow-wrap: normal;
    text-align: center;
    box-sizing: border-box;
    pointer-events: auto;
    touch-action: manipulation;
  }

  .site-hdr .top-desktop-mode-panel {
    flex-wrap: nowrap;
    font-size: 9px;
  }

  .site-hdr .top-desktop-mode-select {
    min-width: 88px;
    max-width: 108px;
    min-height: 19px;
    padding: 1px 3px;
    font-size: 9px;
  }
}


/* RewindClick fix: keep the Desktop Mode dropdown compact on desktop, mobile, and browser resize. */
.site-hdr .top-desktop-mode-panel{
  flex:0 0 auto !important;
  width:auto !important;
  max-width:max-content !important;
  min-width:0 !important;
  align-self:center !important;
}
.site-hdr .top-desktop-mode-label{
  flex:0 0 auto !important;
}
.site-hdr .top-desktop-mode-select{
  flex:0 0 auto !important;
  width:106px !important;
  min-width:106px !important;
  max-width:106px !important;
  height:22px !important;
  min-height:22px !important;
  padding:1px 20px 1px 5px !important;
  font-size:10px !important;
  line-height:1 !important;
  box-sizing:border-box !important;
}
@media (max-width:640px){
  .site-hdr .top-desktop-mode-panel{max-width:max-content !important;}
  .site-hdr .top-desktop-mode-select{
    width:98px !important;
    min-width:98px !important;
    max-width:98px !important;
    height:20px !important;
    min-height:20px !important;
    font-size:9px !important;
    padding:1px 18px 1px 4px !important;
  }
}


/* === Responsive taskbar + mobile settings fixes === */
@media (max-width: 980px){
  .taskbar{
    display:grid !important;
    grid-template-columns:auto 1fr auto auto !important;
    align-items:center;
    column-gap:8px;
  }

  .taskbar-windows{
    min-width:0;
    overflow-x:auto;
    justify-self:stretch;
  }

  .tb-sound{
    grid-column:3;
    justify-self:end;
    flex-shrink:0;
    margin-left:auto;
    position:relative;
    right:0;
  }

  .tb-clock{
    grid-column:4;
    justify-self:end;
    flex-shrink:0;
    white-space:nowrap;
  }
}

@media (max-width: 768px){
  .start-menu-panel{
    left:0 !important;
    right:0 !important;
    width:100vw !important;
    max-width:100vw !important;
    bottom:calc(var(--taskbar-height,44px) + env(safe-area-inset-bottom,0px)) !important;
    border-radius:18px 18px 0 0 !important;
    overflow:hidden;
  }

  .start-menu-shell{
    grid-template-columns:1fr !important;
    min-height:auto;
    max-height:none;
  }

  .start-menu-nav{
    display:grid !important;
    grid-template-columns:repeat(2,minmax(0,1fr));
    border-right:none !important;
    border-bottom:1px solid color-mix(in srgb, var(--accent2) 14%, var(--bd));
    position:sticky;
    top:0;
    z-index:2;
    background:var(--bg2);
  }

  .start-menu-nav-btn{
    min-height:48px;
    justify-content:center;
  }

  .start-menu-content,
  .start-menu-list{
    max-height:55vh !important;
    overflow:auto !important;
    -webkit-overflow-scrolling:touch;
  }
}

@media (max-width: 520px){
  .start-menu-nav{
    grid-template-columns:1fr;
  }

  .taskbar-window-btn{
    min-width:72px;
    max-width:92px;
  }
}
