/* Phone / tablet / app-wrapper layer, loaded after style.css.
   Breakpoints used throughout:
   - compact header: max-width 1180px (single-row bar with short labels; Settings replaces the top-bar audio controls)
   - phone tabs: max-width 600px, or max-width 760px in portrait (navigation moves to a bottom tab bar)
   - short landscape: max-height 500px in landscape (phones on their side)
   - immersive game: pointer coarse, max-width 760px or max-height 500px (the level fills the viewport)
   Reusable primitives: --safe-t/r/b/l, --app-h, --tap, .overlay-card / .overlay-buttons (adaptive modal card
   with a button row), .scroll-x (horizontal scroller), the `prism:screen` event and window.__UI__ from ui.js. */
:root {
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --app-h: 100vh;
  --tap: 44px;
  --tabbar-h: 0px;
}
@supports (height: 100dvh) {
  :root {
    --app-h: 100dvh;
  }
}

/* ----- touch behaviour: pinch zoom stays available, double-tap zoom and text selection on controls do not ----- */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: manipulation;
}
button,
.tile,
.nav,
.brand,
.level-card,
.primary,
.outlined,
.quiet,
.icon-button,
.hero-art,
.setting-link,
.switch,
#game {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
@media (pointer: coarse) {
  input:not([type="range"], [type="checkbox"], [type="radio"]),
  select,
  textarea {
    font-size: 16px; /* below 16px iOS zooms the page on focus */
  }
  input:not([type="range"], [type="checkbox"], [type="radio"]),
  select {
    min-height: var(--tap);
  }
}
.scroll-x {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.scroll-x::-webkit-scrollbar {
  display: none;
}

/* ----- safe areas (notch, rounded corners, home indicator) in the browser as well as installed ----- */
html.standalone body {
  padding: 0; /* style.css padded the whole body; insets are applied per component below */
}
.topbar {
  padding-top: var(--safe-t);
  height: calc(92px + var(--safe-t));
  padding-left: max(5.5%, calc(var(--safe-l) + 12px));
  padding-right: max(5.5%, calc(var(--safe-r) + 12px));
}
main {
  padding-left: max(5.5%, calc(var(--safe-l) + 12px));
  padding-right: max(5.5%, calc(var(--safe-r) + 12px));
  padding-bottom: calc(var(--safe-b) + var(--tabbar-h));
}
#toast {
  z-index: 80;
  bottom: calc(22px + var(--safe-b) + var(--tabbar-h));
}
.auth-gate {
  align-items: flex-start;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: max(24px, var(--safe-t)) max(20px, var(--safe-r)) max(24px, var(--safe-b)) max(20px, var(--safe-l));
}
.auth-card {
  margin: auto;
}
.doc {
  padding-top: calc(36px + var(--safe-t));
  padding-left: max(22px, calc(var(--safe-l) + 12px));
  padding-right: max(22px, calc(var(--safe-r) + 12px));
  padding-bottom: calc(60px + var(--safe-b));
}
#update-gate {
  padding: max(24px, var(--safe-t)) max(24px, var(--safe-r)) max(24px, var(--safe-b)) max(24px, var(--safe-l));
}

/* ----- tap targets everywhere ----- */
.icon-button,
.account-button,
dialog > .icon-button {
  min-width: var(--tap);
  height: var(--tap);
}
.brand {
  min-height: var(--tap);
}
.outlined,
.quiet,
.small,
.account-tabs button,
.catalog-controls select,
.tool {
  min-height: var(--tap);
}
.play-course {
  min-height: var(--tap);
  align-items: center;
}
.practice-course,
.board-course,
.share-course {
  flex: none;
  width: var(--tap);
  min-height: var(--tap);
}
.search-field input,
.share-link input {
  min-height: var(--tap);
  font-size: 16px;
}
.top-actions .account-button,
.top-actions .icon-button {
  min-height: var(--tap);
  height: var(--tap);
}
.icon-button[hidden] {
  display: none;
}
.check-row input[type="checkbox"] {
  width: 24px;
  height: 24px;
}
.check-row {
  min-height: var(--tap);
  align-items: center;
}
.check-row a {
  display: inline-block;
  padding: 14px 0;
  margin: -14px 0;
}.records-tab {
  min-height: var(--tap);
}
.link-button {
  padding: 4px 0;
}
footer .legal-links a {
  display: inline-block;
  padding: 15px 2px;
}
.brand {
  min-width: var(--tap);
}
@media (pointer: coarse) {
  .editor-scroll input[type="range"],
  .setting-row input[type="range"] {
    height: var(--tap);
  }
}
#account-dialog .outlined {
  width: 100%;
}

