:root {
  color-scheme: dark;
  --ink: #e9fbff;
  --muted: #83a0b3;
  --panel: rgba(8, 22, 38, 0.88);
  --line: rgba(113, 229, 255, 0.2);
  --cyan: #5ff4ff;
  --blue: #3478ff;
  --pink: #ff4f9d;
  --yellow: #ffe273;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
  overflow-x: clip;
  overscroll-behavior: none;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 12%, rgba(27, 107, 175, 0.25), transparent 34rem),
    radial-gradient(circle at 83% 72%, rgba(113, 34, 151, 0.18), transparent 32rem),
    #030812;
  color: var(--ink);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button,
canvas,
a {
  -webkit-touch-callout: none;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--yellow);
  outline-offset: 3px;
}

.shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) clamp(12px, 3vw, 28px) max(28px, env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: minmax(92px, 1fr) auto minmax(92px, 1fr);
  align-items: end;
  gap: 16px;
  margin-bottom: 14px;
}

.home-link {
  align-self: center;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-decoration: none;
}

.home-link:hover {
  color: var(--cyan);
}

.title-lockup {
  text-align: center;
}

.title-lockup p {
  margin: 0 0 2px;
  color: var(--cyan);
  font-size: clamp(0.58rem, 1.5vw, 0.72rem);
  font-weight: 800;
  letter-spacing: 0.22em;
}

.title-lockup h1 {
  margin: 0;
  font-size: clamp(1.45rem, 4vw, 2.55rem);
  letter-spacing: -0.055em;
  line-height: 1;
  text-shadow: 0 0 28px rgba(95, 244, 255, 0.24);
}

.title-lockup h1 span {
  color: var(--muted);
  font-size: 0.54em;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.tools {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--cyan);
  background: rgba(21, 59, 83, 0.9);
}

.hud {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  margin-bottom: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--line);
}

.hud > div {
  min-width: 0;
  padding: 8px 9px;
  background: rgba(6, 17, 31, 0.96);
  text-align: center;
}

.hud span {
  display: block;
  margin-bottom: 1px;
  color: var(--muted);
  font-size: clamp(0.5rem, 1.7vw, 0.64rem);
  font-weight: 800;
  letter-spacing: 0.11em;
}

.hud strong {
  display: block;
  overflow: hidden;
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: clamp(0.72rem, 2.3vw, 1rem);
  text-overflow: ellipsis;
  white-space: nowrap;
}

#landValue {
  color: var(--cyan);
}

#lifeValue {
  color: var(--pink);
  letter-spacing: 0.08em;
}

.game-frame {
  position: relative;
  isolation: isolate;
  width: 100%;
  overflow: hidden;
  border: 1px solid rgba(95, 244, 255, 0.42);
  border-radius: 18px;
  aspect-ratio: 3 / 2;
  background: #02060d;
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.46),
    0 0 0 1px rgba(95, 244, 255, 0.07) inset,
    0 0 42px rgba(52, 120, 255, 0.12);
}

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

.scanline {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, transparent 0 3px, rgba(84, 203, 255, 0.025) 3px 4px);
  mix-blend-mode: screen;
}

.overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: clamp(18px, 6vw, 60px);
  background:
    radial-gradient(circle at center, rgba(8, 30, 49, 0.78), rgba(2, 7, 14, 0.96) 72%);
  text-align: center;
  transition: opacity 180ms ease, visibility 180ms ease;
}

.overlay.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.overlay > p:first-child {
  margin: 0 0 11px;
  color: var(--cyan);
  font-family: ui-monospace, monospace;
  font-size: clamp(0.62rem, 2vw, 0.78rem);
  font-weight: 800;
  letter-spacing: 0.17em;
}

.overlay h2 {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 3.45rem);
  letter-spacing: -0.065em;
  line-height: 1.03;
}

