﻿/* Phone layout (V 0.19) */
/* Phone layout (V 0.19) */
/* Loaded after style.css. Only active on touch phones via body.touch. */

@media (max-width: 950px), (max-height: 520px) {
  /* ---------- Base phone UI: readable text, larger controls, safe areas ---------- */
  html:has(body.touch:not(.in-match)) {
    height: auto;
  }

  body.touch:not(.in-match) {
    min-height: 100%;
    overflow-y: auto;
    background: #0c1118;
    color: #ecf2fa;
  }

  body.touch button,
  body.touch select,
  body.touch input:not([type=range]) {
    min-height: 48px;
    font-size: 16px;
    line-height: 1.25;
  }

  body.touch textarea {
    min-height: 96px;
    font-size: 16px;
  }

  body.touch nav button,
  body.touch #audio,
  body.touch #fullscreen,
  body.touch #back {
    min-height: 48px;
    font-size: 16px;
    padding: 10px 12px;
  }

  body.touch small,
  body.touch .fine {
    font-size: 14px !important;
    line-height: 1.35;
  }

  body.touch #status {
    min-height: 22px;
    font-size: 16px;
    margin: 10px 0 8px;
  }

  body.touch .footnote {
    font-size: 14px;
    line-height: 1.35;
    margin: 8px 0;
  }

  /* ---------- Title screen: flowing page instead of fixed 16:9 picture ---------- */
  body.touch:not(.in-match) #app {
    width: auto;
    max-width: none;
    margin: 0;
    padding: calc(12px + var(--safe-top)) calc(14px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(14px + var(--safe-left));
    display: block;
  }

  body.touch:not(.in-match) nav {
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 16px;
  }

  body.touch:not(.in-match) nav > div {
    gap: 8px;
    flex-wrap: wrap;
  }

  body.touch:not(.in-match) #stage {
    width: auto;
    height: auto;
    aspect-ratio: auto;
    max-height: none;
    overflow: visible;
    border-radius: 7px;
  }

  body.touch:not(.in-match) #game {
    display: none;
  }

  /* Portrait default: one column, thumb-friendly order. */
  body.touch:not(.in-match) #title {
    position: relative;
    inset: auto;
    width: auto;
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(14px + var(--safe-left));
    background: radial-gradient(50vw 34vw at 8% 18%, #71e8ca1c, transparent 70%),
                radial-gradient(46vw 34vw at 100% 100%, #ff8f7718, transparent 70%),
                linear-gradient(180deg, #0d1420, #090e16);
    overflow: visible;
    grid-template-areas:
      "eyebrow"
      "title"
      "tagline"
      "menu"
      "options"
      "badges"
      "welcome"
      "daily"
      "hiscore"
      "rules"
      "version";
  }

  body.touch:not(.in-match) #title > * {
    position: relative;
    inset: auto;
    width: auto;
    max-width: none;
    min-height: auto;
    margin: 0;
  }

  body.touch:not(.in-match) #title .eyebrow {
    grid-area: eyebrow;
    font-size: 14px;
    letter-spacing: .12em;
    line-height: 1.35;
    color: var(--mint);
  }

  body.touch:not(.in-match) #title h1 {
    grid-area: title;
    font-size: 40px;
    line-height: 1.06;
    letter-spacing: -.02em;
    margin: 0;
  }

  body.touch:not(.in-match) #title .tagline {
    grid-area: tagline;
    font-size: 16px;
    line-height: 1.45;
    color: #9aa5b2;
    margin-top: 0;
  }

  body.touch:not(.in-match) #title .menu {
    grid-area: menu;
    position: relative;
    width: 100%;
    height: auto;
    display: grid;
    gap: 12px;
    align-content: start;
  }

  body.touch:not(.in-match) #title .main-row {
    min-height: 52px;
    border-radius: 6px;
    overflow: hidden;
  }

  body.touch:not(.in-match) #title .main-row button {
    height: 52px;
    min-height: 52px;
    font-size: 17px;
    padding: 0 14px;
    letter-spacing: .08em;
  }

  body.touch:not(.in-match) #title .main-row #cpu {
    flex: 1;
    font-size: 17px;
    letter-spacing: .1em;
    height: 52px;
    min-height: 52px;
  }

  body.touch:not(.in-match) #title .main-row #cpu-level {
    flex: none;
    width: auto;
    min-width: 96px;
    height: 52px;
    font-size: 16px;
    padding: 0 10px;
    letter-spacing: .08em;
  }

  body.touch:not(.in-match) #title .menu button,
  body.touch:not(.in-match) #title .options-button {
    width: 100%;
    min-height: 52px;
    font-size: 17px;
    padding: 0 14px;
    margin-top: 0;
    border-radius: 6px;
  }

  body.touch:not(.in-match) #title .pair {
    gap: 10px;
    margin-top: 0;
  }

  body.touch:not(.in-match) #title .pair button {
    min-height: 48px;
    font-size: 16px;
  }

  body.touch:not(.in-match) #title .options-button {
    grid-area: options;
    position: relative;
    width: 100%;
    height: auto;
    min-height: 52px;
    font-size: 17px;
    padding: 0 14px;
    border-radius: 6px;
  }

  body.touch:not(.in-match) #title .welcome,
  body.touch:not(.in-match) #menu-help {
    grid-area: welcome;
    position: relative;
    margin: 0;
    min-height: auto;
    font-size: 16px;
    line-height: 1.4;
    color: var(--mint);
  }

  body.touch:not(.in-match) #title .rules {
    grid-area: rules;
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    border-top: 1px solid #2c333d;
    padding-top: 10px;
    margin-top: 4px;
  }

  body.touch:not(.in-match) #title .rules p {
    display: grid;
    gap: 2px;
    font-size: 16px;
    line-height: 1.3;
    min-height: auto;
  }

  body.touch:not(.in-match) #title .rules b,
  body.touch:not(.in-match) #title .rules span {
    font-size: 16px;
    line-height: 1.25;
  }

  body.touch:not(.in-match) #title .version {
    grid-area: version;
    position: relative;
    margin: 0;
    font-size: 14px;
    letter-spacing: .12em;
    text-align: left;
    color: #71869e;
  }

  /* Landscape phone title: two columns, hiscore on the right. */
  @media (orientation: landscape) {
    body.touch:not(.in-match) #title {
      grid-template-columns: minmax(0, 1fr) minmax(260px, 45%);
      gap: 10px;
      grid-template-areas:
        "eyebrow eyebrow"
        "title hiscore"
        "tagline hiscore"
        "menu hiscore"
        "options hiscore"
        "badges hiscore"
        "welcome welcome"
        "daily daily"
        "rules rules"
        "version version";
    }

    body.touch:not(.in-match) #title h1 {
      font-size: 32px;
    }

    body.touch:not(.in-match) #title .menu,
    body.touch:not(.in-match) #title .options-button {
      min-height: 50px;
      font-size: 16px;
    }
  }

  /* ---------- High score board on title screen ---------- */
  body.touch:not(.in-match) #hiscore {
    grid-area: hiscore;
    position: relative;
    width: 100%;
    height: auto;
    min-height: 360px;
    padding: 10px;
    display: block;
    background: linear-gradient(180deg, #121c2acc, #0b121bcc);
    border: 1px solid #ffd84a55;
    border-radius: 6px;
    box-shadow: 0 0 18px #ffd84a14, inset 0 0 16px #00000055;
  }

  body.touch:not(.in-match) .board-tabs {
    position: static;
    margin-bottom: 8px;
    gap: 8px;
  }

  body.touch:not(.in-match) .board-tabs button {
    flex: 1;
    height: 48px;
    min-height: 48px;
    font-size: 16px;
    padding: 0 12px;
    letter-spacing: .08em;
  }

  body.touch:not(.in-match) #hiscore .board {
    position: relative;
    inset: auto;
    opacity: 1;
    pointer-events: auto;
    transition: none;
    display: block;
  }

  body.touch:not(.in-match) #hiscore .board:not(.shown) {
    display: none;
  }

  body.touch:not(.in-match) #hiscore header {
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-bottom: 1px solid #ffd84a33;
    padding-bottom: 6px;
    margin-bottom: 8px;
  }

  body.touch:not(.in-match) #hiscore h2 {
    font-size: 18px;
    letter-spacing: .04em;
  }

  body.touch:not(.in-match) #hiscore header span {
    font-size: 14px;
    letter-spacing: .06em;
  }

  body.touch:not(.in-match) #hiscore ol {
    display: flex;
    flex-direction: column;
    gap: 2px;
    grid-template-rows: none;
    margin-top: 4px;
    font-size: 16px;
  }

  body.touch:not(.in-match) #hiscore li {
    min-height: 34px;
    padding: 5px 8px;
    grid-template-columns: 28px minmax(0, 1fr) 56px 72px 72px;
    gap: 8px;
    font-size: 16px;
    white-space: normal;
  }

  body.touch:not(.in-match) #hiscore .rank,
  body.touch:not(.in-match) #hiscore .name,
  body.touch:not(.in-match) #hiscore .points {
    font-size: 16px;
  }

  body.touch:not(.in-match) #hiscore .level,
  body.touch:not(.in-match) #hiscore .date {
    font-size: 14px;
  }

  body.touch:not(.in-match) #hiscore li.empty .name {
    grid-column: 2 / 5;
    font-size: 16px;
  }

  /* ---------- Dialogs: options, name, online, install, fullscreen help ---------- */
  body.touch dialog {
    width: min(560px, 94vw);
    max-height: calc(var(--view-height) - 32px);
    padding: 18px;
    overflow: auto;
  }

  body.touch dialog h2 {
    margin-top: 0;
    font-size: 22px;
    line-height: 1.2;
    margin-bottom: 10px;
  }

  body.touch dialog p {
    font-size: 16px;
    line-height: 1.45;
  }

  body.touch dialog label {
    display: block;
    margin: 14px 0 8px;
    font-size: 16px;
  }

  body.touch dialog button,
  body.touch #online .code-row button,
  body.touch #online .online-foot button,
  body.touch #online .invite-actions button,
  body.touch #online .offer button {
    min-height: 48px;
    font-size: 16px;
    padding: 10px 12px;
    margin: 6px 8px 6px 0;
  }

  body.touch dialog select,
  body.touch dialog input:not([type=range]),
  body.touch #online input,
  body.touch #name-dialog input {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
    padding: 10px 12px;
  }

  body.touch #settings form {
    display: grid;
    gap: 12px;
    align-content: start;
  }

  body.touch .name-row,
  body.touch #online .code-row > span,
  body.touch #online .invite-actions,
  body.touch #online .offer {
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
  }

  body.touch #sensitivity {
    width: 100%;
    min-height: 40px;
    margin-top: 8px;
    accent-color: var(--mint);
  }

  body.touch .mouse-test {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-start;
    margin: 12px 0;
  }

  body.touch #mouse-test {
    width: min(320px, 58vw);
    max-width: 100%;
    height: auto;
    aspect-ratio: 320 / 146;
    flex: none;
  }

  body.touch .name-row output,
  body.touch #online-name,
  body.touch #online-rating {
    font-size: 16px;
    min-height: 24px;
    line-height: 1.2;
  }

  /* Online window */
  body.touch #online {
    width: min(560px, 94vw);
    padding: 18px;
    max-height: calc(var(--view-height) - 32px);
    overflow: auto;
  }

  body.touch .online-choices {
    grid-template-columns: 1fr;
    gap: 12px;
    margin-top: 12px;
  }

  body.touch #online .online-choices button {
    min-height: 64px;
    font-size: 17px;
    padding: 10px 12px;
    gap: 4px;
  }

  body.touch #online .online-choices small,
  body.touch #online .fine,
  body.touch #online-status {
    font-size: 14px;
    line-height: 1.35;
  }

  body.touch #online input {
    min-height: 48px;
    font-size: 16px;
    padding: 10px 12px;
  }

  body.touch #online #code-input {
    flex: 1;
    min-width: 0;
    font-size: 18px;
    letter-spacing: .12em;
  }

  body.touch .invite-code {
    display: block;
    width: 100%;
    font-size: 34px;
    padding: 10px 0 10px .3em;
    margin-top: 8px;
  }

  /* ---------- Pause / leave menu ---------- */
  body.touch .game-menu {
    position: fixed;
    inset: 0;
    z-index: 5;
    display: grid;
    place-items: center;
    padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  }

  body.touch .game-menu .panel {
    width: min(560px, 92vw);
    max-height: 100%;
    overflow: auto;
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  body.touch #menu-title {
    margin: 0;
    font-size: 24px;
    line-height: 1.15;
  }

  body.touch #menu-note {
    margin: 0;
    font-size: 16px;
    line-height: 1.4;
    color: #c3d1e0;
  }

  body.touch .menu-legend {
    order: 5;
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    text-align: left;
    margin-top: 2px;
  }

  body.touch .legend-head {
    font-size: 14px;
    line-height: 1.2;
  }

  body.touch .legend-row {
    min-height: 32px;
    grid-template-columns: 26px auto 1fr;
    gap: 8px;
    align-items: center;
    font-size: 16px;
    line-height: 1.25;
    color: #c3d1e0;
  }

  body.touch .legend-row canvas {
    width: 26px;
    height: 26px;
  }

  /* Buttons at the bottom of the panel for thumb reach. */
  body.touch .menu-buttons {
    order: 10;
    margin-top: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding-top: 4px;
  }

  body.touch .menu-buttons button {
    min-height: 56px;
    font-size: 17px;
    padding: 10px 12px;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  /* ---------- End-of-duel buttons over the arena ---------- */
  body.touch.in-match .end-buttons {
    left: 25.781%;
    width: 48.438%;
    top: 46%;
    height: auto;
    align-items: stretch;
    gap: 12px;
  }

  body.touch.in-match .end-buttons button {
    min-height: 48px;
    font-size: 16px;
    padding: 0 12px;
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  /* ---------- In-match menu button (pause / leave) ---------- */
  body.touch.in-match .menu-button {
    z-index: 3;
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    padding: 0;
    display: grid;
    place-items: center;
    background: #0c1118cc;
    border: 1px solid #2f4757;
    border-radius: 50%;
    opacity: .92;
    touch-action: manipulation;
  }

  body.touch.in-match .menu-button svg {
    width: 50%;
    height: 50%;
    pointer-events: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 3;
    stroke-linecap: round;
  }

  /* Landscape: inside the scoreboard strip, clear of "ROUNDS WON". */
  @media (orientation: landscape) {
    body.touch.in-match .menu-button {
      position: absolute;
      left: calc(67.6% - 24px);
      right: auto;
      top: max(4px, 1.2%);
      width: 48px;
      height: 48px;
    }
  }

  /* Portrait: fixed outside the thin arena strip, bottom-right thumb zone. */
  @media (orientation: portrait) {
    body.touch.in-match .menu-button {
      position: fixed;
      left: auto;
      top: auto;
      right: calc(16px + var(--safe-right));
      bottom: calc(20px + var(--safe-bottom));
      width: 56px;
      height: 56px;
    }
  }
}

/* V 0.20: much bigger invisible tap area around the round menu button (players never reach that corner). */
body.touch .menu-button::before {
  content: "";
  position: absolute;
  inset: -22px;
  border-radius: 50%;
}

body.touch .menu-button {
  touch-action: none;
}

@media (orientation: portrait) {
  body.touch .menu-button::before {
    inset: -28px;
  }
}

/* V 0.30: BADGES button and the daily challenge card on the phone title page; three end buttons. */
@media (max-width: 950px), (max-height: 520px) {
  body.touch:not(.in-match) #title .badges-button {
    grid-area: badges;
    position: relative;
    left: auto; top: auto;
    width: 100%;
    height: auto;
    min-height: 52px;
    font-size: 17px;
    border-radius: 6px;
  }

  body.touch:not(.in-match) #title .daily {
    grid-area: daily;
    position: relative;
    left: auto; top: auto;
    width: auto;
    padding: 10px 12px;
    border-radius: 6px;
  }

  body.touch:not(.in-match) #title .daily-head {
    font-size: 14px;
    flex-wrap: wrap;
    gap: 4px 10px;
  }

  body.touch:not(.in-match) #title .daily-text {
    font-size: 16px;
    white-space: normal;
    margin-top: 4px !important;
  }

  body.touch:not(.in-match) #title .welcome.clickable {
    text-decoration: underline dotted;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  body.touch.in-match .end-buttons {
    left: 23%;
    width: 54%;
    gap: 8px;
  }

  body.touch.in-match .end-buttons button {
    flex: 1 1 0;
    padding: 0 6px;
    font-size: 15px;
  }
}

/* V 0.30: SHARE is only a square symbol button on phones; PLAY AGAIN and BACK TO TITLE keep 48 px / 16 px
   (V 0.19 standard) and wrap between words in long languages. Held upright the buttons use almost the full width. */
@media (max-width: 950px), (max-height: 520px) {
  body.touch.in-match .end-buttons button {
    font-size: 16px;
    min-height: 48px;
    overflow-wrap: normal;
    letter-spacing: .02em;
  }

  body.touch.in-match #share-result {
    flex: 0 0 52px;
    min-width: 52px;
    padding: 0;
  }

  body.touch.in-match #share-result .share-label {
    display: none;
  }

  body.touch.in-match .share-svg {
    width: 24px;
    height: 24px;
  }
}

@media (orientation: portrait) and (max-width: 950px) {
  body.touch.in-match .end-buttons {
    left: 4%;
    width: 92%;
  }
}