/* ----- header: desktop shows full labels and top-bar controls; compact modes use short labels + Settings ----- */
.nav-short,
.nav-icon,
.topbar .nav-settings {
  display: none;
}
.nav-ind {
  display: none;
}
.nav-icon {
  flex: none;
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.settings-button {
  font-size: 18px;
}

@media (max-width: 1180px) {
  .topbar {
    height: calc(64px + var(--safe-t));
    flex-wrap: nowrap;
    gap: 12px;
    padding-left: max(4%, calc(var(--safe-l) + 12px));
    padding-right: max(4%, calc(var(--safe-r) + 12px));
  }
  .brand {
    font-size: 16px;
    padding-bottom: 0;
    white-space: nowrap;
  }
  .brand-mark {
    font-size: 28px;
  }
  .brand small {
    display: none;
  }
  .topbar nav {
    order: 0;
    flex: 1;
    min-width: 0;
    width: auto;
    height: 100%;
    gap: 2px;
    justify-content: center;
    flex-wrap: nowrap;
  }
  .topbar .nav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    font-size: 14px;
    white-space: nowrap;
  }
  .topbar .nav-long,
  .topbar .new,
  .topbar .nav-support,
  .top-actions #help,
  .top-actions #mute,
  .top-actions .volume-wrap,
  .top-actions .settings-button {
    display: none;
  }
  .topbar .nav-short {
    display: inline;
  }
  .topbar .nav-settings {
    display: inline-flex;
  }
  main {
    padding-left: max(4%, calc(var(--safe-l) + 12px));
    padding-right: max(4%, calc(var(--safe-r) + 12px));
  }
}
@media (max-width: 900px) {
  .top-actions .account-button {
    padding: 0 7px;
  }
  .top-actions .account-label {
    display: none;
  }
  .topbar .nav {
    padding: 0 9px;
  }
}
/* Phone on its side: keep one slim bar, brand mark only. */
@media (max-height: 500px) and (orientation: landscape) and (min-width: 560px) {
  .topbar {
    height: calc(52px + var(--safe-t));
  }
  .topbar .nav {
    font-size: 13px;
    padding: 0 9px;
  }
}
@media (max-height: 500px) and (orientation: landscape) and (min-width: 600px) {
  .level-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
@media (max-height: 500px) and (orientation: landscape) and (min-width: 560px) and (max-width: 800px) {
  .brand {
    font-size: 0;
    gap: 0;
  }
  .brand-mark {
    margin: 0;
  }
}
/* Phone portrait: compact top bar + bottom tab bar. */
@media (max-width: 600px), (max-width: 760px) and (orientation: portrait) {
  :root {
    --tabbar-h: 92px;
  }
  .topbar {
    height: calc(56px + var(--safe-t));
    padding-left: max(16px, calc(var(--safe-l) + 12px));
    padding-right: max(16px, calc(var(--safe-r) + 12px));
  }
  .topbar nav {
    position: fixed;
    z-index: 40;
    left: 0;
    right: 0;
    bottom: 0;
    height: auto;
    display: flex;
    align-items: flex-start;
    gap: 0;
    height: calc(92px + var(--safe-b));
    padding: 9px 8px var(--safe-b);
    background: rgba(9, 13, 25, 0.94);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid #151b2e;
  }
  /* One highlight slides under the tabs; app.js sets --tab to the active tab's index, or .no-tab off the tabs. */
  .topbar .nav-ind {
    display: block;
    position: absolute;
    top: 9px;
    left: calc(8px + var(--tab, 0) * (100% - 16px) / 5);
    width: calc((100% - 16px) / 5);
    height: 72px;
    border: 1px solid rgba(109, 255, 208, 0.35);
    border-radius: 22px;
    background: rgba(109, 255, 208, 0.12);
    pointer-events: none;
    transition: left 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: nav-glow 2.4s ease-in-out infinite;
  }
  .topbar nav.no-tab .nav-ind {
    visibility: hidden;
  }
  .topbar .nav {
    position: relative;
    flex: 1;
    min-width: 0;
    flex-direction: column;
    justify-content: center;
    gap: 6px;
    height: 72px;
    min-height: 72px;
    padding: 0 2px;
    color: #8a93ad;
    font-size: 12px;
    font-weight: 500;
    transition:
      color 0.2s ease,
      transform 0.15s ease;
  }
  .topbar .nav:active {
    transform: scale(0.88);
  }
  .topbar .nav-icon {
    display: block;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  }
  .topbar .nav.active {
    color: var(--mint);
    font-weight: 700;
  }
  .topbar .nav.active .nav-icon {
    animation: nav-pop 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  }
  .topbar .nav.active:after {
    display: none;
  }
  main {
    padding-left: max(16px, calc(var(--safe-l) + 12px));
    padding-right: max(16px, calc(var(--safe-r) + 12px));
  }
  /* Bottom sheets instead of floating dialogs. */
  dialog {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
    border-bottom: 0;
    padding: 20px max(18px, calc(var(--safe-r) + 12px)) calc(22px + var(--safe-b)) max(18px, calc(var(--safe-l) + 12px));
    max-height: calc(var(--app-h) - 12px - var(--safe-t));
  }
  #account-dialog,
  #upgrade-dialog {
    max-width: 100%;
    width: 100%;
    padding: 20px max(18px, calc(var(--safe-r) + 12px)) calc(22px + var(--safe-b)) max(18px, calc(var(--safe-l) + 12px));
    max-height: calc(var(--app-h) - 12px - var(--safe-t));
  }
  dialog[open] {
    animation: sheet-up 0.22s ease-out;
  }
  dialog h2,
  #account-dialog h2 {
    font-size: 24px;
  }
}
@keyframes nav-pop {
  0% {
    transform: translateY(0) scale(0.7) rotate(-14deg);
  }
  60% {
    transform: translateY(-7px) scale(1.28) rotate(6deg);
  }
  100% {
    transform: translateY(-2px) scale(1.12) rotate(0);
  }
}
@keyframes nav-glow {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(109, 255, 208, 0);
  }
  50% {
    box-shadow: 0 0 20px 0 rgba(109, 255, 208, 0.3);
  }
}
@media (prefers-reduced-motion: reduce) {
  .topbar .nav,
  .topbar .nav-icon,
  .topbar .nav-ind {
    transition: none;
  }
  .topbar .nav.active .nav-icon {
    animation: none;
    transform: translateY(-2px) scale(1.12);
  }
  .topbar .nav-ind {
    animation: none;
  }
}
@keyframes sheet-up {
  from {
    transform: translateY(40px);
    opacity: 0;
  }
}
dialog {
  overflow: auto;
  overscroll-behavior: contain;
  max-height: calc(var(--app-h) - 24px - var(--safe-t) - var(--safe-b));
}
@media (max-height: 500px) {
  dialog,
  #account-dialog {
    padding: 18px 24px;
  }
  dialog h2,
  #account-dialog h2 {
    font-size: 22px;
    margin: 4px 0 10px;
  }
  dialog .eyebrow {
    margin-bottom: 8px;
  }
  .auth-card {
    padding: 20px 24px;
  }
  .auth-card h2 {
    font-size: 28px;
  }
  .page-title {
    padding-top: 18px;
  }
  .back-menu {
    margin-top: 8px;
  }
}

