:root {
  --bg: #061111;
  --panel: rgba(8, 20, 20, 0.74);
  --panel-strong: rgba(9, 25, 24, 0.94);
  --line: rgba(116, 255, 218, 0.2);
  --line-strong: rgba(116, 255, 218, 0.42);
  --text: #eefcf7;
  --muted: #94b9b1;
  --green: #4dff9a;
  --cyan: #36e8ff;
  --gold: #ffc94a;
  --danger: #ff5f73;
  --shadow: rgba(0, 0, 0, 0.45);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

html {
  background: var(--bg);
}

body {
  min-height: 100dvh;
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(5, 24, 22, 0.9), rgba(5, 8, 12, 0.95)),
    url("assets/neon-orchard-board.png") center / cover fixed;
  overflow-x: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
select:focus-visible {
  outline: 2px solid rgba(255, 201, 74, 0.9);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  min-height: 100svh;
  margin: 0 auto;
  padding: max(28px, var(--safe-top)) 0 max(28px, var(--safe-bottom));
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
}

.masthead {
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(4, 16, 15, 0.66);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 48px var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 14px;
}

.brand-mark {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 0 28px rgba(54, 232, 255, 0.24);
}

.kicker,
.overlay-kicker {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.65rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.top-stats {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.top-stats div,
.metric {
  min-width: 96px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(4, 16, 15, 0.6);
}

.top-stats span,
.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.top-stats strong,
.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 1.36rem;
  line-height: 1;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.stage {
  position: relative;
  aspect-ratio: 1;
  min-height: 360px;
  border: 1px solid var(--line-strong);
  background: #081313;
  box-shadow: 0 24px 70px var(--shadow), 0 0 0 1px rgba(255, 255, 255, 0.03) inset;
  overflow: hidden;
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0.035), transparent 34%, rgba(0, 0, 0, 0.18));
  mix-blend-mode: screen;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, rgba(8, 36, 32, 0.55), rgba(2, 8, 9, 0.78) 66%);
}

.overlay.is-visible {
  display: flex;
}

.overlay-panel {
  width: min(360px, 100%);
  padding: 22px;
  border: 1px solid var(--line-strong);
  background: var(--panel-strong);
  box-shadow: 0 22px 60px var(--shadow);
  text-align: center;
}

.overlay-mark {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 12px;
}

.overlay h2 {
  margin: 0;
  font-size: clamp(1.65rem, 4vw, 2.4rem);
  line-height: 1;
  letter-spacing: 0;
}

.overlay p {
  color: var(--muted);
}

.primary-action {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 8px;
  color: #031111;
  background: linear-gradient(135deg, var(--gold), #fff06f);
  font-weight: 900;
  box-shadow: 0 10px 30px rgba(255, 201, 74, 0.26);
}

.control-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 48px var(--shadow);
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  min-width: 0;
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.icon-button,
.dpad button {
  min-height: 48px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: rgba(9, 30, 28, 0.86);
  font-size: 1.35rem;
  font-weight: 900;
}

.icon-button:hover,
.dpad button:hover,
.icon-button.is-active {
  border-color: rgba(255, 201, 74, 0.82);
  color: var(--gold);
  box-shadow: 0 0 22px rgba(255, 201, 74, 0.16) inset;
}

.setting-block {
  display: grid;
  gap: 8px;
}

.setting-block label {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.setting-block select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: #081b19;
  padding: 0 10px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 8px;
}

.dpad [data-dir="up"] {
  grid-area: up;
}

.dpad [data-dir="left"] {
  grid-area: left;
}

.dpad [data-dir="down"] {
  grid-area: down;
}

.dpad [data-dir="right"] {
  grid-area: right;
}

@media (max-width: 920px) {
  .app-shell {
    width: min(100vw - 18px - var(--safe-left) - var(--safe-right), 680px);
    padding-top: max(12px, var(--safe-top));
    padding-bottom: max(12px, var(--safe-bottom));
  }

  .masthead,
  .game-layout {
    grid-template-columns: 1fr;
  }

  .masthead {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-stats {
    width: 100%;
  }

  .top-stats div {
    flex: 1;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .app-shell {
    width: calc(100vw - 12px - var(--safe-left) - var(--safe-right));
    gap: 10px;
  }

  .masthead {
    min-height: 76px;
    gap: 12px;
    padding: 10px;
  }

  .brand-mark {
    width: 54px;
    height: 54px;
  }

  .top-stats strong,
  .metric strong {
    font-size: 1.14rem;
  }

  .stage {
    min-height: auto;
  }

  .control-panel {
    gap: 10px;
    padding: 10px;
  }

  .score-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .metric {
    min-width: 0;
    padding: 8px;
  }

  .tool-row,
  .dpad {
    gap: 8px;
  }

  .icon-button,
  .dpad button {
    min-height: 44px;
  }

  .overlay {
    padding: 16px;
  }

  .overlay-panel {
    padding: 18px;
  }
}

@media (orientation: landscape) and (max-height: 620px) and (min-width: 760px) {
  .app-shell {
    width: min(1120px, calc(100vw - 20px - var(--safe-left) - var(--safe-right)));
    padding-top: max(10px, var(--safe-top));
    padding-bottom: max(10px, var(--safe-bottom));
    gap: 10px;
  }

  .masthead {
    min-height: 68px;
    padding: 8px 10px;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
  }

  .game-layout {
    grid-template-columns: minmax(0, calc(100vh - 94px)) 300px;
    align-items: start;
  }

  .stage {
    min-height: auto;
    max-height: calc(100vh - 94px);
  }
}

@media (display-mode: standalone) {
  body {
    background-attachment: scroll;
  }
}

@media (prefers-reduced-motion: reduce) {
  .stage::after {
    display: none;
  }
}
