:root {
  --rushmo-content-max: 620px;
  --rushmo-edge-space: clamp(8px, 3vw, 22px);
  --rushmo-modal-space: clamp(10px, 4vw, 20px);
}

html,
body {
  min-width: 0;
  max-width: 100%;
}

body {
  overflow-wrap: break-word;
}

button,
.action-link,
input[type='checkbox'],
input[type='radio'] {
  touch-action: manipulation;
}

header {
  padding-top: max(10px, env(safe-area-inset-top));
  padding-right: max(clamp(16px, 5vw, 72px), env(safe-area-inset-right));
  padding-bottom: 10px;
  padding-left: max(clamp(16px, 5vw, 72px), env(safe-area-inset-left));
}

.brand,
.header-actions,
nav,
main,
main > section,
.top > *,
.preference-row > * {
  min-width: 0;
}

main {
  width: min(
    var(--rushmo-content-max),
    calc(100% - max(var(--rushmo-edge-space), env(safe-area-inset-left)) - max(var(--rushmo-edge-space), env(safe-area-inset-right)))
  );
  padding-top: clamp(36px, 7vh, 64px);
  padding-bottom: max(clamp(32px, 6vh, 56px), env(safe-area-inset-bottom));
}

h1 {
  max-width: 100%;
  margin-block: clamp(14px, 3vh, 24px) clamp(28px, 5vh, 42px);
  font-size: clamp(2.7rem, 11vw, 5.4rem);
  overflow-wrap: anywhere;
}

h2 {
  max-width: 100%;
  font-size: clamp(2rem, 8vw, 2.7rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

form,
.result {
  max-width: 100%;
  padding: clamp(16px, 4vw, 24px);
}

#home-name,
#profile-pseudo,
.profile-heading strong,
.previous-word,
.history-word {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.top {
  align-items: flex-start;
  gap: clamp(12px, 4vw, 28px);
}

.top > div {
  flex: 1 1 auto;
}

.top p {
  margin-block: .5rem 0;
}

#timer {
  flex: 0 0 auto;
  min-width: 5ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#play {
  --rushmo-cell-size: clamp(42px, min(14vw, 7.4dvh), 54px);
  --rushmo-grid-gap: clamp(4px, .9vw, 7px);
  max-width: 100%;
}

.grid {
  gap: var(--rushmo-grid-gap);
  max-width: 100%;
  margin: clamp(16px, 4vh, 36px) 0 clamp(8px, 2vh, 14px);
}

.row {
  grid-template-columns: repeat(5, var(--rushmo-cell-size));
  gap: var(--rushmo-grid-gap);
  max-width: 100%;
}

.cell {
  width: var(--rushmo-cell-size);
  height: auto;
  aspect-ratio: 1;
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
}

#error {
  min-height: 20px;
  height: auto;
  margin-block: 4px;
}

#keys {
  max-width: 100%;
  margin-top: clamp(8px, 2vh, 18px);
  padding-bottom: 10px;
}

.site-footer {
  padding-right: max(clamp(16px, 5vw, 72px), env(safe-area-inset-right));
  padding-left: max(clamp(16px, 5vw, 72px), env(safe-area-inset-left));
}

.keys {
  width: 100%;
  gap: clamp(3px, 1vw, 6px);
  margin: clamp(3px, .8vh, 6px) 0;
}

.key {
  min-height: 42px;
  height: clamp(42px, min(11vw, 7dvh), 52px);
  font-size: clamp(.75rem, 3.2vw, .95rem);
}

.key-action {
  font-size: clamp(.75rem, 3vw, .9rem);
}

.stats-grid,
.profile-grid,
.history-card,
.preferences-card,
.table-wrap,
table,
pre {
  max-width: 100%;
}

pre {
  overflow-wrap: anywhere;
}

.preference-row {
  flex-wrap: wrap;
}

.preference-row > div:first-child {
  flex: 1 1 220px;
}

.keyboard-layout-preference {
  display: grid;
  justify-content: stretch;
  gap: 8px;
  min-inline-size: 0;
  margin: 0;
  padding: 14px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.keyboard-layout-preference legend {
  width: 100%;
  padding: 0;
  font-weight: 700;
}

.keyboard-layout-preference > small {
  margin-top: -4px;
}

.preference-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 2px;
}

.preference-option {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #11161b;
  cursor: pointer;
}

