/* Phone layout, shared by every page. Applies to small screens in any browser; html.app is set inside the
   Android/iOS app and in phone browsers (see mobile_head.html); it turns on the app layout. */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior-y: none; }
html.app body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  -webkit-user-select: none; user-select: none; }
html.app *, html.app *::before, html.app *::after { box-sizing: border-box; }
html.app input, html.app textarea, html.app code { -webkit-user-select: text; user-select: text; }
html.app a, html.app button { touch-action: manipulation; }

@media (max-width: 700px) {
  /* navigation: one swipeable row of windows instead of a wrapped pile */
  .nav { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px 4px 8px; gap: 6px; font-size: 12px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav > * { flex: 0 0 auto; }
  .nav .spacer { display: none; }
  .nav a, .nav .nav_text, .nav button.navbtn, .nav form button { padding: 10px 10px; font-size: 12px; border-width: 3px; min-height: 44px; }
  .nav .nav_text { max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  body.rpg { padding: 6px; font-size: 14px; }
  .rpg h1 { font-size: 18px; }
  .rpg h2 { font-size: 14px; }
  .rpg label, .rpg .auth_links { font-size: 12px; }
  .rpg_box, .rpg .box { padding: 10px 10px; margin: 10px 0; border-width: 3px; }
  .rpg .auth_box { margin: 10px 0; }

  /* 16px inputs stop iOS from zooming the page on focus; tall controls are easy to tap */
  .rpg input[type=text], .rpg input[type=number], .rpg input[type=email], .rpg input[type=password],
  .rpg select, .rpg textarea { font-size: 16px; min-height: 44px; }
  .rpg button, .rpg .button, .rpg input[type=submit] { min-height: 44px; font-size: 13px; }
  .rpg td input[type=text], .rpg td select, .rpg td input[type=number] { min-width: 0; width: 100%; }
  .rpg table { display: block; overflow-x: auto; }
  .rpg table.arenatable { overflow: visible; }

  /* drink page */
  #selection_area { flex-direction: column; }
  #drink_sizes, #drink_weights { align-items: stretch; }
  .drink_size, .drink_weight { min-width: 0; width: 100%; height: auto; min-height: 70px; }
  #player_box { padding: 12px; max-height: none; }
  #submit_area { height: auto; min-height: 80px; }

  /* stats page: players stack instead of scrolling sideways */
  #players { flex-flow: column; }
  .player { min-width: 0; width: 100%; }

  /* arena page: keep the stage above the log, sprites scale down */
  #arena { flex-wrap: nowrap; }
  #events { font-size: 11px; }
}

@media (max-width: 700px) and (orientation: portrait) {
  .rpg .controls .actions { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Inside the app: every live page is one fixed screen (no vertical scrolling) ===== */
html.app { --navh: 66px; --safe-t: env(safe-area-inset-top); --safe-b: env(safe-area-inset-bottom); overscroll-behavior: none; }
@media (orientation: landscape) {
  html.app { --navh: 48px; }
  html.app .nav { padding-top: 4px; padding-bottom: calc(4px + var(--safe-b)); }
  html.app .nav a, html.app .nav .nav_text, html.app .nav button.navbtn, html.app .nav form button { min-height: 34px; padding: 4px 10px; }
}
/* the usable height between the status bar and the navigation bar */
html.app { --stage: calc(100dvh - var(--safe-t) - var(--safe-b) - var(--navh) - 12px); }

/* navigation sits at the bottom where a thumb reaches it; swipe it sideways if it is wider than the screen */
html.app .nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; margin: 0; background: #000000;
  border-top: 3px solid #ffffff; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 6px; font-size: 12px;
  padding: 6px calc(6px + env(safe-area-inset-right)) calc(6px + var(--safe-b)) calc(6px + env(safe-area-inset-left)); }
html.app .nav::-webkit-scrollbar { display: none; }
html.app .nav > * { flex: 0 0 auto; }
html.app .nav .spacer { display: none; }
html.app .nav a, html.app .nav .nav_text, html.app .nav button.navbtn, html.app .nav form button {
  padding: 8px 10px; font-size: 12px; border-width: 3px; min-height: 40px; box-shadow: 2px 2px 2px #000000; }
html.app .nav .nav_text { max-width: 70vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
html.app body { margin: 0; padding-bottom: calc(var(--navh) + var(--safe-b) + 12px); }

/* ---- drink page: pick a size and a strength, tap Submit ---- */
html.app body:has(#selection_area) #header { display: none; }
html.app #selection_area { display: grid; gap: 8px; height: var(--stage); min-height: 0;
  grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) minmax(0, 2fr) auto; width: 100%;
  grid-template-areas: "player" "sizes" "weights" "submit"; }
html.app #player_area { display: contents; }
html.app #player_box { grid-area: player; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 0;
  padding: 6px 10px; max-height: none; text-align: left; min-height: 56px; font-size: 14px; }
html.app #player_icon img, html.app #player_icon .icon_fallback { height: 40px; width: auto; max-height: 40px; }
html.app #player_icon .icon_fallback { width: 40px; line-height: 40px; font-size: 22px; }
html.app #player_select { width: 100%; min-height: 44px; font-size: 16px; }
html.app #drink_sizes { grid-area: sizes; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
html.app #drink_weights { grid-area: weights; display: grid; grid-template-rows: repeat(5, minmax(0, 1fr)); gap: 6px; }
html.app #submit_area { grid-area: submit; height: auto; min-height: 60px; align-items: stretch; }
html.app #submit_button { width: 100%; margin: 0; text-align: center; padding: 14px 0; font-size: 20px; background-color: #00a060; }
html.app .drink_size, html.app .drink_weight { min-width: 0; height: auto; margin: 0; padding: 4px; display: flex;
  align-items: center; justify-content: center; overflow: hidden; }
html.app .drink_size { flex-direction: column; gap: 4px; font-size: 11px; }
html.app .drink_weight { flex-direction: row; gap: 12px; justify-content: flex-start; padding-left: 14px; font-size: 13px; text-align: left; }
html.app .drink_size p, html.app .drink_weight p { margin: 0; }
html.app .size_icon, html.app .weight_icon { height: auto; max-height: 70%; max-width: 40%; width: auto; object-fit: contain; }
html.app .drink_size .size_icon { max-width: 80%; max-height: 55%; }
@media (orientation: landscape) {
  html.app #selection_area { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "player sizes weights" "submit sizes weights"; }
  html.app #drink_sizes { grid-template-columns: minmax(0, 1fr); grid-template-rows: repeat(5, minmax(0, 1fr)); }
  html.app .drink_size { flex-direction: row; gap: 12px; font-size: 13px; }
  html.app .drink_size .size_icon, html.app .weight_icon { height: min(36px, 7.5vh); width: auto; max-height: none; max-width: 30%; }
  html.app #player_box { flex-direction: column; justify-content: center; text-align: center; }
}

/* ---- stats page: one swipeable card per player ---- */
html.app #players { display: flex; flex-flow: row; gap: 10px; height: calc(var(--stage) - 52px); overflow-x: auto; overflow-y: hidden;
  scroll-snap-type: x mandatory; scrollbar-width: none; }
html.app #players::-webkit-scrollbar { display: none; }
html.app #players .player { flex: 0 0 100%; min-width: 0; scroll-snap-align: center; overflow-y: auto; scrollbar-width: none;
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-content: start; font-size: 10px; line-height: 1.6;
  grid-template-areas: "head head" "record stats" "equipped stats" "damage stats"; }
html.app #players .header { grid-area: head; height: auto; display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 14px; }
html.app #players .header p { margin: 0; }
html.app #players .header img { max-height: 36px; }
html.app #players .record { grid-area: record; }
html.app #players .stats { grid-area: stats; }
html.app #players .equipped { grid-area: equipped; }
html.app #players .damage { grid-area: damage; }
html.app #players .rpg_box { margin: 0; padding: 6px; display: grid; grid-template-columns: 1fr auto; column-gap: 6px; align-content: start; border-width: 3px; }
html.app #players .stat_name { overflow-wrap: break-word; }
html.app #players .equipped { grid-template-columns: 1fr; }
html.app #players .equipped .stat_value { text-align: left; color: var(--accent, #ffd34d); margin-bottom: 4px; }
@media (orientation: landscape) {
  html.app #players .player { flex-basis: 100%; grid-template-columns: 1.2fr 1fr 1fr;
    grid-template-areas: "head record equipped" "stats stats damage"; }
}

