:root {
  color-scheme: light;
  --ink: #18201d;
  --muted: #64706b;
  --line: #d8ded4;
  --paper: #f5f2e9;
  --panel: #fffdf7;
  --steel: #2f4b4f;
  --steel-dark: #1f3438;
  --mint: #4da58a;
  --amber: #d89a2b;
  --red: #c74b3f;
  --blue: #49789c;
  --shadow: 0 18px 48px rgba(42, 52, 44, 0.16);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background:
    linear-gradient(90deg, rgba(47, 75, 79, 0.06) 1px, transparent 1px),
    linear-gradient(0deg, rgba(47, 75, 79, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 14px 14px calc(70px + env(safe-area-inset-bottom));
}

.topbar {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin: 0 auto 14px;
  max-width: 1120px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  align-items: center;
  background: var(--steel);
  border: 2px solid var(--steel-dark);
  color: #f8f3df;
  display: inline-flex;
  font-size: 13px;
  font-weight: 900;
  height: 40px;
  justify-content: center;
  letter-spacing: 0;
  width: 40px;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.1;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.profile-chip input {
  background: rgba(255, 253, 247, 0.86);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  max-width: 136px;
  min-height: 38px;
  outline: none;
  padding: 8px 10px;
}

.profile-chip input:focus {
  border-color: var(--steel);
  box-shadow: 0 0 0 3px rgba(77, 165, 138, 0.18);
}

.content-shell {
  margin: 0 auto;
  max-width: 1120px;
}

.bottom-nav {
  background: rgba(31, 52, 56, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  bottom: 0;
  box-shadow: 0 12px 32px rgba(24, 32, 29, 0.28);
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(4, 1fr);
  left: 12px;
  margin: 0 auto;
  max-width: 520px;
  padding: 6px;
  position: fixed;
  right: 12px;
  z-index: 30;
}

.bottom-nav a {
  border-radius: 6px;
  color: rgba(255, 253, 247, 0.72);
  font-size: 14px;
  font-weight: 800;
  padding: 10px 8px;
  text-align: center;
}

.bottom-nav a.active {
  background: #f7f1db;
  color: var(--steel-dark);
}

.game-layout,
.editor-layout,
.list-view,
.locked-view,
.loading-view,
.empty-state {
  animation: lift 180ms ease-out;
}

@keyframes lift {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.game-layout {
  display: grid;
  gap: 8px;
  overscroll-behavior: contain;
  touch-action: none;
}

.game-head,
.section-title {
  align-items: end;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.game-head {
  align-items: center;
}

.level-title {
  min-width: 0;
}

.game-head h1,
.section-title h1,
.locked-view h1,
.loading-view h1,
.empty-state h1 {
  font-size: clamp(25px, 4vw, 42px);
  line-height: 1.02;
  margin: 4px 0 8px;
}

.game-head h1 {
  margin-bottom: 0;
}

.game-actions {
  justify-content: flex-end;
}

.icon-button {
  align-items: center;
  background: rgba(255, 253, 247, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--steel-dark);
  cursor: pointer;
  display: inline-flex;
  height: 40px;
  justify-content: center;
  padding: 0;
  width: 40px;
}

.ui-icon {
  display: inline-block;
  position: relative;
}

.ui-icon-restart {
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  height: 18px;
  width: 18px;
}

.ui-icon-restart::after {
  border-bottom: 5px solid transparent;
  border-left: 7px solid currentColor;
  border-top: 5px solid transparent;
  content: "";
  position: absolute;
  right: -4px;
  top: -3px;
  transform: rotate(-26deg);
}

.ui-icon-hint {
  background: currentColor;
  border-radius: 50%;
  height: 18px;
  width: 18px;
}

.ui-icon-hint::before {
  background: #fffdf7;
  border-radius: 50%;
  content: "";
  height: 5px;
  left: 6px;
  position: absolute;
  top: 4px;
  width: 6px;
}

.ui-icon-hint::after {
  background: #fffdf7;
  border-radius: 2px;
  bottom: 3px;
  content: "";
  height: 3px;
  left: 7px;
  position: absolute;
  width: 4px;
}

.ui-icon-share {
  border: 2px solid currentColor;
  border-radius: 3px;
  height: 16px;
  width: 16px;
}

.ui-icon-share::before {
  border-left: 2px solid currentColor;
  border-top: 2px solid currentColor;
  content: "";
  height: 9px;
  position: absolute;
  right: -4px;
  top: -5px;
  transform: rotate(45deg);
  width: 9px;
}

.ui-icon-floor {
  background: #e7e0cf;
  border: 2px solid currentColor;
  border-radius: 3px;
  height: 18px;
  opacity: 0.72;
  width: 18px;
}

.ui-icon-wall {
  background:
    linear-gradient(135deg, currentColor 25%, transparent 25%) 0 0 / 8px 8px,
    rgba(92, 101, 93, 0.82);
  border-radius: 3px;
  height: 20px;
  width: 20px;
}

.ui-icon-hidden {
  background:
    linear-gradient(135deg, rgba(255, 244, 191, 0.65), transparent 42%),
    currentColor;
  border-radius: 3px;
  height: 20px;
  opacity: 0.76;
  width: 20px;
}

.ui-icon-person {
  background: currentColor;
  border-radius: 50% 50% 45% 45%;
  height: 20px;
  width: 16px;
}

.ui-icon-person::before {
  background: currentColor;
  border-radius: 50%;
  content: "";
  height: 11px;
  left: 2px;
  position: absolute;
  top: -9px;
  width: 11px;
}

.ui-icon-door {
  border: 3px solid currentColor;
  border-radius: 2px;
  height: 22px;
  width: 16px;
}

.ui-icon-door::after {
  background: currentColor;
  border-radius: 50%;
  content: "";
  height: 3px;
  position: absolute;
  right: 3px;
  top: 9px;
  width: 3px;
}

.ui-icon-key,
.ui-icon-fake-key {
  border: 3px solid currentColor;
  border-radius: 50%;
  height: 13px;
  transform: rotate(-25deg);
  width: 13px;
}

.ui-icon-key::after,
.ui-icon-fake-key::after {
  background: currentColor;
  content: "";
  height: 4px;
  left: 9px;
  position: absolute;
  top: 2px;
  width: 15px;
}

.ui-icon-key::before,
.ui-icon-fake-key::before {
  border-bottom: 4px solid currentColor;
  border-left: 4px solid transparent;
  content: "";
  height: 5px;
  left: 19px;
  position: absolute;
  top: 2px;
  width: 6px;
}

.ui-icon-elite-key {
  border: 3px solid currentColor;
  height: 16px;
  transform: rotate(45deg);
  width: 16px;
}

.ui-icon-elite-key::after {
  background: currentColor;
  content: "";
  height: 15px;
  left: 4px;
  position: absolute;
  top: 13px;
  width: 4px;
}

.ui-icon-elite-key::before {
  border-left: 4px solid currentColor;
  border-right: 4px solid currentColor;
  border-top: 4px solid currentColor;
  content: "";
  height: 4px;
  left: 2px;
  position: absolute;
  top: 25px;
  width: 4px;
}

.ui-icon-fake-key {
  opacity: 0.55;
}

.ui-icon-switch {
  background: currentColor;
  border-radius: 50%;
  height: 18px;
  width: 18px;
}

.ui-icon-switch::after {
  background: #fffdf7;
  border-radius: 4px;
  content: "";
  height: 4px;
  left: 4px;
  position: absolute;
  top: 7px;
  transform: rotate(-32deg);
  width: 12px;
}

.ui-icon-gate {
  background: repeating-linear-gradient(90deg, currentColor 0, currentColor 3px, transparent 3px, transparent 6px);
  border-left: 2px solid currentColor;
  border-right: 2px solid currentColor;
  height: 22px;
  width: 22px;
}

.ui-icon-laser {
  background: currentColor;
  border-radius: 999px;
  height: 4px;
  width: 24px;
}

.ui-icon-laser::before,
.ui-icon-laser::after {
  background: currentColor;
  border-radius: 50%;
  content: "";
  height: 8px;
  position: absolute;
  top: -2px;
  width: 8px;
}

.ui-icon-laser::before {
  left: -4px;
}

.ui-icon-laser::after {
  right: -4px;
}

.ui-icon-spike {
  border-bottom: 22px solid currentColor;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  height: 0;
  width: 0;
}

.game-head p,
.section-title p,
.locked-view p,
.loading-view p,
.empty-state p,
.level-card p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0;
}

.eyebrow {
  color: var(--steel);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0;
  text-transform: uppercase;
}

.hud-grid {
  display: grid;
  gap: 6px;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  min-width: min(360px, 100%);
}

.hud-item,
.quota-line,
.record-item {
  background: rgba(255, 253, 247, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}

.hud-item span,
.quota-line span,
.record-item span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
}

.hud-item strong,
.quota-line strong,
.record-item strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
  margin-top: 4px;
}

.board-wrap {
  align-items: center;
  display: flex;
  justify-content: center;
  overflow-x: auto;
  padding: 2px 0;
  overscroll-behavior: contain;
  touch-action: none;
}

.game-board-stack {
  display: grid;
  gap: 7px;
  justify-items: center;
}

.board-stage {
  display: inline-grid;
  overscroll-behavior: contain;
  position: relative;
  touch-action: none;
}

.room-board {
  --cell-size: min(10.5vw, 48px);
  background: #24383c;
  border: 4px solid #24383c;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(var(--cols), var(--cell-size));
  grid-template-rows: repeat(var(--rows), var(--cell-size));
  padding: 3px;
  touch-action: none;
}

.room-cell {
  align-items: center;
  border: 0;
  border-radius: 4px;
  color: var(--ink);
  display: inline-flex;
  font-size: clamp(10px, 2.6vw, 16px);
  font-weight: 900;
  height: var(--cell-size);
  justify-content: center;
  line-height: 1;
  min-width: 0;
  padding: 0;
  position: relative;
  width: var(--cell-size);
}

.room-cell:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.ghost-button:focus-visible,
.danger-button:focus-visible,
.tool-button:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgba(77, 165, 138, 0.38);
  outline-offset: 2px;
}

.cell-floor {
  background: #e7e0cf;
}

.cell-wall {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08) 25%, transparent 25%) 0 0 / 10px 10px,
    #5c655d;
}

.cell-start {
  background: #a9d1be;
}

.cell-exit {
  background: #293b3f;
  color: #fff5d7;
  font-size: clamp(8px, 2vw, 12px);
}

.cell-key,
.cell-key {
  background: #f2cf72;
}

.cell-elite-key {
  background: #d8e4f5;
  color: #1c4f7a;
}

.cell-fake-key {
  background: #d9d1c3;
  color: #8f4037;
}

.cell-switch-a,
.cell-switch-b {
  background: #83b8d4;
}

.cell-switch-b {
  background: #b8a3d2;
}

.cell-gate {
  background: repeating-linear-gradient(90deg, #414b4d 0, #414b4d 5px, #d0cabd 5px, #d0cabd 8px);
  color: #fffdf7;
}

.cell-laser {
  background: #efe2da;
  overflow: hidden;
}

.cell-laser::after {
  background: var(--red);
  content: "";
  height: 4px;
  left: 5px;
  position: absolute;
  right: 5px;
  top: calc(50% - 2px);
}

.cell-laser.is-disabled::after {
  background: #8fa39a;
  opacity: 0.32;
}

.cell-spike,
.cell-moving-trap,
.room-cell.has-moving-trap {
  background: #5b3131;
  color: #ffe0d7;
}

.cell-hidden {
  background:
    linear-gradient(135deg, rgba(255, 244, 191, 0.24), transparent 38%),
    #6c746b;
}

.room-cell.has-player::before {
  content: none;
}

.room-cell.has-player .cell-mark {
  color: var(--steel-dark);
  position: relative;
  z-index: 2;
}

.game-actions,
.editor-actions,
.card-actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  align-items: center;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 900;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
}

.primary-button {
  background: var(--steel);
  border: 1px solid var(--steel-dark);
  color: #fff8df;
}

.secondary-button,
.ghost-button {
  background: rgba(255, 253, 247, 0.88);
  border: 1px solid var(--line);
  color: var(--steel-dark);
}

.ghost-button {
  color: var(--muted);
}

.danger-button {
  background: #fff4ef;
  border: 1px solid #edc2b8;
  color: #9b352c;
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.game-message-slot {
  bottom: 10px;
  left: 10px;
  pointer-events: none;
  position: absolute;
  right: 10px;
  z-index: 10;
}

.game-legend {
  align-items: center;
  background: rgba(255, 253, 247, 0.82);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  max-width: min(100%, 560px);
  padding: 6px;
}

.legend-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  padding: 0 2px;
}

.legend-chip {
  align-items: center;
  background: rgba(238, 241, 232, 0.95);
  border-radius: 999px;
  color: var(--steel-dark);
  display: inline-flex;
  gap: 5px;
  min-height: 26px;
  padding: 4px 8px;
}

.legend-chip .ui-icon {
  transform: scale(0.64);
  transform-origin: center;
}

.legend-chip small {
  color: #47564f;
  font-size: 12px;
  font-weight: 900;
}

.game-message {
  background: rgba(31, 52, 56, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(24, 32, 29, 0.26);
  color: #fff8df;
  display: grid;
  gap: 4px;
  justify-items: start;
  margin: 0 auto;
  max-width: 320px;
  padding: 10px 12px;
  pointer-events: auto;
}

.game-message strong,
.game-message span {
  line-height: 1.35;
}

.game-message strong {
  font-size: 15px;
}

.game-message span {
  color: rgba(255, 248, 223, 0.86);
  font-size: 13px;
}

.game-message.success,
.game-message.won {
  background: rgba(36, 97, 79, 0.94);
}

.game-message.failed {
  background: rgba(143, 53, 45, 0.94);
}

.message-action {
  background: #fff8df;
  border: 0;
  border-radius: 7px;
  color: var(--steel-dark);
  font-weight: 900;
  margin-top: 5px;
  min-height: 34px;
  padding: 7px 11px;
}

.segmented {
  background: rgba(255, 253, 247, 0.9);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: inline-flex;
  gap: 4px;
  padding: 4px;
}

.segmented button {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 900;
  min-height: 34px;
  padding: 7px 10px;
}

.segmented button.active {
  background: var(--steel);
  color: #fff8df;
}

.level-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.list-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  margin: 8px 0 0;
}

.level-card {
  background: rgba(255, 253, 247, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.rank-badge {
  background: #263b3f;
  border-radius: 999px;
  color: #fff8df;
  display: inline-flex;
  font-size: 11px;
  margin-right: 8px;
  padding: 4px 7px;
}

.level-card h2 {
  font-size: 20px;
  line-height: 1.2;
  margin: 3px 0 6px;
}

.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stat-row span {
  background: #eef1e8;
  border-radius: 999px;
  color: #48554f;
  font-size: 12px;
  font-weight: 800;
  padding: 6px 9px;
}

.editor-layout {
  display: grid;
  gap: 14px;
}

.editor-fields {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.editor-fields label {
  color: var(--muted);
  display: grid;
  font-size: 12px;
  font-weight: 800;
  gap: 5px;
}

.editor-fields label:first-child,
.editor-fields label:nth-child(2) {
  grid-column: span 2;
}

.editor-fields input {
  background: #fffdf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  outline: none;
  padding: 9px 10px;
}

.editor-fields small {
  color: var(--muted);
  line-height: 1.3;
}

.editor-guide {
  align-items: center;
  background: rgba(255, 253, 247, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  padding: 9px 11px;
}

.editor-guide strong {
  color: var(--steel-dark);
  flex: 0 0 auto;
  font-size: 14px;
  white-space: nowrap;
}

.editor-guide span {
  color: var(--muted);
  flex: 1;
  font-size: 13px;
  font-weight: 800;
  text-align: right;
}

.tool-row {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(7, minmax(74px, 1fr));
  overflow-x: auto;
  padding-bottom: 2px;
}

.tool-button {
  background: #fffdf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 3px;
  min-height: 56px;
  min-width: 74px;
  padding: 7px;
}

.tool-button.active {
  background: var(--steel);
  border-color: var(--steel);
  box-shadow: 0 8px 20px rgba(31, 52, 56, 0.22), inset 0 0 0 2px rgba(255, 248, 223, 0.32);
  color: #fff8df;
  transform: translateY(-1px);
}

.tool-glyph {
  align-items: center;
  display: inline-flex;
  font-size: 16px;
  font-weight: 900;
  height: 26px;
  justify-content: center;
}

.tool-glyph .ui-icon {
  transform: scale(0.82);
  transform-origin: center;
}

.tool-button small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.tool-button.active small {
  color: rgba(255, 248, 223, 0.92);
}

.editor-board .room-cell {
  cursor: crosshair;
}

.locked-view,
.loading-view,
.empty-state {
  align-items: flex-start;
  background: rgba(255, 253, 247, 0.88);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 22px;
}

.empty-state.compact {
  box-shadow: none;
  padding: 14px;
}

.unlock-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.unlock-grid span {
  background: #eee8da;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 900;
  padding: 8px 12px;
}

.unlock-grid span.done {
  background: rgba(77, 165, 138, 0.18);
  color: #24614f;
}

.quota-line {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
}

.quota-line strong {
  margin: 0;
}

.subhead {
  font-size: 18px;
  margin: 20px 0 4px;
}

.record-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.record-item {
  display: flex;
  gap: 8px;
  justify-content: space-between;
}

.record-item strong {
  font-size: 14px;
  margin: 0;
}

.record-item span {
  text-align: right;
}

.skeleton-card {
  background: linear-gradient(90deg, rgba(255, 253, 247, 0.72), rgba(255, 253, 247, 0.96), rgba(255, 253, 247, 0.72));
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 142px;
  overflow: hidden;
}

.modal-backdrop {
  align-items: center;
  background: rgba(24, 32, 29, 0.48);
  bottom: 0;
  display: flex;
  justify-content: center;
  left: 0;
  padding: 16px;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 60;
}

.share-modal {
  background: #fffdf7;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  max-width: 360px;
  padding: 18px;
  position: relative;
  width: 100%;
}

.share-modal h2 {
  margin: 0;
}

.modal-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-weight: 800;
  position: absolute;
  right: 10px;
  top: 10px;
}

.qr-image {
  align-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  height: 180px;
  justify-self: center;
  width: 180px;
}

.share-link {
  background: #f7f2e6;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 40px;
  padding: 9px;
  width: 100%;
}

#toast-root {
  bottom: calc(90px + env(safe-area-inset-bottom));
  display: grid;
  gap: 8px;
  left: 14px;
  position: fixed;
  right: 14px;
  z-index: 80;
}

.toast {
  background: rgba(31, 52, 56, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  box-shadow: 0 10px 28px rgba(24, 32, 29, 0.24);
  color: #fff8df;
  font-weight: 800;
  justify-self: center;
  max-width: min(420px, 100%);
  padding: 11px 14px;
}

.toast.success {
  background: #24614f;
}

.toast.error {
  background: #8f352d;
}

@media (min-width: 800px) {
  .app-shell {
    padding: 22px 24px 82px;
  }

  .game-layout {
    justify-items: center;
  }

  .game-head,
  .game-status-row,
  .board-wrap {
    width: min(620px, 100%);
  }

  .room-board {
    --cell-size: min(5.1vw, 54px);
  }

  .level-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .record-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    overflow: hidden;
    padding-bottom: calc(58px + env(safe-area-inset-bottom));
    padding-left: 10px;
    padding-right: 10px;
  }

  .game-layout {
    gap: 7px;
  }

  .game-head,
  .section-title {
    align-items: center;
    flex-direction: row;
  }

  .game-head h1 {
    font-size: 26px;
  }

  .hud-grid {
    grid-template-columns: repeat(3, 1fr);
    min-width: 0;
  }

  .hud-item {
    padding: 7px 8px;
  }

  .hud-item strong {
    font-size: 15px;
  }

  .room-board {
    --cell-size: min(calc((100vw - 52px) / var(--cols)), calc((100dvh - 318px) / var(--rows)), 38px);
    gap: 2px;
  }

  .game-legend {
    gap: 4px;
    padding: 5px;
  }

  .legend-chip {
    gap: 3px;
    min-height: 24px;
    padding: 3px 7px;
  }

  .legend-chip small,
  .legend-label {
    font-size: 11px;
  }

  .editor-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-fields label:first-child,
  .editor-fields label:nth-child(2) {
    grid-column: span 2;
  }

  .tool-row {
    grid-template-columns: repeat(14, 74px);
  }

  .bottom-nav {
    left: 0;
    max-width: none;
    right: 0;
  }
}

@media (max-width: 380px) {
  .brand small {
    display: none;
  }

  .profile-chip input {
    max-width: 112px;
  }

  .room-board {
    --cell-size: min(calc((100vw - 48px) / var(--cols)), calc((100dvh - 304px) / var(--rows)), 34px);
  }
}
