html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: #000;
  overflow: hidden;
}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100dvh;
}
#canvas {
  display: block;
  width: min(100vw, calc(100dvh * 4 / 3));
  height: min(100dvh, calc(100vw * 3 / 4));
  outline: none;
  touch-action: none;
}
#loading {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  color: #eee;
  font:
    16px system-ui,
    sans-serif;
}
#loading[hidden] {
  display: none;
}
#loading-text {
  max-width: 90vw;
  white-space: pre-wrap;
  text-align: center;
}
#pvz-soft-keyboard {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  font-size: 16px;
}

/* Keep controls in a reserved black margin, never over the game. */
body {
  --tools-width: 220px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--tools-width);
  font-family: system-ui, sans-serif;
  color: #eee;
}
#game-stage {
  position: relative;
  min-width: 0;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
}
#canvas, #startup-logo {
  width: min(calc(100vw - var(--tools-width)), calc(100dvh * 4 / 3));
  height: min(100dvh, calc((100vw - var(--tools-width)) * 3 / 4));
}
#startup-logo {
  position: absolute;
  display: grid;
  place-items: center;
  background: #000;
  pointer-events: none;
}
#startup-logo img { width: 37.5%; height: auto; }
#startup-logo[hidden] { display: none; }
#game-mask {
  position: absolute;
  inset: 0;
  z-index: 2;
}
#game-mask[hidden] {
  display: none;
}
#cheat-panel {
  box-sizing: border-box;
  padding: 24px 18px;
  align-self: center;
  max-height: 100dvh;
  overflow: auto;
  font-size: 13px;
}
#cheat-panel h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0 0 16px;
  color: #eee3c7;
}
.window-tools {
  border-bottom: 1px solid #282828;
  padding-bottom: 14px;
  margin-bottom: 18px;
}
#cheat-panel .window-tools button {
  margin-top: 8px;
  padding: 9px 7px;
  background: #202a30;
  border-color: #45545c;
}
#cheat-panel .window-tools button:disabled {
  background: #191919;
  border-color: #303030;
}
#window-status:empty { display: none; }
#exit-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  background: #080b08;
  text-align: center;
}
#exit-screen[hidden] { display: none; }
#exit-screen h2 { color: #eee3c7; }
#exit-screen p { max-width: 520px; line-height: 1.7; }
#exit-screen button {
  padding: 12px 24px;
  border: 1px solid #536747;
  border-radius: 7px;
  background: #253323;
  color: #eee;
  cursor: pointer;
}
#cheat-panel p {
  margin: 8px 0;
  line-height: 1.6;
}
#cheat-player {
  font-weight: 600;
  overflow-wrap: anywhere;
}
#cheat-panel .muted,
#cheat-panel .help {
  color: #999;
  font-size: 12px;
}
#cheat-panel button {
  display: block;
  width: 100%;
  margin-top: 18px;
  padding: 11px 8px;
  border: 1px solid #536747;
  border-radius: 7px;
  background: #253323;
  color: #e3eddd;
  font:
    600 13px system-ui,
    sans-serif;
  cursor: pointer;
}
#cheat-panel button.gold {
  background: #4d3e1d;
  color: #ffe3a2;
  border-color: #806a33;
}
#cheat-panel button:hover:enabled {
  filter: brightness(1.22);
}
#cheat-panel button:focus-visible {
  outline: 2px solid #f2d185;
  outline-offset: 3px;
}
#cheat-panel button:disabled {
  color: #777;
  border-color: #303030;
  background: #191919;
  cursor: default;
}
.wallet {
  display: grid;
  gap: 4px;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #282828;
}
.wallet span {
  font-size: 12px;
  color: #aaa;
}
.wallet strong {
  font-size: 23px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #f1dc99;
}
.wallet small {
  font-size: 11px;
  color: #777;
}
#cheat-status {
  min-height: 44px;
  color: #d4d1b7;
  font-size: 12px;
}
#cheat-panel .footnote {
  font-size: 11px;
  color: #666;
  border-top: 1px solid #282828;
  padding-top: 12px;
}
@media (max-width: 600px) {
  body {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100dvh;
  }
  #game-stage {
    width: 100%;
    height: auto;
    flex: 1;
    min-height: 0;
  }
  #canvas, #startup-logo {
    width: min(100vw, calc((100dvh - 232px) * 4 / 3));
    height: min(calc(100vw * 3 / 4), calc(100dvh - 232px));
  }
  #cheat-panel {
    width: 100%;
    padding: 12px 16px;
    max-height: 232px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 14px;
  }
  #cheat-panel h1 {
    display: none;
  }
  .window-tools {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-bottom: 6px;
    padding-bottom: 8px;
  }
  #cheat-panel .window-tools button { width: auto; margin: 0; }
  #window-mode, #audio-state, #window-status { font-size: 10px; }
  #cheat-panel p {
    margin: 3px 0;
  }
  #cheat-panel button {
    margin-top: 8px;
  }
  .wallet {
    margin-top: 0;
    padding-top: 0;
    border: 0;
    grid-column: 2;
    grid-row: 1 / 3;
  }
  .wallet strong {
    font-size: 19px;
  }
  #cheat-gold {
    grid-column: 1;
  }
  #cheat-coins {
    grid-column: 2;
    grid-row: 3;
  }
  #cheat-panel .help {
    font-size: 10px;
  }
  #cheat-status,
  #cheat-panel .footnote {
    grid-column: 1 / -1;
    min-height: 0;
  }
  #cheat-panel .footnote {
    display: none;
  }
}

.language-tools { border-bottom: 1px solid #282828; padding-bottom: 12px; margin-bottom: 14px; }
#language-status:empty { display: none; }
#cheat-panel #switch-language { margin-top: 7px; background: #202a30; border-color: #45545c; }
@media (max-width: 600px) { .language-tools { grid-column: 1 / -1; margin: 0; display: flex; align-items: center; gap: 12px; } #cheat-panel #switch-language { width: auto; margin: 0; } }
body:has(.about-page) {display:block;overflow:auto;height:auto;min-height:100dvh;}
.about-page {max-width:760px;margin:40px auto;padding:24px;line-height:1.8;}
.about-page a {color:#cddcaf;}

.web-save-tools {margin:16px 0;padding:12px 0;border-bottom:1px solid #333;} .web-save-tools a {color:#cddcaf;}