.overlay > p:nth-of-type(2) {
  max-width: 580px;
  margin: 14px 0 22px;
  color: #a7bdca;
  font-size: clamp(0.72rem, 2.1vw, 0.98rem);
  line-height: 1.65;
  word-break: keep-all;
}

.overlay button {
  min-width: 150px;
  min-height: 46px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--cyan), #75a7ff);
  color: #02101b;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 0 36px rgba(95, 244, 255, 0.28);
}

.overlay button:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.status-row {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 3px 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.status-row p {
  margin: 0;
}

#message {
  color: #b8ced9;
}

kbd {
  padding: 2px 5px;
  border: 1px solid rgba(155, 207, 226, 0.35);
  border-radius: 4px;
  background: #0d1b29;
  color: var(--ink);
  font: 0.68rem ui-monospace, monospace;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset;
}

.mobile-controls {
  display: none;
  grid-template-areas:
    ". up ."
    "left center right"
    ". down .";
  grid-template-columns: repeat(3, 54px);
  justify-content: center;
  gap: 6px;
  margin: 10px auto 0;
  touch-action: none;
}

.move {
  width: 54px;
  height: 44px;
  border: 1px solid rgba(95, 244, 255, 0.26);
  border-radius: 12px;
  background: linear-gradient(180deg, #142b40, #0a1827);
  color: #c8faff;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 0 #030a12;
}

.move:active,
.move.active {
  transform: translateY(3px);
  border-color: var(--cyan);
  box-shadow: 0 1px 0 #030a12, 0 0 20px rgba(95, 244, 255, 0.2);
}

.up { grid-area: up; }
.left { grid-area: left; }
.center { grid-area: center; color: var(--pink); }
.right { grid-area: right; }
.down { grid-area: down; }

.instructions {
  margin: 15px 2px 0;
  border-top: 1px solid rgba(116, 171, 195, 0.16);
  color: var(--muted);
  font-size: 0.78rem;
}

.instructions summary {
  width: max-content;
  padding: 13px 0 5px;
  color: #a8c7d6;
  cursor: pointer;
  font-weight: 800;
}

.instructions div {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.instructions p {
  margin: 4px 0;
  line-height: 1.55;
}

.instructions strong {
  color: var(--cyan);
}

@media (max-width: 760px), (pointer: coarse) {
  .shell {
    padding-inline: 10px;
  }

  .topbar {
    grid-template-columns: 62px 1fr auto;
    gap: 7px;
    margin-bottom: 9px;
  }

  .home-link {
    font-size: 0.58rem;
  }

  .tools {
    gap: 4px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 0.82rem;
  }

  .hud {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .hud > div {
    padding: 6px 2px;
  }

  .game-frame {
    border-radius: 12px;
  }

  .mobile-controls {
    display: grid;
  }

  .key-hint {
    display: none;
  }

  .status-row {
    justify-content: center;
    min-height: 32px;
    text-align: center;
  }

  .instructions div {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media (max-width: 430px) {
  .title-lockup h1 span {
    display: block;
    margin-top: 3px;
  }

  .hud > div:nth-child(3),
  .hud > div:nth-child(7) {
    display: none;
  }

  .hud {
    grid-template-columns: repeat(5, 1fr);
  }

  .overlay {
    padding: 16px 22px;
  }

  .overlay > p:nth-of-type(2) {
    margin-block: 9px 13px;
    line-height: 1.45;
  }

  .overlay button {
    min-height: 40px;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 176px;
    grid-template-areas:
      "top controls"
      "hud controls"
      "game controls"
      "status controls";
    gap: 5px 12px;
    width: min(930px, 100%);
    padding-block: 6px;
  }

  .topbar { grid-area: top; margin: 0; }
  .hud { grid-area: hud; margin: 0; }
  .game-frame { grid-area: game; max-height: calc(100vh - 118px); justify-self: center; }
  .status-row { grid-area: status; }
  .mobile-controls { grid-area: controls; align-self: center; }
  .instructions { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
