/* Phone-only rules. Loaded last; every block is gated by a media query so desktop is untouched. */

/* ---------- touch devices: no sticky hover states ---------- */
@media (hover: none) {
  .board.interactive .tile:not(.blank):hover .tile-face {
    transform: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22), inset 0 -2px 0 rgba(0, 0, 0, 0.28), 0 6px 14px -5px rgba(0, 0, 0, 0.6);
  }
  .board.interactive .tile:not(.blank):active .tile-face { transform: scale(0.96); }
  .btn:hover { transform: none; background: var(--surface); border-color: var(--border); }
  .btn-primary:hover { background: var(--accent-grad); filter: none; }
  .btn:active { transform: scale(0.97); }
  .icon-btn:hover { transform: none; background: var(--surface); }
  .mode-card:hover { transform: none; border-color: var(--border); box-shadow: var(--shadow-sm); }
  .mode-card:hover::before { opacity: 0; }
  .mode-card:active { transform: scale(0.985); }
  .skin-card:hover { transform: none; border-color: var(--border); }
  .brand:hover .brand-text { color: var(--text); }
  .brand:hover .mark-slider { transform: none; }
}

/* ---------- phones (portrait and small screens) ---------- */
@media (max-width: 700px) {
  html { font-size: 17px; }
  button, a, .switch, .seg, .chip { touch-action: manipulation; }
  main { padding-inline: 12px; }
  .muted, .mode-desc, .setting-text small, .stat-sub, .best-label { font-size: 0.95rem; }
  .control-label { font-size: 0.82rem; }

  /* tap targets */
  .btn, .btn-sm { min-height: 46px; padding: 0.6rem 1rem; font-size: 1rem; }
  .btn-lg { min-height: 52px; font-size: 1.1rem; }
  .icon-btn { width: 44px; height: 44px; }
  .seg { width: 100%; }
  .seg button { flex: 1; min-height: 40px; font-size: 0.95rem; padding: 0.4rem 0.5rem; }
  .chip { min-height: 40px; font-size: 0.9rem; }
  .switch { width: 52px; height: 30px; }
  .switch-track::after { width: 22px; height: 22px; }
  .switch input:checked + .switch-track::after { transform: translateX(22px); }
  kbd { font-size: 0.7em; }

  /* top bar */
  .topbar { padding: 0.55rem 0.8rem; }
  .brand span:last-child { display: none; }
  .topnav .btn { min-height: 40px; padding: 0.4rem 0.85rem; font-size: 0.95rem; }

  /* performance: big blurs are expensive on phones */
  .bg-orbs span { filter: blur(40px); animation: none; }
  .panel, .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; }
  .panel { background: color-mix(in srgb, var(--surface-solid) 85%, transparent); }

  /* home */
  .hero { padding-top: 1.2rem; gap: 1.4rem; }
  .eyebrow { font-size: 0.8rem; }
  .lead { font-size: 1.08rem; }
  .hero-actions { flex-direction: column; align-items: stretch; }
  .hero-demo-stage { width: min(100%, 300px); }
  .hero-demo-caption { font-size: 0.95rem; }
  .section-title { font-size: 1.35rem; }
  .mode-grid { grid-template-columns: 1fr; gap: 0.8rem; }
  .mode-card { padding: 1.1rem 1.15rem; }
  .mode-name { font-size: 1.25rem; }
  .mode-tagline { font-size: 1rem; }
  .mode-meta { font-size: 0.85rem; }
  .foot { font-size: 0.9rem; }

  /* game screen: flatten the side panel so its panels can be ordered under the board */
  .game-layout { display: flex; flex-direction: column; align-items: stretch; gap: 0.8rem; padding-top: 0.6rem; }
  .side-panel { display: contents; }
  .board-column { order: 1; gap: 0.7rem; }
  #tutor-panel { order: 2; }
  #panel-controls { order: 3; }
  #ghost-panel, #zen-panel, #daily-panel, #demo-panel, #ring-panel { order: 4; }

  .board-topline { gap: 0.5rem; flex-wrap: nowrap; }
  .board-topline .btn { min-height: 40px; padding: 0.35rem 0.7rem; font-size: 0.9rem; }
  .mode-chip { font-size: 1rem; min-width: 0; }
  .mode-chip > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .live-stats { gap: 0.8rem; flex-shrink: 0; }
  .live-label { font-size: 0.66rem; }
  .live-value { font-size: 1.35rem; }
  .board-stage { height: min(calc(100vw - 24px), calc(100vh - 190px)); height: min(calc(100vw - 24px), calc(100dvh - 190px)); }
  .board-under { font-size: 0.95rem; }
  .twist-controls { gap: 0.6rem; }
  .btn-twist { flex: 1; min-height: 50px; font-size: 1rem; padding: 0.6rem 0.6rem; }

  #panel-controls { display: flex; flex-direction: column; padding: 0.9rem; }
  #panel-controls .control-grid { order: 1; margin-bottom: 0.3rem; gap: 0.6rem; }
  #panel-controls .control-grid .btn { min-height: 50px; }
  #panel-controls .control-row { order: 2; margin-top: 0.7rem; }
  #panel-controls .control-row .seg { flex: 1; margin-left: 0.6rem; }
  #panel-controls .skin-btn { max-width: none; }
  #panel-controls .preview-box { order: 3; }
  #panel-controls .bests { order: 4; }
  #panel-controls .mode-desc { order: 9; margin: 0.9rem 0 0; font-size: 0.95rem; }
  .best-value { font-size: 1.25rem; }

  /* tutor: sticky bottom sheet while the board is on screen */
  #tutor-panel {
    position: sticky; bottom: 0; z-index: 15;
    display: flex; flex-direction: column;
    margin: 0 -12px; border-radius: 18px 18px 0 0; border-bottom: 0;
    padding: 0.65rem 0.9rem calc(0.6rem + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface-solid) 94%, #8b6cff);
    box-shadow: 0 -12px 34px rgba(0, 0, 0, 0.4);
  }
  [data-theme='light'] #tutor-panel { background: #ffffff; box-shadow: 0 -12px 34px rgba(30, 40, 90, 0.18); }
  #tutor-panel .panel-title { display: none; }
  .tutor-phase { order: 1; font-size: 0.88rem; font-weight: 700; color: var(--muted); padding-right: 3.2rem; line-height: 1.3; }
  .tutor-step { order: 2; font-size: 1.02rem; padding: 0.55rem 0.75rem; margin: 0.4rem 0 0.35rem; }
  .tutor-progress-row { order: 3; font-size: 0.8rem; margin-bottom: 0.25rem; }
  #tutor-panel .progress { order: 4; height: 4px; }
  .tutor-lesson { order: 5; display: none; font-size: 0.95rem; margin: 0.5rem 0 0; }
  #tutor-panel.expanded .tutor-lesson { display: block; }
  .tutor-more { display: block; position: absolute; top: 0.45rem; right: 0.9rem; padding: 0.2rem 0.4rem; font-size: 0.9rem; min-height: 32px; }
  #tutor-panel .control-grid { order: 6; margin: 0.55rem 0 0; gap: 0.5rem; }
  #tutor-panel .control-grid .btn { min-height: 42px; font-size: 0.95rem; }
  #tutor-actions[hidden] { display: none !important; }

  /* other panels */
  .ghost-stage { max-width: 200px; }
  .ghost-status { font-size: 1rem; }
  .zen-num { font-size: 3rem; }

  /* modals become bottom sheets */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%; max-height: 92vh; max-height: 92dvh;
    border-radius: 22px 22px 0 0; border-bottom: 0;
    transform: translateY(40px);
  }
  .modal-head { padding: 1rem 1.1rem 0.5rem; }
  .modal-head h2 { font-size: 1.35rem; }
  .modal-body { padding: 0.3rem 1.1rem 0.8rem; font-size: 1rem; }
  .modal-actions { padding: 0.7rem 1.1rem calc(0.9rem + env(safe-area-inset-bottom)); }
  .modal-actions .btn { flex: 1; min-height: 48px; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 1.4rem; }
  .summary-title { font-size: 2.2rem; }
  .heatmap { max-width: 100%; }
  .heat-num { font-size: 1rem; }
  .heat-count { font-size: 0.72rem; }
  .dir-row { grid-template-columns: 70px 1fr 78px; font-size: 0.95rem; }
  .skin-grid { grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
  .skin-name { font-size: 0.9rem; }
  .skin-import { min-height: 120px; }
  .setting-row { padding: 0.75rem 0; }
  .kbd-list { font-size: 0.95rem; }
  #toasts { bottom: calc(1rem + env(safe-area-inset-bottom)); width: min(94vw, 460px); }
  .toast { font-size: 1rem; padding: 0.85rem 1rem; }
}

/* ---------- landscape phones: board left, panels right ---------- */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
  .game-layout { display: flex; flex-direction: row; align-items: flex-start; gap: 0.8rem; }
  .side-panel { display: flex; flex-direction: column; gap: 0.7rem; position: static; flex: 1; min-width: 0; }
  .board-column { flex: 0 0 52%; order: 0; }
  .board-stage { height: calc(100vh - 120px); height: calc(100dvh - 120px); }
  #tutor-panel { position: static; margin: 0; border-radius: var(--radius); box-shadow: var(--shadow-sm); order: 0; }
  #panel-controls, #ghost-panel, #zen-panel, #daily-panel, #demo-panel, #ring-panel { order: 0; }
}