.preference-option input {
  appearance: auto;
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 0;
  padding: 0;
  accent-color: var(--lime);
}

.preference-option span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.update-notes-backdrop,
.roadmap-backdrop,
.help-backdrop,
.migration-backdrop,
.profile-action-dialog-backdrop {
  padding-top: max(var(--rushmo-modal-space), env(safe-area-inset-top));
  padding-right: max(var(--rushmo-modal-space), env(safe-area-inset-right));
  padding-bottom: max(var(--rushmo-modal-space), env(safe-area-inset-bottom));
  padding-left: max(var(--rushmo-modal-space), env(safe-area-inset-left));
}

.migration-dialog,
.profile-action-dialog,
.help-dialog,
.update-notes,
.roadmap {
  max-width: 100%;
  max-height: 100%;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.dialog-actions button,
.help-tabs button,
.help-confirm,
.update-notes-confirm,
.update-notes-roadmap,
.roadmap > button:last-child {
  min-height: 44px;
}

@media (max-width: 650px) {
  header {
    gap: 8px;
  }

  .header-actions {
    min-width: 0;
    flex-wrap: wrap;
  }

  nav {
    min-width: 0;
  }

  nav button {
    padding-inline: clamp(2px, 1.4vw, 6px);
    font-size: clamp(.72rem, 3vw, .78rem);
  }

  main {
    padding-top: clamp(28px, 5vh, 42px);
  }
}

@media (max-width: 450px) {
  .migration-dialog,
  .profile-action-dialog,
  .help-dialog,
  .update-notes,
  .roadmap {
    padding: clamp(18px, 6vw, 25px);
  }

  .dialog-actions {
    margin-top: 16px;
  }
}

@media (max-width: 360px) {
  nav {
    gap: 2px;
  }

  .preference-options {
    grid-template-columns: 1fr;
  }

  .top {
    gap: 8px;
  }

  .top p {
    font-size: .8rem;
  }
}

@media (max-width: 900px) and (max-height: 760px) {
  main {
    padding-top: clamp(18px, 4vh, 30px);
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  #play {
    --rushmo-cell-size: clamp(40px, min(13vw, 7dvh), 48px);
    --rushmo-grid-gap: clamp(3px, .75vw, 5px);
  }

  .grid {
    margin-block: 14px 6px;
  }

  #keys {
    margin-top: 7px;
  }

  .keys {
    margin-block: 3px;
  }

  .key {
    height: clamp(40px, min(10vw, 7dvh), 46px);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  header {
    min-height: 58px;
    padding-top: max(6px, env(safe-area-inset-top));
    padding-bottom: 6px;
  }

  main {
    padding-top: 12px;
  }

  #play {
    --rushmo-cell-size: clamp(38px, min(11vw, 10dvh), 44px);
    --rushmo-grid-gap: 3px;
  }

  .grid {
    margin-block: 10px 4px;
  }

  .key {
    min-height: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .preference-option,
  .key {
    scroll-behavior: auto;
  }
}
/* Competition v0.5: reuse the existing compact shell and keyboard geometry. */
[hidden] { display: none !important; }
.music-invite-dialog h2 { font-size: clamp(1.35rem, 5.5vw, 1.8rem); }
.board-switch, .training-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.training-actions {
  justify-content: center;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.training-actions .text-button {
  min-height: 44px;
  max-width: 100%;
  white-space: normal;
}
.board-switch { margin-bottom: 1rem; }
.board-switch button { flex: 1; }
.board-switch [aria-pressed="true"] { border-color: var(--accent, #dfff53); color: var(--accent, #dfff53); }
.result-summary { text-align: left; border-left: 2px solid #dfff53; padding-left: .9rem; margin: 1rem 0; }
.result-summary p { margin: .5rem 0; line-height: 1.5; overflow-wrap: anywhere; }
#weekly-description { font-size: .9rem; line-height: 1.5; }
#weekly-description p { overflow-wrap: anywhere; }
.weekly-rules summary { cursor: pointer; min-height: 44px; align-content: center; }
#win .result { gap: .55rem; padding: 1.1rem; line-height: 1.45; margin-block: 20px; }
#daily-result-rank strong { display: inline; font-size: inherit; }
#win-training { margin: .6rem 0; }
#game-mode-label { margin-bottom: .6rem; }
[hidden].training-actions { display: none; }
