:root {
  color-scheme: dark;
  --void: #080b12;
  --stone: #172031;
  --edge: #3a465e;
  --silver: #e7edf7;
  --muted: #a5b0c4;
  --gold: #edce90;
  font-family: 'Trebuchet MS', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  color: var(--silver);
  background: var(--void);
}

#game-shell {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  height: 100%;
  height: 100dvh;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: radial-gradient(ellipse at 50% 48%, #202a3d, var(--void) 75%);
}

#game {
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#game canvas { display: block; }
.portrait-header, .portrait-footer { display: none; }

button {
  appearance: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.play-button {
  min-height: 50px;
  padding: 0.6em 1.6em;
  border: 1px solid #f1d496;
  border-radius: 6px;
  background: #dfbc7e;
  color: #221a13;
  font-weight: 700;
}

.play-button:active { background: #f2dcae; }
.play-button:disabled { opacity: 0.55; cursor: default; }

.intro {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 1.2rem;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: radial-gradient(ellipse, #172031, var(--void) 72%);
}

.intro img {
  display: block;
  width: min(100%, 72rem);
  height: 100%;
  object-fit: contain;
}

.intro-status { color: var(--muted); text-align: center; }
.intro-status p { margin: 0 0 0.6rem; }

@media (orientation: portrait) and (any-pointer: coarse) {
  #game-shell {
    grid-template-rows: auto minmax(0, 1fr) auto;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
  }

  .portrait-header {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-width: 0;
    padding: 0.55rem 0.85rem;
    border-bottom: 1px solid #253048;
    background: var(--void);
  }

  .portrait-header img { width: 2.35rem; height: 2.35rem; border-radius: 6px; }
  .portrait-header h1 { margin: 0; font: 700 1.15rem Georgia, serif; letter-spacing: 0.075em; }

  #game canvas { outline: 1px solid #384457; outline-offset: -1px; }

  .portrait-footer {
    display: block;
    width: min(100%, 36rem);
    margin-inline: auto;
    padding: 0.65rem clamp(0.55rem, 3vw, 1.1rem) 0;
  }

  body[data-screen="loading"] .portrait-footer { visibility: hidden; }
  #portrait-lobby { text-align: center; }
  #play-button { width: min(100%, 22rem); }

  .control-row, .control-tools {
    display: grid;
    gap: clamp(0.3rem, 1.5vw, 0.7rem);
  }

  .control-row { grid-template-columns: 0.8fr 0.8fr 1fr 1fr; }
  .control-tools { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 0.5rem; }

  .control, .control-tools button {
    min-width: 0;
    border: 1px solid var(--edge);
    border-radius: 7px;
    background: linear-gradient(#222e44, var(--stone));
    box-shadow: 0 3px 0 #070a11;
    -webkit-tap-highlight-color: transparent;
  }

  .control {
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 0.12rem;
    min-height: 56px;
    min-height: clamp(52px, 12svh, 76px);
    padding: 0.22rem;
    font-size: 0.79rem;
    font-weight: 700;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .control svg {
    width: 1.45rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
    pointer-events: none;
  }

  .control-attack { border-color: #6e5538; background: linear-gradient(#423425, #2c231f); color: var(--gold); }
  .control-tools button { min-height: 44px; padding: 0.25rem; color: var(--muted); font-size: 0.82rem; }
  .control:active, .control[data-pressed], .control-tools button:active { background: #34435e; transform: translateY(2px); }
  .orientation-hint { margin: 0.65rem 0 0; color: var(--muted); font-size: 0.76rem; text-align: center; }
}
