/* One viewport, with intentional inner scrolling only for the library and dialogs. */
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}
#app {
  height: 100%;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}
#app > .shell,
#app .online-game-panel > .shell {
  height: 100%;
  max-width: none;
  margin: 0;
  min-height: 0;
  padding: env(safe-area-inset-top, 0px)
    max(12px, env(safe-area-inset-right, 0px)) env(safe-area-inset-bottom, 0px)
    max(12px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#app .site-header {
  height: 50px;
  min-height: 50px;
  flex-shrink: 0;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}
#app .site-header .brand {
  font-size: 23px;
  margin-right: auto;
}
#app .site-header .brand-mark {
  width: 29px;
  height: 29px;
  font-size: 27px;
  margin-right: 7px;
  border-radius: 9px;
}
#app .site-header .text-button {
  font-size: 11px;
  padding: 8px;
  min-height: 40px;
  white-space: nowrap;
}
#app > .app-lobby {
  padding-inline: 0;
}
#app .app-lobby .site-header {
  padding-inline: max(18px, env(safe-area-inset-left, 0px));
  min-height: 64px;
  height: 64px;
  max-width: 1100px;
  width: 100%;
  margin: auto;
}
#app .app-lobby .lobby {
  width: 100%;
  max-width: 1100px;
  min-height: 0;
  flex: 1;
  overflow: auto;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-width: thin;
  padding: 18px max(18px, env(safe-area-inset-right, 0px)) 26px
    max(18px, env(safe-area-inset-left, 0px));
  -webkit-overflow-scrolling: touch;
}
html[data-screen="game"] #app {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#app .game-main,
#app .arcade-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 8px 0 10px;
  display: grid;
  gap: 8px;
  grid-template-rows: 28px 44px 36px minmax(0, 1fr);
}
#app .arcade-main {
  grid-template-rows: 28px 44px 34px minmax(0, 1fr) auto;
}
#app .game-title-row {
  margin: 0;
  gap: 8px;
  min-height: 0;
  align-items: center;
}
#app .game-title-row h1 {
  font-size: 23px;
  letter-spacing: -0.7px;
  margin: 0;
  line-height: 1.1;
}
#app .game-title-row .eyebrow,
#app .round-tag span {
  display: none;
}
#app .round-tag {
  font-size: 9px;
}
#app .scoreboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}
#app .scoreboard:has(> .score-tile:nth-child(2):last-child) {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
#app .scoreboard:has(> .score-tile:nth-child(3):last-child) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
#app .score-tile {
  padding: 7px 9px;
  gap: 8px;
  min-width: 0;
  border-radius: 10px;
}
#app .score-tile strong {
  font-size: 10px;
  white-space: nowrap;
}
#app .score-value {
  font-size: 17px;
  letter-spacing: -0.5px;
  white-space: nowrap;
}
#app .colour-name {
  display: none;
}
#app .colour-dot {
  width: 9px;
  height: 9px;
  flex-shrink: 0;
}
#app .arena-toolbar,
#app .arcade-toolbar {
  margin: 0;
  min-height: 0;
  gap: 8px;
  align-items: center;
  display: flex;
  justify-content: space-between;
}
#app .arena-status,
#app .arcade-status {
  font-size: 10px;
  line-height: 1.35;
  min-width: 0;
}
#app .timer {
  min-width: 76px;
  padding: 5px 8px;
}
#app .timer > b {
  font-size: 21px;
}
#app .arena,
#app .arcade-stage {
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  margin: 0;
  aspect-ratio: auto;
  border-radius: 12px;
  box-shadow: none;
  align-self: stretch;
  overflow: hidden;
}
#app .arcade-stage {
  background: #ede8f2;
}
#app .arena canvas {
  width: 100%;
  height: 100%;
}
#app .arcade-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
#app .arcade-controls {
  margin: 0;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  min-height: 0;
}
#app .arcade-controls[data-players="1"] {
  grid-template-columns: 1fr;
}
#app .arcade-controls[data-pass-play="true"] {
  display: none;
}
#app .control-panel {
  padding: 8px 10px;
  border-radius: 10px;
  min-width: 0;
}
#app .control-panel > strong {
  font-size: 10px;
  line-height: 1.1;
}
#app .action-buttons {
  margin-top: 6px;
  gap: 6px;
}
#app .action-buttons button {
  min-height: 44px;
  font-size: 11px;
}
#app .colour-buttons {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
#app .colour-buttons button {
  font-size: 9px;
}
#app .arena-overlay,
#app .arcade-overlay {
  align-items: safe center;
  justify-content: center;
  padding: 14px;
  overscroll-behavior: contain;
  touch-action: pan-y;
  overflow: auto;
}
#app .overlay-card,
#app .arcade-overlay-card {
  width: min(100%, 540px);
  min-width: 0;
  max-height: none;
  padding: 8px 12px;
  margin: auto;
  flex-shrink: 0;
}
#app .overlay-card h2,
#app .arcade-overlay-card h2 {
  font-size: 27px;
}
#app .overlay-card p,
#app .arcade-overlay-card p {
  font-size: 12px;
  line-height: 1.65;
}
#app .overlay-card .overlay-icon,
#app .arcade-overlay-card .overlay-icon {
  font-size: 33px;
}
#app .colour-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
#app .card-surface {
  height: 100%;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#app .memory-grid {
  height: 100%;
  width: 100%;
  max-width: 680px;
  margin: 0;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
