:root {
  color-scheme: dark;
  --ink: #332c3b;
  --cream: #f5e5bc;
  --peach: #e8a87c;
  --mint: #91b6a0;
  --yellow: #e8c56b;
  --red: #bd5d5d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #24202b;
  font-family: "Courier New", Courier, monospace;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 35%, #52455b 0, #322b3b 45%, #1d1a23 100%);
}

button { font-family: inherit; }

#game-shell {
  width: min(100vw, 1066px);
  padding: 16px;
}

#screen-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 6px solid var(--ink);
  border-radius: 8px;
  background: #121016;
  box-shadow: 0 18px 60px #0008, inset 0 0 0 3px #716478;
}

#game,
#game canvas {
  width: 100% !important;
  height: 100% !important;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

#desktop-hint {
  margin: 10px 0 0;
  color: #b9a9be;
  text-align: center;
  font-size: 12px;
  letter-spacing: .08em;
}

#touch-controls,
#rotate-overlay { display: none; }

@media (orientation: portrait) and (max-width: 700px),
       (orientation: portrait) and (hover: none) and (pointer: coarse) {
  body {
    display: block;
    min-height: 100dvh;
    background: #211d28;
  }

  #game-shell { display: none; }

  #rotate-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    min-height: 100dvh;
    padding:
      max(28px, env(safe-area-inset-top))
      max(24px, env(safe-area-inset-right))
      max(28px, env(safe-area-inset-bottom))
      max(24px, env(safe-area-inset-left));
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--cream);
    text-align: center;
    background:
      radial-gradient(circle at 50% 34%, #5a4b60 0 8%, #3e3448 38%, #211d28 76%);
  }

  #rotate-overlay::before,
  #rotate-overlay::after {
    content: "✦   ·   ✧   ·   ✦";
    position: absolute;
    color: #e8c56b99;
    font-size: 18px;
    letter-spacing: .35em;
  }

  #rotate-overlay::before {
    top: max(42px, calc(env(safe-area-inset-top) + 22px));
    left: 22px;
    transform: rotate(-12deg);
  }

  #rotate-overlay::after {
    right: 16px;
    bottom: max(50px, calc(env(safe-area-inset-bottom) + 24px));
    transform: rotate(13deg);
  }

  .rotate-stars {
    margin-bottom: 25px;
    color: var(--mint);
    font-size: 18px;
    letter-spacing: .2em;
  }

  .phone-icon {
    position: relative;
    width: 72px;
    height: 116px;
    margin: 0 0 34px;
    border: 5px solid var(--cream);
    border-radius: 13px;
    box-shadow: 0 0 0 7px #e8c56b18, 0 14px 30px #0005;
    animation: rotate-phone 2.8s ease-in-out infinite;
  }

  .phone-icon::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    width: 24px;
    height: 4px;
    border-radius: 3px;
    background: var(--cream);
    transform: translateX(-50%);
  }

  .phone-icon span {
    position: absolute;
    inset: 23px 10px 12px;
    border: 3px solid var(--peach);
    background:
      linear-gradient(135deg, #91b6a044 25%, transparent 25% 50%, #bd5d5d33 50% 75%, transparent 75%),
      #f5e5bc18;
  }

  .rotate-eyebrow {
    margin: 0 0 14px;
    color: var(--yellow);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .16em;
  }

  #rotate-overlay h1 {
    margin: 0;
    max-width: 340px;
    font-size: clamp(28px, 8vw, 42px);
    line-height: 1.08;
    letter-spacing: -.035em;
  }

  #rotate-overlay > p:last-of-type {
    margin: 20px 0 0;
    max-width: 340px;
    color: #d2c4d5;
    font-size: 14px;
    line-height: 1.65;
  }

  .rotate-arrow {
    margin-top: 24px;
    color: var(--peach);
    font-size: 35px;
    line-height: 1;
  }

  @keyframes rotate-phone {
    0%, 18%, 82%, 100% { transform: rotate(0deg); }
    36%, 64% { transform: rotate(90deg); }
  }

  @media (prefers-reduced-motion: reduce) {
    .phone-icon { animation: none; transform: rotate(90deg); }
  }
}

