/*
  CodePlay Mobile — the phone layout.
  Loaded after style.css, so these rules win. Think of it as a "small stage" preset:
  same show, everything moved into one column and made big enough for a thumb.
*/

/* ---------- Every screen size ---------- */

/* The ☰ button and the menu words only show on a phone. On a big screen the
   menu's buttons simply sit in the top bar like before. */
#menu-toggle { display: none; }
.topbar-menu { display: flex; align-items: center; gap: .5rem; }
.topbar-menu > * { white-space: nowrap; }
.menu-label { display: none; }
.menu-only { display: none !important; }      /* Install / Share live in the phone menu */

/* No grey flash when tapping, and no page jumping sideways. */
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
body { overflow-x: clip; }

/* Phones have no mouse: skip the "lift on hover" so buttons don't stay lifted after a tap. */
@media (hover: none) {
  button:hover, .pad:hover, .track-card:hover, a.boss-pad:hover, .player-card:hover { transform: none; }
}


/* ---------- Phone size (iPhone is about 375–430 wide) ---------- */
@media (max-width: 640px) {
  html { font-size: 17px; }

  /* Top bar: logo on the left; XP, goal ring and ☰ on the right. Respects the iPhone notch. */
  /* From the home screen the app runs full screen, so the bar starts below the clock / notch
     (safe-area-inset-top) with breathing room. --top-safe is reused by things stuck under the bar. */
  :root { --top-safe: env(safe-area-inset-top, 0px); }
  .topbar {
    padding: .25rem max(.6rem, env(safe-area-inset-right)) .25rem max(.85rem, env(safe-area-inset-left));
    padding-top: calc(var(--top-safe) + .25rem);
    gap: .6rem;
    transition: transform .25s ease;
  }
  /* Scrolling down to read: the bar slides up out of the way (see startTopBar()). On an iPhone
     a plain strip stays behind the clock so text never scrolls under it (0 tall elsewhere). */
  body.bar-away .topbar { transform: translateY(-100%); }
  html::before {                             /* (body::before is Arcade's grid floor) */
    content: ""; position: fixed; top: 0; left: 0; right: 0; z-index: 11;
    height: var(--top-safe); background: var(--bg); pointer-events: none;
  }
  #goal-mini { display: none; }              /* more room up top; the goal ring is on the home page */
  .logo { font-size: .95rem; gap: .45rem; min-width: 0; }
  .logo img { width: 30px; height: 30px; border-radius: 7px; }
  .logo-text { display: flex; flex-direction: column; line-height: 1.15; }
  [data-theme="arcade"] .logo { font-size: .62rem; }
  .topbar-right { position: relative; gap: .2rem; flex: none; }
  #level-chip { padding: .3rem .65rem; }
  #level-chip .chip-dot { display: none; }   /* "🎧 15 XP" is enough on a phone */

  /* ☰ is a plain icon (still a 44-point tap target), not another box next to the XP badge. */
  #menu-toggle {
    display: grid; place-items: center; width: 44px; height: 44px; padding: 0;
    font-size: 1.35rem; line-height: 1; border-radius: 12px;
    background: transparent; border-color: transparent; box-shadow: none;
  }
  [data-theme="arcade"] #menu-toggle { color: var(--cyan); background: transparent; border-color: transparent; box-shadow: none; }
  #menu-toggle[aria-expanded="true"] { background: var(--card); }
  /* The menu drops down under the ☰ button. */
  .topbar-menu {
    display: none; position: absolute; right: 0; top: calc(100% + .5rem); z-index: 20;
    flex-direction: column; align-items: stretch; gap: .4rem; width: 220px;
    padding: .6rem; border-radius: 16px; background: var(--card);
    border: 1px solid var(--line); box-shadow: 0 12px 32px rgba(0, 0, 0, .35);
  }
  .topbar-menu.open { display: flex; }
  .topbar-menu > * {
    display: flex; align-items: center; gap: .4rem; min-height: 44px;
    padding: .4rem .9rem; font-size: .95rem; border-radius: 12px; text-align: left;
  }
  .topbar-menu #player-chip .level-name { display: inline; }
  .menu-label { display: inline; }
  .topbar-menu .menu-only { display: flex !important; }
  [data-theme="arcade"] .topbar-menu { border: 2px solid var(--cyan); border-radius: 6px; background: #0d0d2b; box-shadow: 0 0 20px rgba(41, 243, 255, .3); }
  [data-theme="arcade"] .topbar-menu > * { border-radius: 6px; }
  [data-theme="arcade"] .topbar-menu > a { font-size: .6rem; }
  #sound-toggle::after { content: " Sounds"; }
  #app-version { min-height: 0; padding: .1rem .9rem 0; font-size: .7rem; color: var(--muted); }
  #app-version:empty { display: none !important; }

  /* The page itself: narrower edges, one column. */
  main { padding: 1rem max(.85rem, env(safe-area-inset-left)) 4rem; }
  .footer { padding-bottom: max(2rem, env(safe-area-inset-bottom)); }
  /* Pop-up messages drop in under the top bar (the bottom belongs to the lesson's Next button). */
  #toasts { right: .75rem; left: .75rem; top: calc(var(--bar-h, 4.2rem) + .5rem); bottom: auto; align-items: stretch; }

  /* Thumb-sized buttons: at least 44 points tall (Apple's guideline). */
  button, a.button { min-height: 44px; }
  .term { min-height: 0; }        /* glossary words are inline text, keep them that way */

  /* Text boxes at 16px or more, or the iPhone zooms in when you tap them. */
  input, select, textarea, #g-search, .player-form input, .goal-tile select { font-size: 16px; }

  /* ----- Home ----- */
  .hero { padding: 1.3rem 1.1rem; margin-top: 0; border-radius: 20px; }
  .hero h1 { font-size: 1.6rem; }
  [data-theme="arcade"] .hero h1 { font-size: 1rem; }
  .hero button.primary { width: 100%; }
  .tracker { grid-template-columns: 1fr 1fr; gap: .7rem; }
  .level-tile, .tile.continue { grid-column: 1 / -1; }
  .tile { padding: .8rem .9rem; }
  .track-grid { grid-template-columns: 1fr; }
  .record-grid { grid-template-columns: repeat(3, 1fr); }

  /* ----- A language's stage map ----- */
  .track-hello { padding: 1.1rem 1rem; }
  .track-hello button { width: 100%; }
  .stage { grid-template-columns: 36px 1fr; gap: .6rem; }
  .stage-node { width: 36px; height: 36px; font-size: 1rem; border-width: 3px; }
  .map::before { left: 16px; }
  .stage-card { padding: .9rem .9rem 1rem; }
  .pads { grid-template-columns: 1fr 1fr; }
  .pad { min-height: 72px; }

  /* ----- A lesson ----- */
  .lesson-top { flex-direction: column; align-items: flex-start; gap: .4rem; }
  .lesson-title { font-size: 1.55rem; }
  [data-theme="arcade"] .lesson-title { font-size: .95rem; }

  /* The step buttons become one row you can swipe sideways, stuck under the top bar. */
  .steps {
    position: sticky; top: var(--bar-h, calc(var(--top-safe) + 62px)); z-index: 5;
    transition: top .25s ease;
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 -.85rem 1rem; padding: .4rem .85rem;
    background: var(--bg);
  }
  body.bar-away .steps { top: var(--top-safe); }               /* follows the bar up */
  .steps::-webkit-scrollbar { display: none; }
  .steps button { flex: none; min-height: 40px; }
  [data-theme="arcade"] .steps button { font-size: .6rem; }
  .card { padding: 1rem 1rem 1.1rem; scroll-margin-top: calc(var(--bar-h, 110px) + 64px); }
  .idea { font-size: 1.05rem; }

  /* Editor above, preview below; the buttons fill the width so they're easy to hit. */
  .workbench { grid-template-columns: 1fr; }
  .toolbar { gap: .45rem; }
  .toolbar button { flex: 1 1 auto; }
  #run-btn { order: -1; flex-basis: 100%; }
  .editor .cm-editor { min-height: 140px; }
  .editor .cm-scroller { -webkit-overflow-scrolling: touch; }
  .editor .cm-lineNumbers .cm-gutterElement { padding-left: 8px; min-width: 1.8em; }
  .editor .cm-line { padding: 0 12px 0 8px; }

  /* Bug hunts: each code line is a big tap target. */
  .bug-line { padding: .55rem .7rem; min-height: 44px; align-items: baseline; gap: .6rem; white-space: pre-wrap; word-break: break-word; }
  .bug-code { overflow-x: visible; }
  .bug-hunt { padding: .7rem .7rem; }
  #skip-hunt { width: 100%; }

  /* Challenges and the checkpoint */
  .challenge { padding: .8rem .8rem; }
  .chal-status { margin-left: 0; width: 100%; }
  .options button { min-height: 52px; }

  /* Previous / next: stacked, full width */
  .pager { flex-direction: column; }
  .pager a.next { order: -1; }

  /* Long code words (like Live.Song.tempo.add_listener) may break onto the next line. */
  code { overflow-wrap: anywhere; }
  main button { white-space: normal; }

  /* Glossary pop-up never wider than the screen */
  #term-pop { max-width: calc(100vw - 1.5rem); }

  /* Boxes in a grid may shrink instead of pushing the page wider. */
  .tracker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile, .stage-card, .card { min-width: 0; overflow-wrap: anywhere; }
}