#app .memory-card {
  min-height: 0;
  font-size: clamp(18px, 4dvh, 32px);
  box-shadow: none;
  touch-action: none;
}
@media (min-width: 900px) {
  #app > .game-shell,
  #app .online-game-panel > .game-shell,
  #app > .arcade-shell,
  #app .online-game-panel > .arcade-shell {
    padding-inline: max(24px, env(safe-area-inset-right, 0px));
  }
  #app .arcade-controls {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  #app .arcade-controls[data-players="2"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #app .arcade-controls[data-players="3"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 460px) {
  #app .site-header .brand {
    font-size: 20px;
  }
  #app .site-header .text-button {
    font-size: 10px;
    padding: 7px 5px;
  }
  #app .score-tile {
    padding: 7px 6px;
    gap: 5px;
  }
  #app .score-value {
    font-size: 14px;
  }
  #app .score-tile strong {
    font-size: 9px;
  }
  #app .scoreboard:has(> .score-tile:nth-child(4)) .colour-dot {
    display: none;
  }
  #app .scoreboard:has(> .score-tile:nth-child(4)) .score-tile {
    flex-wrap: wrap;
    gap: 2px;
    align-content: center;
  }
  #app .scoreboard:has(> .score-tile:nth-child(4)) .score-value {
    font-size: 13px;
  }
  #app .game-title-row h1 {
    font-size: 22px;
  }
  #app .arcade-status {
    font-size: 9px;
  }
}
@media (orientation: landscape) and (max-height: 600px) {
  #app .site-header {
    height: 40px;
    min-height: 40px;
  }
  #app .site-header .brand {
    font-size: 18px;
  }
  #app .site-header .brand-mark {
    width: 24px;
    height: 24px;
    font-size: 23px;
  }
  #app .arcade-main {
    grid-template-columns: minmax(0, 1fr) 180px;
    grid-template-rows: 36px 28px minmax(0, 1fr);
    gap: 6px;
    padding: 6px 0;
  }
  #app .arcade-main .game-title-row {
    display: none;
  }
  #app .arcade-main .scoreboard {
    grid-column: 1;
    grid-row: 1;
  }
  #app .arcade-toolbar {
    grid-column: 1;
    grid-row: 2;
  }
  #app .arcade-stage {
    grid-column: 1;
    grid-row: 3;
  }
  #app .arcade-controls {
    grid-column: 2;
    grid-row: 1 / span 3;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  #app .control-panel {
    flex: 1;
    padding: 5px 7px;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }
  #app .action-buttons {
    margin-top: 4px;
  }
  #app .action-buttons button {
    min-height: 36px;
  }
  #app .colour-buttons {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #app .colour-buttons button {
    min-height: 28px;
  }
  #app .arcade-main:has(.arcade-controls[data-pass-play="true"]) {
    grid-template-columns: minmax(0, 1fr);
  }
  #app .game-main {
    grid-template-rows: 32px 28px minmax(0, 1fr);
    padding: 6px 0;
    gap: 5px;
  }
  #app .game-main .game-title-row {
    display: none;
  }
  #app .overlay-card h2,
  #app .arcade-overlay-card h2 {
    font-size: 23px;
  }
  #app .overlay-card p,
  #app .arcade-overlay-card p {
    font-size: 11px;
  }
  #app .overlay-icon {
    display: none;
  }
}
.learning-level {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin: 16px 0;
}
.learning-level label {
  font-size: 13px;
  font-weight: 750;
}
.learning-level select {
  padding: 10px 16px;
  background: #fffdf8;
  border: 1px solid #d5c8e4;
  border-radius: 10px;
  font-size: 14px;
  min-height: 44px;
}

/* Keep Home in the same safe-area corner on every playable screen. */
#app .shell .site-header button.game-home {
  position: fixed;
  inset: calc(env(safe-area-inset-top, 0px) + 8px) auto auto
    calc(env(safe-area-inset-left, 0px) + 12px);
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0;
  border: 1px solid #9187a8;
  border-radius: 50%;
  background: #211a35;
  color: #fff9ee;
  font: 28px/1 Georgia, serif;
  pointer-events: auto;
}
#app .shell .site-header button.game-home::before { content: none; }
