/* Final layout rules: size the game from its panel, not the device name. */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-block: 88px 24px;
}
body { min-height: 100svh; }
#main {
  width: 100%;
  max-width: 1120px;
  min-height: 100svh;
  padding: env(safe-area-inset-top, 0px) max(12px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  container: game-shell / inline-size;
}
.screen-header { top: env(safe-area-inset-top, 0px); }
.game-top {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(110px, 136px);
  height: auto;
  min-height: 62px;
  gap: 8px;
  padding: 6px 4px;
}
.game-top .round-icon { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
.top-points { justify-self: center; min-width: 0; max-width: 100%; padding: 6px 8px; }
.top-points strong { min-width: 0; overflow-wrap: anywhere; font-size: clamp(17px, 3.5vw, 23px); }
.top-points small { font-size: 12px; }
.language-controls { min-width: 0; max-width: 100%; padding: 0; margin: 0; }
.language-select { width: 136px; max-width: 100%; min-height: 44px; height: auto; font-size: 16px; }
.game-top .language-select { width: 100%; }
.play-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "stage" "controls";
  gap: 12px;
  max-width: 680px;
  margin-inline: auto;
  padding-top: 0;
  align-items: start;
}
.stage { grid-area: stage; min-width: 0; padding: 10px 12px 0; container: pyramid-panel / inline-size; }
.game-controls { grid-area: controls; min-width: 0; max-width: none; align-self: start; padding: 12px 10px 16px; }
.stage-title, .stage-title h1, .stage-title p { max-width: 100%; overflow-wrap: anywhere; }
.stage-title h1 { font-size: clamp(22px, 4vw, 28px); line-height: 1.25; }
.stage-title p { font-size: 15px; }
.automatic-hint .hint-box { font-size: 15px; line-height: 1.45; }
.pyramid[data-layers] {
  --row-count: 4;
  --cube-cap: 64px;
  --cube-gap: 6px;
  --tile: min(var(--cube-cap), calc((100vw - 88px - (var(--row-count) - 1) * var(--cube-gap)) / var(--row-count)), max(32px, calc((100svh - 530px) / var(--row-count) - 10px)));
  min-height: 0;
  width: 100%;
  margin: 0;
  padding: 18px 16px 16px;
  row-gap: 10px;
  touch-action: pan-y pinch-zoom;
}
.pyramid[data-layers="3"] { --row-count: 3; --cube-cap: 76px; }
.pyramid[data-layers="4"] { --row-count: 4; --cube-cap: 64px; }
.pyramid[data-layers="5"] { --row-count: 5; --cube-cap: 58px; }
.pyramid[data-layers="6"] { --row-count: 6; --cube-cap: 52px; }
.pyramid[data-layers="7"] { --row-count: 7; --cube-cap: 46px; }
.pyramid[data-layers="8"] { --row-count: 8; --cube-cap: 42px; }
@supports (width: 1cqw) {
  .pyramid[data-layers] {
    --tile: min(var(--cube-cap), calc((100cqw - 32px - (var(--row-count) - 1) * var(--cube-gap)) / var(--row-count)), max(32px, calc((100svh - 530px) / var(--row-count) - 10px)));
  }
}
.pyramid-row { gap: var(--cube-gap); flex-shrink: 0; align-items: center; }
.pyramid-row.editable { min-height: 44px; }
.pyramid .tile { flex: 0 0 var(--tile); }
.layer-rewards { margin: 0 auto 10px; }
.round-reward { margin-bottom: 0; font-size: 14px; }
.letter-count-note { font-size: 14px; line-height: 1.45; }
.letter-rack { --tile: 48px; padding: 10px 5px 16px; touch-action: pan-y pinch-zoom; }
.bank-row { gap: 12px 8px; }
.actions { grid-template-columns: repeat(5, minmax(0, 1fr)); width: 100%; max-width: none; gap: 5px; }
.actions .primary, .actions .secondary, .actions .erase, .actions .solution-button, .actions .pick-challenge {
  width: 100%; min-width: 0; height: auto; min-height: 76px;
  padding: 8px 3px; font-size: 13px; line-height: 1.25;
  white-space: normal; overflow-wrap: anywhere;
}
.actions .erase small, .actions #hintButton small, .actions .solution-cost { font-size: 12px; line-height: 1.25; }
.actions .solution-button { min-width: 0; }
.adventure-card { max-width: 680px; margin: 12px auto; }
.adventure-copy > .adventure-title { flex-wrap: wrap; }
.adventure-copy > .adventure-title > span { white-space: normal; overflow-wrap: anywhere; }
.adventure-goal, .adventure-copy small { font-size: 13px; }
.adventure-copy { display: flex; flex-direction: column; }
.adventure-copy progress { grid-column: auto; grid-row: auto; }
.adventure-copy small { grid-column: auto; grid-row: auto; }
/* Dialogs scroll within the available height, including with a keyboard open. */
.info-dialog, .settings-dialog, .menu-dialog, .meanings-dialog {
  box-sizing: border-box;
  width: min(480px, calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-width: none;
  max-height: calc(100vh - 24px);
  max-height: calc(var(--visible-height, 100dvh) - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  padding: 16px 20px 22px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 60px 20px;
}
.dialog-close { position: sticky; float: right; top: 0; right: auto; margin: 0 0 6px 8px; width: 44px; height: 44px; min-height: 44px; z-index: 5; }
.info-dialog h2, .settings-dialog h2, .menu-dialog h2 { padding-top: 8px; margin-right: 0; overflow-wrap: anywhere; }
.settings-card .mode-tabs { clear: both; }
.settings-dialog .select, .account-form input, .player-name { font-size: 16px; min-height: 44px; }
.settings-dialog .difficulty-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.difficulty-btn strong { font-size: 14px; }
.difficulty-btn small { font-size: 12px; line-height: 1.4; }
.setting-label, .setting-note { font-size: 14px; line-height: 1.5; }
.settings-dialog .secondary, .menu-dialog .secondary, .info-dialog .primary { min-height: 44px; white-space: normal; overflow-wrap: anywhere; }
.solved-meaning { gap: 12px; }
.solved-meaning dd { font-size: 16px; }
.welcome-screen { width: 100%; max-width: 480px; padding: 22px 20px; margin: 18px auto 0; }
.welcome-identity, .profile-heading { min-width: 0; }
.welcome-identity h1, .profile-heading > div { min-width: 0; overflow-wrap: anywhere; }
.welcome-identity h1 { font-size: clamp(26px, 5vw, 35px); }
.welcome-stats { gap: clamp(20px, 6vw, 60px); }
.welcome-points strong { font-size: clamp(40px, 12vw, 68px); overflow-wrap: anywhere; }
.played-modes > div { gap: 12px; }
.played-modes > div > span { min-width: 0; overflow-wrap: anywhere; }
.account-links { gap: 8px 12px; }
.account-links .text-button, .account-signout { min-height: 44px; font-size: 15px; padding: 8px; }
.profile-screen { max-width: 680px; margin-inline: auto; }
.profile-screen > .profile-back { font-size: 16px; }
.profile-security .secondary { white-space: normal; min-height: 44px; }
.avatar-option { overflow-wrap: anywhere; }
.stats-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-item { min-width: 0; padding: 12px 10px; overflow-wrap: anywhere; }
.stat-item span { font-size: 13px; }
.unlock-list { min-width: 0; container: unlock-panel / inline-size; }
.unlock-item { display: grid; grid-template-columns: minmax(0, 1fr); align-items: center; gap: 10px 16px; }
.unlock-item > div { min-width: 0; overflow-wrap: break-word; word-break: normal; }
.unlock-item strong, .unlock-item small { word-break: normal; overflow-wrap: break-word; }
.unlock-item .secondary { width: auto; max-width: 100%; min-width: 0; margin: 0; justify-self: start; white-space: normal; }
.unlock-open { justify-self: start; }
@container unlock-panel (min-width: 360px) {
  .unlock-item { grid-template-columns: minmax(0, 1fr) auto; }
  .unlock-item .secondary, .unlock-open { justify-self: end; }
}
.section-card, .intro { overflow-wrap: anywhere; }
.intro { flex-wrap: wrap; }
/* Split view only when both panels have enough usable room. */
@container game-shell (min-width: 800px) {
  .play-screen { max-width: none; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); grid-template-areas: "stage controls"; gap: 24px; align-items: center; }
  .game-controls { align-self: center; }
  .adventure-card { max-width: 680px; }
  .pyramid[data-layers] { --tile: min(var(--cube-cap), calc((100cqw - 32px - (var(--row-count) - 1) * var(--cube-gap)) / var(--row-count)), max(32px, calc((100svh - 300px) / var(--row-count) - 10px))); }
}
@media (min-width: 600px) {
  #main { padding-inline: max(24px, env(safe-area-inset-left, 0px)) max(24px, env(safe-area-inset-right, 0px)); }
  .actions { gap: 8px; }
  .actions .primary, .actions .secondary, .actions .erase, .actions .solution-button, .actions .pick-challenge { font-size: 14px; padding-inline: 5px; }
}
@media (max-width: 360px) {
  .stage { padding-inline: 8px; }
  .game-controls { padding-inline: 6px; }
  .actions { gap: 4px; }
  .actions .primary, .actions .secondary, .actions .erase, .actions .solution-button, .actions .pick-challenge { min-height: 88px; font-size: 12px; }
  .settings-dialog .difficulty-list { grid-template-columns: minmax(0, 1fr); }
  .difficulty-btn { display: flex; text-align: left; padding: 10px; }
  .welcome-screen, .profile-screen { padding-inline: 14px; }
  .profile-heading { flex-wrap: wrap; }
  .avatar-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-height: 500px) {
  .screen-header { position: relative; top: auto; }
  .adventure-card { min-height: 68px; }
  .intro-name { top: 28%; }
  .intro-skip { bottom: max(12px, env(safe-area-inset-bottom, 0px)); }
}

/* One compact entry per played layer count, regardless of round history length. */
.layer-progress-list{display:grid;gap:0}.layer-progress-row{display:flex;align-items:center;justify-content:space-between;gap:12px;padding:12px 0;border-bottom:1px solid rgba(36,48,75,.12)}.layer-progress-row:last-child{border-bottom:0}.layer-progress-row span{font-size:1rem;color:#24304b}.progress-unlocks{margin-top:14px}.progress-unlocks>summary{cursor:pointer;font-weight:700}.progress-unlocks:not([open]){padding-block:16px}
