:root {
  --navy: #0b1a4f;
  --navy-2: #13287a;
  --frame: #f39a1c;
  --frame-dark: #c46a08;
  --yellow: #ffd91a;
  --red: #e3241b;
  --red-dark: #a8140d;
  --ink: #fff8e6;
  --muted: #c9d3ff;
  --gutter: 16px;
  --toolbar-h: 48px;
  --font: ui-rounded, "Nunito", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(ellipse at 50% 30%, var(--navy-2), var(--navy) 70%);
  background-color: var(--navy);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
}

#wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: var(--gutter);
}

/* Moldura 4:3 que lembra a lousa do título. */
#stage {
  position: relative;
  width: min(100%, calc((100vh - var(--toolbar-h) - 3 * var(--gutter)) * 4 / 3));
  width: min(100%, calc((100dvh - var(--toolbar-h) - 3 * var(--gutter)) * 4 / 3));
  aspect-ratio: 4 / 3;
  border: clamp(4px, 1.2vmin, 12px) solid var(--frame);
  border-radius: 14px;
  box-shadow: 0 0 0 3px var(--frame-dark), 0 18px 50px rgba(0, 0, 0, .55);
  background: #000;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  outline: none;
  cursor: default;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.overlay[hidden] { display: none; }

#intro { background: var(--navy); }
#cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;
}

.panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 4% 6% 3.5%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  background: linear-gradient(to top, rgba(6, 14, 46, .95) 55%, rgba(6, 14, 46, 0));
}

.load { width: min(420px, 90%); }
.load[hidden] { display: none; }
.bar {
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .15);
  border: 2px solid rgba(255, 255, 255, .35);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--yellow), var(--frame));
  border-radius: 999px;
  transition: width .2s ease-out;
}
.load-text { margin: 8px 0 0; font-size: 15px; color: var(--muted); font-variant-numeric: tabular-nums; }

.play {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 14px 40px 14px 30px;
  font: 800 clamp(22px, 3.4vmin, 32px)/1 var(--font);
  letter-spacing: .02em;
  color: var(--yellow);
  background: var(--red);
  border: 3px solid var(--yellow);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--red-dark), 0 10px 24px rgba(0, 0, 0, .45);
  cursor: pointer;
  transition: transform .08s ease, box-shadow .08s ease;
  animation: pulse 1.8s ease-in-out infinite;
}
.play svg { width: 1.1em; height: 1.1em; fill: currentColor; }
.play:hover { transform: translateY(-1px); }
.play:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--red-dark), 0 4px 10px rgba(0, 0, 0, .45); }
.play:focus-visible { outline: 3px solid #fff; outline-offset: 4px; }
.play[hidden] { display: none; }
.play.small { font-size: 18px; padding: 10px 24px; animation: none; }

@keyframes pulse { 50% { transform: scale(1.04); } }
@media (prefers-reduced-motion: reduce) { .play { animation: none; } }

.hint { margin: 0; font-size: 13px; color: var(--muted); max-width: 46ch; }

.booting { background: rgba(0, 0, 0, .75); gap: 14px; font-size: 18px; }
.spinner {
  width: 44px; height: 44px;
  border: 5px solid rgba(255, 255, 255, .2);
  border-top-color: var(--yellow);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error { background: rgba(20, 4, 4, .92); gap: 8px; padding: 24px; }
.error-title { margin: 0; font-size: 24px; font-weight: 800; color: var(--yellow); }
.error-text { margin: 0 0 12px; color: var(--muted); max-width: 52ch; font-size: 14px; }

#toolbar {
  height: var(--toolbar-h);
  width: min(100%, calc((100vh - var(--toolbar-h) - 3 * var(--gutter)) * 4 / 3));
  width: min(100%, calc((100dvh - var(--toolbar-h) - 3 * var(--gutter)) * 4 / 3));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.tip { font-size: 14px; color: var(--muted); }
.tool {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font: 700 15px/1 var(--font);
  color: var(--ink);
  background: rgba(255, 255, 255, .1);
  border: 2px solid rgba(255, 255, 255, .3);
  border-radius: 10px;
  cursor: pointer;
}
.tool:hover { background: rgba(255, 255, 255, .18); }
.tool:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

/* Tela cheia: só o jogo, centralizado, sem moldura. */
#wrap:fullscreen { padding: 0; background: #000; }
#wrap:fullscreen #stage {
  width: min(100vw, calc(100vh * 4 / 3));
  width: min(100dvw, calc(100dvh * 4 / 3));
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
#wrap:fullscreen #toolbar { display: none; }

@media (max-width: 560px) {
  .tip { display: none; }
  #toolbar { justify-content: flex-end; }
}
/* Phones in landscape: little height, so the toolbar moves to the right side and shows icons only. */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --gutter: 6px; --toolbar-w: 44px; }
  #wrap { flex-direction: row; gap: 6px; }
  #stage {
    width: min(100% - var(--toolbar-w), calc((100vh - 2 * var(--gutter)) * 4 / 3));
    width: min(100% - var(--toolbar-w), calc((100dvh - 2 * var(--gutter)) * 4 / 3));
  }
  #toolbar { width: var(--toolbar-w); height: auto; flex-direction: column; justify-content: center; gap: 8px; }
  .tip { display: none; }
  .tool { padding: 8px; }
  .tool span { display: none; }
}

