/* Phones and touch devices only. Loaded last; every rule sits inside a media
   query, so desktop layouts never match anything here. */

/* ---------- Performance on touch devices ---------- */

@media (pointer: coarse) {
  /* A full-screen blended grain layer makes the phone re-composite the whole
     screen every time the background curve repaints; plain texture is cheap. */
  .home-screen::after {
    display: none;
  }

  .home-screen {
    background-image: var(--grain);
  }

  /* Blurring everything behind a dialog is expensive on phone GPUs. */
  .daily-dialog-backdrop {
    backdrop-filter: none;
  }

  /* The rotating colour glow sits under the finger, where it can't be seen. */
  .drawing-aura {
    display: none;
  }
}

/* ---------- Phone layout ---------- */

@media (max-width: 600px) {
  /* Game: the graph comes first, with listening and checking right under it. */
  body .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
    grid-template-areas:
      "game-header"
      "game-main"
      "game-sidebar";
  }

  /* One-row header: the theme toggle stays on the homepage. */
  .app .game-header {
    flex-wrap: nowrap;
    min-height: 48px;
    padding: 6px 12px;
  }

  .app #gameAppearanceDock {
    display: none;
  }

  html .app main {
    padding: 12px 10px 6px;
  }

  .app .canvas-wrap {
    --graph-gutter: 26px;
    height: clamp(240px, 40svh, 420px);
    min-height: 240px;
  }

  /* Graph readouts sit side by side, without their long captions. */
  .app .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .app .metric {
    padding: 7px 8px;
  }

  .app .metric + .metric {
    border-top: 0;
    border-left: 1px dashed var(--line);
  }

  .app .metric span {
    font-size: 0.66rem;
  }

  .app .metric small {
    display: none;
  }

  .app .metric strong {
    margin-top: 2px;
    font-size: 0.95rem;
  }

  /* Sidebar under the graph, reordered for play: listen, draw controls,
     feedback, then the rest. */
  .app > aside {
    gap: 12px;
    padding: 12px;
  }

  .app > aside > .panel:not(.controls):not(.daily-progress-panel) { order: 1; }
  .app > aside > .panel.controls { order: 2; }
  .app > aside > .feedback { order: 3; }
  .app > aside > .daily-progress-panel { order: 4; }
  .app > aside > .score-strip { order: 5; }
  .app > aside > .brand { order: 6; }

  .app .panel {
    padding: 12px;
  }

  .app .panel-title {
    margin-bottom: 8px;
  }

  /* Target mappings as compact ruled lines. */
  .app .target-grid {
    gap: 0;
  }

  .app .target-row {
    grid-template-columns: 26px minmax(0, 1fr);
    padding: 5px 2px;
  }

  .app .target-row .symbol {
    width: 26px;
    height: 26px;
    font-size: 0.8rem;
  }

  .app .target-row p {
    font-size: 0.9rem;
  }

  /* Check match / Give up / Clear share one row. */
  .app .tool-row {
    flex-wrap: nowrap;
  }

  .app .tool-row button:not(.icon) {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0 10px;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  /* Scores in a single row of four. */
  .app .score-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .app .score-box {
    padding: 8px 6px;
  }

  .app .score-box span {
    font-size: 0.62rem;
    letter-spacing: 0.04em;
  }

  .app .score-box strong,
  .app .score-box strong.small-score,
  .app .score-box strong.rating-score {
    font-size: 1.05rem;
  }

  .app .feedback {
    min-height: 0;
  }

  /* Profile: one-row header, stats two by two, less padding. */
  .profile-screen .profile-topbar {
    flex-wrap: nowrap;
    min-height: 48px;
    padding: 6px 12px;
  }

  .profile-screen .profile-topbar [data-appearance-dock] {
    display: none;
  }

  .profile-screen .profile-page-layout {
    width: calc(100% - 24px);
    margin: 16px auto 24px;
  }

  .profile-screen .profile-page-nav {
    margin-bottom: 14px;
  }

  .profile-screen .profile-page-card {
    padding: 24px 16px;
  }

  .profile-screen .profile-page-card .profile-header {
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 14px;
  }

  .profile-screen .profile-page-card .profile-avatar {
    width: 56px;
    height: 56px;
    font-size: 1.4rem;
  }

  .profile-screen .profile-page-card .home-stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .profile-screen .home-stat {
    padding: 8px 10px;
  }

  .profile-screen .home-stat strong {
    font-size: 1.25rem;
  }

  /* Homepage: keep the card clear of the footer. */
  .home-screen {
    padding-bottom: 44px;
  }
}