/* ----- readable sizes on phones and tablets (decorative hero art stays as designed) ----- */
@media (max-width: 1180px), (pointer: coarse) {
  .eyebrow,
  .section-heading .eyebrow,
  .hero .eyebrow,
  .overlay-card .eyebrow {
    font-size: 11px;
    letter-spacing: 1.4px;
  }
  .more-levels small,
  .count {
    font-size: 11px;
  }
  .studio-banner .outlined {
    font-size: 13px;
  }
  .section-note,
  .studio-banner p,
  .record-summary span,
  .panel h2 small {
    font-size: 13px;
  }
  .card-number,
  .card-duration,
  .difficulty,
  .stars,
  .level-tag,
  .card-progress-label {
    font-size: 11px;
  }
  .card-progress-label b {
    font-size: 12px;
  }
  .play-course {
    font-size: 13px;
    padding: 8px 12px;
  }
  .practice-course {
    font-size: 17px;
  }
  .outlined,
  .small {
    font-size: 13px;
  }
  th,
  .editor-settings label,
  .editor-scroll,
  .tool span,
  .editor-foot b,
  .keycap,
  kbd,
  .badge,
  .hero-meta {
    font-size: 11px;
  }
  .editor-foot,
  .editor-warning,
  .game-bottom {
    font-size: 13px;
  }
  footer {
    font-size: 11px;
    letter-spacing: 1px;
    flex-wrap: wrap;
    justify-content: center;
    text-align: center;
    padding-bottom: calc(27px + var(--safe-b));
  }
  .footer-support {
    flex-direction: column;
  }
  .footer-support .outlined {
    width: 100%;
  }
  .game-title small,
  .hud-label,
  .progress-hud #form-label,
  .mode-instruction {
    font-size: 11px;
  }
  #exit-game {
    font-size: 14px;
  }
  /* Level studio: fields keep a usable width; tools scroll sideways in one row. */
  .editor-settings {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 170px), 1fr));
    align-items: end;
  }
  .editor-settings #delete-level {
    justify-self: start;
  }
  .tool-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    gap: 4px;
  }
  .tool-row::-webkit-scrollbar {
    display: none;
  }
  .tool {
    flex: none;
    padding: 6px 10px;
  }
  .tool-divider {
    display: block;
    flex: none;
  }
}
@media (max-width: 720px) {
  .editor-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  .editor-actions button {
    min-height: var(--tap);
    justify-content: center;
    font-size: 13px;
  }
  .editor-actions .quiet {
    border: 1px solid #3a455e;
    border-radius: 6px;
  }
}

