:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #121019;
  color: #f4efe6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 50% 30%, rgba(126, 92, 142, 0.18), transparent 42rem),
    #121019;
}

.shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 46px) 22px;
}

.masthead {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: #e6a95c;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.65rem, 3.5vw, 3.25rem);
  font-weight: 400;
  letter-spacing: -0.035em;
}

.controls {
  display: flex;
  align-items: center;
  gap: 16px;
  color: #bcb5c5;
  font-size: 0.84rem;
}

kbd {
  padding: 3px 7px;
  border: 1px solid #4d4658;
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #24202d;
  color: #fff8ed;
  font-family: inherit;
  font-size: 0.72rem;
}

button {
  border: 1px solid #5c5266;
  border-radius: 999px;
  padding: 8px 13px;
  background: transparent;
  color: #eee8f1;
  cursor: pointer;
}

button:hover, button:focus-visible { background: #2b2534; outline: none; }

.stage {
  position: relative;
  overflow: hidden;
  border: 1px solid #383140;
  border-radius: 18px;
  background: #1a1721;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.36);
  aspect-ratio: 1280 / 760;
  max-height: calc(100vh - 180px);
  max-height: calc(100dvh - 180px);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.status {
  position: absolute;
  inset: auto 16px 14px 16px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
  color: rgba(255, 255, 255, 0.68);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
}

.dialog-bubble {
  position: absolute;
  z-index: 5;
  width: max-content;
  max-width: min(270px, 42%);
  transform: translate(-50%, calc(-100% - 18px));
  padding: 10px 13px;
  border: 2px solid #332a35;
  border-radius: 12px;
  background: #fff9eb;
  color: #2d2530;
  box-shadow: 0 7px 22px rgba(25, 18, 27, 0.28);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

.dialog-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 14px;
  height: 14px;
  border-right: 2px solid #332a35;
  border-bottom: 2px solid #332a35;
  background: #fff9eb;
  transform: translate(-50%, -7px) rotate(45deg);
}

.dialog-bubble a {
  position: relative;
  z-index: 1;
  color: #9a343d;
  font-weight: 750;
  text-underline-offset: 2px;
}

.dialog-bubble[hidden] { display: none; }

.mobile-hint { display: none; }

.note {
  margin: 13px 3px 0;
  color: #817989;
  font-size: 0.78rem;
}

code { color: #c7a36f; }

@media (max-width: 760px), (max-height: 520px) {
  body { overflow: hidden; }

  .shell {
    height: 100vh;
    height: 100dvh;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .masthead {
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
  }

  .eyebrow { display: none; }
  h1 { font-size: clamp(1.25rem, 7vw, 1.75rem); }
  .controls { width: 100%; justify-content: space-between; gap: 10px; font-size: 0.76rem; }
  .desktop-hint { display: none; }
  .mobile-hint { display: inline; }

  button {
    min-height: 44px;
    padding-inline: 14px;
  }

  .stage {
    width: 100%;
    height: 100%;
    min-height: 0;
    max-height: none;
    aspect-ratio: auto;
    border-radius: 12px;
  }

  .status {
    inset: auto 10px max(8px, env(safe-area-inset-bottom)) 10px;
  }

  #position { display: none; }

  .dialog-bubble {
    max-width: calc(100% - 24px);
    font-size: 0.82rem;
  }
}

.editor-preview .shell { width: 100%; padding: 0; }
.editor-preview .masthead,
.editor-preview .note { display: none; }
.editor-preview .stage { height: 100vh; max-height: none; aspect-ratio: auto; border: 0; border-radius: 0; box-shadow: none; }
.editor-preview canvas { width: 100%; max-height: none; min-height: 0; cursor: grab; }
.editor-preview .status { display: none; }
.editor-preview .dialog-bubble { display: none; }