/* ---- arena (battle) page: the two teams side by side, the log above the navigation bar ---- */
html.app body:has(#arena) #header { display: flex; height: 36px; align-items: center; }
html.app #battle_id { font-size: 11px; margin: 0; }
html.app #arena { position: relative; display: flex; gap: 8px; align-items: stretch; width: 100%;
  height: calc(var(--stage) - 36px - 76px); }
html.app #partyA, html.app #partyB { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 6px; justify-content: center; }
html.app #arena .player { box-sizing: border-box; width: 100%; flex: 1 1 0; min-width: 0; min-height: 0; margin: 0; padding: 4px; overflow: hidden; font-size: 10px; max-height: 110px; justify-content: center; }
html.app #arena .stats { font-size: 10px; line-height: 1.5; }
html.app #arena .player_name { line-height: 1.5; margin-bottom: 2px; }
html.app #arena .player_name { font-size: 11px; overflow-wrap: anywhere; }
html.app #arena .player img { max-height: 34px; }
html.app #arena .team_name { font-size: 11px; margin-bottom: 2px; }
html.app #battlefield { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 44%; pointer-events: none; z-index: 5; }
html.app #spell { max-width: 100%; height: auto; }
html.app #events { position: fixed; left: calc(6px + env(safe-area-inset-left)); right: calc(6px + env(safe-area-inset-right));
  bottom: calc(var(--navh) + var(--safe-b) + 8px); z-index: 40; max-height: 64px; overflow: hidden; font-size: 11px; line-height: 1.5; padding: 4px 8px; }