/* ----- game: the level fills the viewport on touch devices and small windows ----- */
.rotate-hint {
  display: none;
}
@media (pointer: coarse), (max-width: 760px), (max-height: 500px) {
  html.in-game,
  html.in-game body {
    overflow: hidden;
    overscroll-behavior: none;
  }
  html.in-game .topbar {
    display: none;
  }
  html.in-game #game.active {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: flex;
    flex-direction: column;
    height: var(--app-h);
    padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
    background: var(--bg);
  }
  #game .game-top {
    flex: none;
    min-height: 52px;
    gap: 8px;
    padding: 4px 12px;
  }
  #game .game-top .quiet {
    gap: 8px;
    padding: 0 6px;
  }
  #game .game-title {
    min-width: 0;
    gap: 3px;
    font-size: 13px;
    letter-spacing: 1.2px;
  }
  #game .game-title span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #game .game-top-right {
    gap: 6px;
  }
  #game .icon-button {
    width: var(--tap);
    height: var(--tap);
  }
  #game .game-shell {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  #game-canvas {
    height: 100%;
    min-height: 0;
  }
  #game .game-hud {
    top: 10px;
    left: 14px;
    right: 14px;
  }
  #game .game-hud strong {
    font-size: 20px;
  }
  #game .progress-hud {
    width: 40%;
    min-width: 120px;
  }
  #game .mode-instruction {
    bottom: 10px;
  }
  #game .game-bottom {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 8px 12px;
  }
  #game .game-bottom > div:first-child,
  #game .game-hint {
    display: none;
  }
  #game .practice-controls {
    flex-wrap: nowrap;
    gap: 8px;
    font-size: 13px;
  }
  #game .practice-controls .small {
    padding: 8px 12px;
  }
  /* Pause / result card: covers the whole screen so it never squeezes into a short canvas. */
  #game .game-overlay {
    position: fixed;
    inset: 0;
    z-index: 70;
    overflow-y: auto;
    overscroll-behavior: contain;
    align-items: flex-start;
    padding: max(16px, var(--safe-t)) max(16px, var(--safe-r)) max(16px, var(--safe-b)) max(16px, var(--safe-l));
  }
  #game .game-overlay.hidden {
    display: none !important;
  }
  #game .overlay-card {
    margin: auto;
    min-width: 0;
    width: min(440px, 100%);
    padding: 24px 22px;
  }
  /* Portrait: a landscape-shaped course view (at least ~800 world units wide) over a large tap pad. */
  @media (orientation: portrait) {
    #game .game-shell {
      flex: none;
      width: 100%;
      aspect-ratio: 10 / 7;
      max-height: calc(var(--app-h) - var(--safe-t) - var(--safe-b) - 200px);
    }
    #game .mode-instruction {
      display: none;
    }
    #game .game-bottom {
      flex: 1 1 auto;
      min-height: 0;
      flex-direction: column;
      align-items: stretch;
      padding: 12px 14px;
    }
    #game .practice-controls {
      justify-content: space-between;
    }
    #game .touch-action {
      display: flex;
      flex: 1 1 auto;
      width: 100%;
      min-height: 96px;
      border-radius: 18px;
      border: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
      background:
        radial-gradient(80% 60% at 50% 100%, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
        #0d1626;
      color: var(--accent);
      box-shadow: inset 0 0 40px color-mix(in srgb, var(--accent) 10%, transparent);
      font-size: 16px;
      letter-spacing: 1.5px;
      transition:
        background 0.08s,
        transform 0.08s;
    }
    #game .touch-action.pressed {
      background: color-mix(in srgb, var(--accent) 85%, #0d1626);
      color: #071d1c;
      transform: scale(0.985);
    }
    #game .rotate-hint {
      display: block;
      text-align: center;
      font-size: 12px;
      color: var(--muted);
    }
  }
  /* Landscape: the canvas takes every remaining pixel and is itself the tap zone. */
  @media (orientation: landscape) {
    #game .game-shell {
      flex: 1 1 auto;
      min-height: 0;
    }
    #game .touch-action {
      display: none;
    }
    #game:not(.practice-on) .game-bottom {
      display: none;
    }
    #game .game-bottom {
      flex: none;
      justify-content: center;
      padding: 4px 12px;
    }
  }
}
@media (max-height: 500px) {
  .overlay-card {
    padding: 18px 22px;
  }
  .overlay-card h2 {
    font-size: 28px;
    margin: 6px 0;
  }
  .overlay-card p {
    margin-bottom: 14px;
  }
  .overlay-buttons {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .overlay-buttons button {
    flex: 1 1 140px;
    width: auto;
  }
}

/* ----- Settings screen ----- */
#settings [hidden] {
  display: none !important;
}
.settings-list {
  display: grid;
  gap: 16px;
  max-width: 760px;
  margin-bottom: 36px;
}
.settings-group {
  margin: 0;
  padding: 6px 20px;
}
.settings-group h2 {
  margin: 14px 0 2px;
  font:
    700 12px "DM Sans",
    system-ui,
    sans-serif;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.setting-row,
.setting-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 60px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  text-align: left;
  color: inherit;
}
.settings-group h2 + .setting-row,
.settings-group h2 + .setting-link,
.settings-group h2 + [hidden] + .setting-row {
  border-top: 0;
}
.setting-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.setting-text strong {
  font-size: 16px;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.setting-text small {
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.setting-link b {
  font-size: 24px;
  font-weight: 400;
  color: var(--muted);
}
.setting-link:hover b {
  color: var(--mint);
}
.setting-row input[type="range"] {
  width: min(240px, 50%);
  height: var(--tap);
  flex: none;
}
.setting-row .outlined {
  flex: none;
}
.switch {
  position: relative;
  flex: none;
  width: 60px;
  height: var(--tap);
}
.switch::before {
  content: "";
  position: absolute;
  inset: 6px 2px;
  border-radius: 999px;
  background: #273049;
  border: 1px solid #3a455e;
  transition: background 0.18s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 10px;
  left: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #cbd5e8;
  transition: transform 0.18s;
}
.switch[aria-checked="true"]::before {
  background: var(--mint);
  border-color: var(--mint);
}
.switch[aria-checked="true"]::after {
  transform: translateX(24px);
  background: #071d1c;
}
.settings-foot {
  margin: 10px 0 12px;
  font-size: 12px;
}

/* ----- end-of-run summary and level leaderboard (verified runs) ----- */
@media (pointer: coarse), (max-width: 760px), (max-height: 500px) {
  /* The result card already covers the screen here; with a summary it widens and scrolls inside the overlay. */
  #game .game-overlay.summary-open .overlay-card {
    width: min(760px, 100%);
    padding: 18px 16px;
  }
  #game .game-overlay.summary-open .overlay-card h2 {
    font-size: 28px;
  }
  .rs-section {
    padding: 10px 12px;
  }
  .rs-row {
    min-height: 30px;
  }
  .board-row {
    min-height: var(--tap);
  }
  .board-course,
  .share-course {
    width: var(--tap);
    min-height: var(--tap);
  }
}
@media (pointer: coarse), (max-width: 760px), (max-height: 500px) {
  @media (orientation: portrait) {
    .rs-grid {
      grid-template-columns: 1fr;
    }
  }
}
/* Short landscape (phone on its side): two columns, compact totals, buttons in one row. */
@media (max-height: 500px) and (orientation: landscape) and (min-width: 560px) {
  .rs-total strong {
    font-size: 26px;
  }
  .rs-grid,
  .rs-col {
    gap: 10px;
  }
  .board-list {
    max-height: calc(var(--app-h) - 230px - var(--safe-t) - var(--safe-b));
  }
}
/* Phone portrait: the leaderboard is a bottom sheet like the other dialogs. */
@media (max-width: 600px), (max-width: 760px) and (orientation: portrait) {
  .board-list {
    max-height: calc(var(--app-h) - 300px - var(--safe-t) - var(--safe-b));
  }
  #board-dialog .gate-actions {
    flex-direction: column;
  }
  #board-dialog .gate-actions button {
    width: 100%;
    min-height: var(--tap);
  }
  .daily-pick {
    padding: 12px;
    margin-top: 18px;
  }
}