@media (orientation: landscape) and (max-height: 600px),
       (orientation: landscape) and (hover: none) and (pointer: coarse) {
  html, body {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
  }

  body {
    display: block;
    background: #17131d;
  }

  #game-shell {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-width: none;
    padding:
      env(safe-area-inset-top)
      env(safe-area-inset-right)
      env(safe-area-inset-bottom)
      env(safe-area-inset-left);
    display: grid;
    place-items: center;
  }

  #screen-wrap {
    width: min(100%, calc(100dvh * 16 / 9));
    height: min(100%, calc(100vw * 9 / 16));
    aspect-ratio: 16 / 9;
    border: 0;
    border-radius: 0;
    box-shadow: 0 0 34px #000b;
  }

  #desktop-hint,
  #rotate-overlay { display: none; }

  body[data-scene="store"] #touch-controls {
    position: fixed;
    inset: 0;
    z-index: 10;
    display: block;
    pointer-events: none;
  }

  .joystick-wrap,
  .action-pad {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #f5e5bccc;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .12em;
    text-shadow: 0 2px 4px #000c;
    pointer-events: none;
  }

  .joystick-wrap {
    left: max(8px, env(safe-area-inset-left));
    bottom: max(58px, calc(env(safe-area-inset-bottom) + 42px));
    gap: 5px;
  }

  .joystick {
    position: relative;
    width: clamp(72px, 12.5vw, 92px);
    height: clamp(72px, 12.5vw, 92px);
    border: 3px solid #f5e5bca6;
    border-radius: 50%;
    background:
      radial-gradient(circle, #f5e5bc24 0 22%, transparent 23%),
      #332c3ba8;
    box-shadow: inset 0 0 0 6px #17131d42, 0 6px 18px #0007;
    backdrop-filter: blur(4px);
    pointer-events: auto;
    touch-action: none;
  }

  .joystick::before,
  .joystick::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    background: #f5e5bc35;
    transform: translate(-50%, -50%);
  }

  .joystick::before { width: 62%; height: 2px; }
  .joystick::after { width: 2px; height: 62%; }

  .joystick-knob {
    position: absolute;
    top: 50%;
    left: 50%;
    width: clamp(31px, 5.5vw, 40px);
    height: clamp(31px, 5.5vw, 40px);
    border: 3px solid var(--ink);
    border-radius: 50%;
    background: var(--cream);
    box-shadow: 0 4px 0 #17131d88, 0 7px 14px #0006;
    transform: translate(0, 0);
    translate: -50% -50%;
    transition: transform 55ms linear, background 120ms ease;
    pointer-events: none;
  }

  .joystick.active .joystick-knob {
    background: var(--yellow);
    transition: none;
  }

  .action-pad {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(24px, calc(env(safe-area-inset-bottom) + 12px));
    gap: 7px;
  }

  #touch-controls .action {
    width: clamp(62px, 9.5vw, 74px);
    height: clamp(62px, 9.5vw, 74px);
    padding: 0;
    border: 3px solid var(--ink);
    border-radius: 50%;
    color: var(--ink);
    background: #e8a87ce0;
    font: bold clamp(21px, 3.8vw, 28px)/1 "Courier New", monospace;
    box-shadow: 0 5px 0 #17131d9c, 0 9px 18px #0006;
    backdrop-filter: blur(4px);
    pointer-events: auto;
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
  }

  #touch-controls .action:active,
  #touch-controls .action.pressed {
    transform: translateY(4px);
    background: var(--yellow);
    box-shadow: 0 1px 0 #17131d9c, 0 4px 10px #0005;
  }
}