html.app #events p { margin: 0; }
@media (orientation: landscape) { html.app #arena { height: calc(var(--stage) - 36px - 50px); } html.app #events { max-height: 44px; }
  html.app #arena .player { padding: 1px 4px; } html.app #arena .player img { max-height: 24px; } }
/* an enemy: its picture is an emoji, so size it to the box (it would otherwise be far bigger than the sprites around it) */
html.app #arena .player.enemy { max-height: 140px; }
html.app #arena .enemy_sprite { font-size: 44px; padding: 0 4px 0 0; }
html.app #arena .player.enemy .stats_img_wrapper { grid-template-columns: auto minmax(0, 1fr); align-items: center; }
html.app #arena .player.enemy .stats_img_wrapper > * { min-width: 0; }
html.app #arena .player.enemy .player_name { font-size: 10px; }
html.app #arena .enemy_level { display: block; font-size: 9px; }
html.app #arena .player.enemy .stats { align-self: end; }
html.app #arena .player.enemy .action_text { min-height: 1.2em; font-size: 10px; }
@media (orientation: landscape) {
  html.app #arena .player.enemy { max-height: 90px; }
  html.app #arena .enemy_sprite { font-size: 30px; padding: 0 3px 0 0; }
  html.app #arena .enemy_level { display: inline; }
}

/* ---- the other pages: tighter, but they hold forms and lists so they may still scroll ---- */
html.app body.rpg { padding-top: calc(6px + var(--safe-t)); }
html.app .rpg main { padding-bottom: 8px; }
html.app .rpg h1 { margin: 4px 0 6px; }

/* collapsible sections (open on the web, folded in the app) */
details.fold > summary { cursor: pointer; list-style: none; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary > h2 { display: inline; }
details.fold > summary::before { content: '\25B8 '; color: var(--accent, #ffd34d); }
details.fold[open] > summary::before { content: '\25BE '; }
details.fold > summary.muted { display: block; margin: 4px 0; }
html.app details.fold { margin: 2px 0; }
html.app .rpg .rowactions { white-space: normal; line-height: 2.8; }
html.app .rpg .rowactions a.button { margin: 0 6px 0 0; }

/* ---- sub-pages (js/mobile.js) ---- */
html.app .v-off { display: none !important; }
html.app .viewmenu { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 10px 0; }
html.app .viewmenu button { margin: 0; min-height: 52px; background-color: var(--blue); }
html.app .viewmenu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
html.app .backbar { display: block; width: 100%; margin: 0 0 8px; min-height: 44px; text-align: left; font-size: 13px;
  background-color: #3a4a98; color: #fff; border: 4px ridge #fff; border-radius: 10px; font-family: nesFont, monospace; text-shadow: 2px 2px #000; }
html.app .rpg .backbar { margin-top: 0; }
/* the stats roster: one button per player */
html.app .roster { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-content: start;
  height: var(--stage); overflow-y: auto; scrollbar-width: none; }
html.app .rosterbtn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; margin: 0; padding: 6px;
  min-height: 80px; color: #fff; font-family: nesFont, monospace; font-size: 12px; cursor: pointer; text-shadow: 2px 2px #000; }
html.app .rosterbtn img { max-height: 40px; }
html.app .rosterbtn .rrec { font-size: 10px; color: var(--muted, #b8c8ff); }
html.app #players.single .player:not(.sel) { display: none; }
@media (orientation: landscape) {
  html.app .roster { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  html.app .rosterbtn { flex-direction: row; gap: 10px; min-height: 64px; }
}

@media (orientation: landscape) {
  html.app .backbar { min-height: 34px; margin-bottom: 4px; padding: 2px 10px; }
  html.app #players { height: calc(var(--stage) - 38px); }
  html.app #players .player { line-height: 1.45; gap: 4px; }
  html.app .viewmenu { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 6px; margin: 6px 0; }
  html.app .viewmenu button { min-height: 40px; font-size: 11px; padding: 4px 6px; line-height: 1.3; }
}

/* ---- home: arenas as cards at any width (the table is for desktops) ---- */
html.app .rpg table.arenatable, html.app .rpg table.arenatable tbody, html.app .rpg table.arenatable tr,
html.app .rpg table.arenatable td { display: block; width: 100%; }
html.app .rpg table.arenatable tr:first-child { display: none; }
html.app .rpg table.arenatable tr { border-top: 2px dotted rgba(255, 255, 255, .4); padding: 4px 0; }
html.app .rpg table.arenatable td { border: 0; padding: 2px 8px; }
html.app .rpg table.arenatable td:nth-child(2)::before { content: 'Role: '; color: var(--muted); }
html.app .rpg table.arenatable td:nth-child(3)::before { content: 'Members: '; color: var(--muted); }
html.app .rpg table.arenatable td:nth-child(2), html.app .rpg table.arenatable td:nth-child(3) { display: inline-block; width: auto; font-size: 12px; }
html.app .rpg .rowactions { white-space: normal; line-height: 2.6; text-align: left; }
html.app .rpg h1 { font-size: 16px; }

/* the congratulations screen leaves the navigation bar free */
html.app #victory { bottom: calc(var(--navh) + var(--safe-b)); }