/* Records → Ratings tab on phones: filters two per row, tabs full width. */
@media (max-width: 640px) {
  .records-tabs .records-tab {
    flex: 1;
    min-height: var(--tap, 44px);
  }
  .ratings-filters select {
    flex: 1 1 calc(50% - 8px);
    min-height: var(--tap, 44px);
  }
}

/* Engagement on phones: strip cards stack, ladder wraps, follow form full width. */
@media (max-width: 640px) {
  .engage {
    grid-template-columns: 1fr;
  }
  .season-ladder {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .setting-friends {
    flex-direction: column;
    align-items: stretch;
  }
  .follow-form input {
    flex: 1;
    width: auto;
    min-height: var(--tap, 44px);
  }
  .board-filters select,
  #ratings-scope {
    min-height: var(--tap, 44px);
  }
}

/* Shared links and search on phones: full-width search, stacked sheet actions, link field above Copy. */
@media (max-width: 600px), (max-width: 760px) and (orientation: portrait) {
  .catalog-controls .search-field {
    flex: 1 1 100%;
  }
  .ls-actions button {
    flex: 1 1 calc(50% - 8px);
  }
  .ls-actions .primary {
    flex-basis: 100%;
  }
  .share-link {
    flex-direction: column;
  }
  .share-targets .share-target {
    flex: 1 1 calc(33% - 8px);
    min-height: var(--tap, 44px);
  }
  /* Two cards per row leave no room for Play and three icon buttons side by side. */
  .level-grid .card-buttons:has(.share-course) {
    flex-wrap: wrap;
  }
  .level-grid .card-buttons:has(.share-course) .play-course {
    flex-basis: 100%;
    min-height: var(--tap, 44px);
    align-items: center;
  }
  .level-grid .card-buttons:has(.share-course) > :not(.play-course) {
    flex: 1 1 0;
    width: auto;
  }
}