/* Touch screens: on-screen keyboard button, and a "rotate" notice in portrait while playing. */
#keyboard { display: none; }
@media (pointer: coarse) { #keyboard { display: inline-flex; } }
#kbd-input {
  position: fixed;
  left: 0; bottom: 0;
  width: 1px; height: 1px;
  padding: 0; border: 0;
  opacity: 0;
  font-size: 16px;  /* below 16px iOS zooms the page on focus */
  pointer-events: none;
}
#rotate { display: none; }
@media (pointer: coarse) and (orientation: portrait) {
  body.playing:not(.rotate-skipped) #rotate {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px;
    text-align: center;
    font-size: 20px;
    font-weight: 800;
    color: var(--yellow);
    background: var(--navy);
  }
  #rotate svg { width: 72px; height: 72px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  #rotate .rotate-skip { font: 700 15px/1 var(--font); }
}

.debug-console {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 30vh;
  background: #000;
  color: #9f9;
  font: 12px/1.4 ui-monospace, monospace;
  border: 0;
  padding: 8px;
  z-index: 10;
}
.debug-console[hidden] { display: none; }

/* Game dialogs (recompiled build): a 640x480 layer scaled with the canvas, Windows 98 look. */
.dlg-layer {
  position: absolute;
  left: 0; top: 0;
  width: 640px; height: 480px;
  transform: scale(var(--s, 1));
  transform-origin: 0 0;
  background: rgba(0, 0, 0, .25);
  z-index: 5;
}
.dlg-layer[hidden] { display: none; }
.dlg {
  position: absolute;
  background: #c0c0c0;
  color: #000;
  border: 1px solid;
  border-color: #dfdfdf #000 #000 #dfdfdf;
  box-shadow: inset 1px 1px #fff, inset -1px -1px #808080, 4px 4px 0 rgba(0, 0, 0, .35);
  padding: 2px;
  font: 11px/1.25 "MS Sans Serif", "Microsoft Sans Serif", Tahoma, Arial, sans-serif;
}
.dlg-title {
  height: 18px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  background: linear-gradient(90deg, #000080, #1084d0);
  color: #fff;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
}
.dlg-body { position: relative; }
.dlg-static, .dlg-button, .dlg-check { position: absolute; box-sizing: border-box; }
.dlg-static { white-space: pre-wrap; overflow: hidden; }
.dlg-button {
  font: inherit;
  color: #000;
  background: #c0c0c0;
  border: 1px solid;
  border-color: #fff #000 #000 #fff;
  box-shadow: inset -1px -1px #808080, inset 1px 1px #dfdfdf;
  padding: 0;
  cursor: pointer;
}
.dlg-button:active { border-color: #000 #fff #fff #000; box-shadow: inset 1px 1px #808080; }
.dlg-button.dlg-default { outline: 1px solid #000; }
.dlg-button:focus-visible { outline: 1px dotted #000; outline-offset: -4px; }
.dlg-check { display: flex; align-items: flex-start; gap: 4px; cursor: pointer; }
.dlg-check input { margin: 1px 0 0; }

.tip-link { color: var(--yellow); margin-left: 6px; }