/* ---------- Narrow phones (Galaxy S22 with bigger screen zoom, iPhone SE, …) ---------- */
@media (max-width: 380px) {
  .topbar { gap: .35rem; padding-left: max(.6rem, env(safe-area-inset-left)); padding-right: max(.6rem, env(safe-area-inset-right)); }
  .topbar-right { gap: .3rem; }
  #level-chip { padding: .25rem .5rem; font-size: .8rem; }
  [data-theme="arcade"] #level-chip { font-size: .5rem; }
  [data-theme="arcade"] .logo { font-size: .55rem; }
  .logo { gap: .3rem; }
  .logo img { width: 22px; height: 22px; }
}
/* Last resort on very narrow screens: the logo words get cut with "…" rather than push things off. */
@media (max-width: 640px) {
  .logo-text { min-width: 0; overflow: hidden; }
  .logo-text, .logo-text .by { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
}


/* ---------- Install on phone (app/mobile.js) ---------- */
.install-card {
  display: flex; gap: .9rem; align-items: flex-start; margin-bottom: 1rem; padding: 1rem;
  border-radius: var(--radius); background: var(--card); border: 2px solid var(--accent); box-shadow: var(--shadow);
}
.install-card img { border-radius: 13px; flex: none; }
.install-card p { margin: .2rem 0 .5rem; color: var(--muted); font-size: .9rem; }
.install-card .toolbar { margin-top: .3rem; }
.install-page { max-width: 640px; margin: 0 auto; }
.install-page h1 { margin: .3rem 0; }
.install-steps { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .9rem; }
.install-steps li { display: flex; gap: .8rem; align-items: flex-start; }
.install-steps small { color: var(--muted); }
.step-num {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700;
}
.ios-icon { width: 1.4em; height: 1.4em; vertical-align: -0.35em; color: #0a84ff; background: #fff; border-radius: 6px; padding: 2px; }
.install-finish { margin-top: 1rem; font-weight: 600; }
.install-done { text-align: center; }
.install-done .big { font-size: 3rem; }
[data-theme="arcade"] .install-card { border-color: var(--cyan); box-shadow: 0 0 18px rgba(41, 243, 255, .3); border-radius: 6px; }
[data-theme="arcade"] .install-card strong { font-family: "Pixel", monospace; font-weight: 400; font-size: .65rem; line-height: 1.7; color: var(--yellow); }
[data-theme="arcade"] .step-num { border-radius: 4px; background: var(--pink); font-family: "Pixel", monospace; font-size: .6rem; font-weight: 400; }

/* ---------- Bite-size lessons: one step at a time (app/mobile.js) ---------- */
.view-toggle { font-size: .8rem; padding: .2rem .8rem; }
.bite-hidden { display: none !important; }
main.bite { padding-bottom: 7rem; }
main.bite .pager { display: none; }                          /* the bottom bar does this job */
main.bite:not(.bite-first) .lesson-sub { display: none; }    /* after step 1, more room for the step */
.steps button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.bite-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: .6rem; align-items: center;
  padding: .6rem max(.85rem, env(safe-area-inset-right)) calc(.6rem + env(safe-area-inset-bottom)) max(.85rem, env(safe-area-inset-left));
  background: var(--bg); background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.bite-bar button { min-height: 50px; }
.bite-back { width: 56px; flex: none; font-size: 1.2rem; padding: 0; }
.bite-back:disabled { opacity: .35; }
.bite-next { flex: 1; font-size: 1rem; }
.bite-dots { display: flex; gap: 5px; flex: none; }
.bite-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.bite-dots span.past { background: var(--done); }
.bite-dots span.now { background: var(--accent); transform: scale(1.3); }
body.typing .bite-bar { display: none; }
[data-theme="arcade"] .bite-bar { border-top: 2px solid var(--line); }
[data-theme="arcade"] .bite-dots span { border-radius: 1px; }
[data-theme="arcade"] .bite-dots span.now { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
[data-theme="arcade"] .bite-dots span.past { background: var(--green); }
[data-theme="arcade"] .view-toggle { font-size: .75rem; }

/* Link-buttons match the real buttons (pink in Arcade, gradient in Light / Dark). */
a.button { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; }
a.button.primary { background: linear-gradient(135deg, #6f6cf2, #a45cd4); border: 0; color: #fff; }
[data-theme="arcade"] a.button.primary {
  background: var(--pink); color: #fff; border-radius: 6px; font-family: "Pixel", monospace; font-size: .62rem;
  box-shadow: 0 5px 0 #a3196a, 0 0 20px rgba(255, 62, 165, .45);
}
