:root {
  color-scheme: dark;
  --ink: #f3f1e8;
  --muted: #a9b8af;
  --page: #081513;
  --panel: #102320;
  --panel-strong: #162d28;
  --teal: #4fc4a4;
  --amber: #f2c66d;
  --coral: #ec7e67;
  --line: rgba(213, 233, 222, 0.14);
  --shadow: rgba(1, 8, 7, 0.72);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--page);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 8%, rgba(79, 196, 164, 0.14), transparent 28rem),
    radial-gradient(circle at 88% 90%, rgba(242, 198, 109, 0.1), transparent 30rem),
    linear-gradient(145deg, #0b1b18 0%, var(--page) 48%, #06110f 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  pointer-events: none;
  opacity: 0.22;
  background-image:
    linear-gradient(rgba(212, 235, 223, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(212, 235, 223, 0.045) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-mask-image: linear-gradient(to bottom, black, transparent 82%);
  mask-image: linear-gradient(to bottom, black, transparent 82%);
}

button,
canvas {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 20;
  padding: 0.65rem 0.85rem;
  color: #07120f;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
  background: var(--amber);
  border-radius: 0.55rem;
  transform: translateY(-160%);
  transition: transform 140ms ease;
}

.skip-link:focus {
  transform: translateY(0);
}

.page-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(0.65rem, 1.4vh, 1rem);
  width: min(100%, 1600px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding:
    max(0.75rem, env(safe-area-inset-top))
    max(0.75rem, env(safe-area-inset-right))
    max(0.75rem, env(safe-area-inset-bottom))
    max(0.75rem, env(safe-area-inset-left));
}

.topbar,
.page-footer {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar {
  justify-content: space-between;
  min-height: 3.25rem;
}

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

.brand-mark {
  position: relative;
  flex: 0 0 auto;
  width: 2.65rem;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid rgba(242, 198, 109, 0.42);
  border-radius: 0.78rem;
  background:
    linear-gradient(var(--amber), var(--amber)) center / 0.42rem 100% no-repeat,
    linear-gradient(90deg, var(--amber), var(--amber)) center / 100% 0.42rem no-repeat,
    var(--panel-strong);
  box-shadow:
    inset 0 0 0 0.28rem rgba(7, 20, 17, 0.74),
    0 8px 24px rgba(2, 10, 8, 0.34);
}

.brand-mark::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0.52rem;
  aspect-ratio: 1;
  content: "";
  background: var(--coral);
  border: 2px solid var(--panel-strong);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.brand-copy {
  display: grid;
  min-width: 0;
  gap: 0.12rem;
}

.brand-copy strong {
  overflow: hidden;
  font-size: clamp(1rem, 2vw, 1.22rem);
  line-height: 1.05;
  letter-spacing: -0.025em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-copy > span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.5rem;
}

.control-chip,
.fullscreen-button {
  min-height: 2.35rem;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: rgba(15, 35, 31, 0.78);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.025);
}

.control-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.62rem 0.35rem 0.4rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

kbd {
  min-width: 1.75rem;
  padding: 0.28rem 0.38rem;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1;
  text-align: center;
  background: var(--panel-strong);
  border: 1px solid rgba(238, 245, 240, 0.17);
  border-bottom-color: rgba(238, 245, 240, 0.34);
  border-radius: 0.38rem;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.28);
}

.fullscreen-button {
  display: inline-flex;
  align-items: center;
  gap: 0.48rem;
  padding: 0.35rem 0.68rem;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 750;
  cursor: pointer;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    transform 140ms ease;
}

.fullscreen-button svg {
  width: 1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.fullscreen-button:not(:disabled):hover {
  background: rgba(27, 62, 54, 0.92);
  border-color: rgba(79, 196, 164, 0.5);
  transform: translateY(-1px);
}

.fullscreen-button:focus-visible,
.focus-hint:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 3px;
}

.fullscreen-button:disabled {
  cursor: wait;
  opacity: 0.42;
}

.game-stage {
  display: grid;
  min-height: 0;
  place-items: center;
}

.unity-container {
  position: relative;
  isolation: isolate;
  width: min(100%, calc((100svh - 9.25rem) * var(--game-ratio)));
  max-width: 100%;
  aspect-ratio: var(--game-aspect);
  overflow: hidden;
  background: #0b1816;
  border: 1px solid rgba(214, 235, 224, 0.18);
  border-radius: clamp(0.8rem, 1.6vw, 1.2rem);
  box-shadow:
    0 2px 0 rgba(255, 255, 255, 0.04) inset,
    0 24px 80px var(--shadow),
    0 0 0 0.3rem rgba(9, 25, 21, 0.78);
}

.unity-container::after {
  position: absolute;
  inset: 0;
  z-index: 5;
  content: "";
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.035);
  border-radius: inherit;
}

#unity-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  background: #152823;
  outline: none;
}

#unity-canvas:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: -4px;
}

.loading-panel {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  grid-template-columns: auto minmax(0, 24rem);
  align-content: center;
  justify-content: center;
  gap: 0.85rem 1rem;
  padding: 1.5rem;
  background:
    radial-gradient(circle at center, rgba(35, 76, 66, 0.9), rgba(8, 21, 18, 0.96) 58%),
    #081512;
}

.loading-mark {
  grid-row: 1 / span 2;
  align-self: center;
  width: 2.85rem;
  aspect-ratio: 1;
  border: 1px solid rgba(242, 198, 109, 0.32);
  border-radius: 0.82rem;
  background:
    linear-gradient(var(--amber), var(--amber)) center / 0.34rem 100% no-repeat,
    linear-gradient(90deg, var(--amber), var(--amber)) center / 100% 0.34rem no-repeat,
    rgba(13, 34, 29, 0.8);
  box-shadow: inset 0 0 0 0.35rem rgba(8, 21, 18, 0.82);
  animation: loading-pulse 1.45s ease-in-out infinite;
}

.loading-copy {
  display: grid;
  align-self: end;
  min-width: 0;
  gap: 0.25rem;
}

.loading-copy strong {
  font-size: clamp(0.96rem, 2vw, 1.12rem);
  letter-spacing: -0.015em;
}

.loading-copy span {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.loading-progress-row {
  display: flex;
  align-self: start;
  align-items: center;
  gap: 0.65rem;
  min-width: 15rem;
}

.progress-track {
  flex: 1 1 auto;
  height: 0.42rem;
  overflow: hidden;
  background: rgba(226, 239, 232, 0.12);
  border: 1px solid rgba(226, 239, 232, 0.08);
  border-radius: 999px;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--amber));
  border-radius: inherit;
  box-shadow: 0 0 1rem rgba(79, 196, 164, 0.34);
  transition: width 160ms ease-out;
}

.loading-percent {
  width: 2.6rem;
  color: var(--muted);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  text-align: right;
}

.unity-container[data-state="error"] .loading-mark {
  border-color: rgba(236, 126, 103, 0.46);
  background:
    linear-gradient(var(--coral), var(--coral)) center / 0.34rem 100% no-repeat,
    linear-gradient(90deg, var(--coral), var(--coral)) center / 100% 0.34rem no-repeat,
    rgba(13, 34, 29, 0.8);
  animation: none;
}

.unity-container[data-state="error"] .loading-copy span {
  max-width: min(28rem, 70vw);
  color: #efc5bc;
  white-space: normal;
}

.unity-warning {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  z-index: 8;
  display: grid;
  width: min(90%, 42rem);
  gap: 0.4rem;
  pointer-events: none;
  transform: translateX(-50%);
}

.unity-message {
  padding: 0.65rem 0.8rem;
  font-size: 0.72rem;
  line-height: 1.4;
  border: 1px solid;
  border-radius: 0.65rem;
  box-shadow: 0 12px 32px rgba(1, 8, 7, 0.44);
  backdrop-filter: blur(12px);
}

.unity-message--warning {
  color: #f7e7bd;
  background: rgba(83, 61, 18, 0.9);
  border-color: rgba(242, 198, 109, 0.46);
}

.unity-message--error {
  color: #ffe0da;
  background: rgba(88, 31, 24, 0.92);
  border-color: rgba(236, 126, 103, 0.58);
}

.focus-hint {
  position: absolute;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 7;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: calc(100% - 1.5rem);
  min-height: 2rem;
  padding: 0.38rem 0.62rem;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.68rem;
  font-weight: 720;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  background: rgba(5, 15, 13, 0.84);
  border: 1px solid rgba(240, 246, 242, 0.18);
  border-radius: 999px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(10px);
  transition:
    background 140ms ease,
    border-color 140ms ease,
    opacity 140ms ease;
}

.focus-hint:hover {
  background: rgba(16, 43, 36, 0.94);
  border-color: rgba(79, 196, 164, 0.42);
}

.focus-dot,
.note-dot {
  flex: 0 0 auto;
  width: 0.45rem;
  aspect-ratio: 1;
  background: var(--amber);
  border-radius: 50%;
  box-shadow: 0 0 0 0.18rem rgba(242, 198, 109, 0.14);
}

.focus-hint.is-focused {
  color: #ccefe4;
  border-color: rgba(79, 196, 164, 0.36);
}

.focus-hint.is-focused .focus-dot {
  background: var(--teal);
  box-shadow: 0 0 0 0.18rem rgba(79, 196, 164, 0.15);
}

.noscript-message {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  padding: 2rem;
  color: #ffe0da;
  text-align: center;
  background: #0b1816;
  place-items: center;
}

.page-footer {
  justify-content: center;
  min-width: 0;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.3;
}

.prototype-note,
.data-note {
  margin: 0;
}

.prototype-note {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.38rem;
  padding: 0.38rem 0.62rem;
  color: #f5e4ba;
  background: rgba(74, 55, 18, 0.36);
  border: 1px solid rgba(242, 198, 109, 0.22);
  border-radius: 999px;
}

.prototype-note .note-dot {
  width: 0.36rem;
}

.data-note {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.keyboard-note {
  display: none;
  flex: 0 0 auto;
  color: #c7d4cd;
}

@keyframes loading-pulse {
  0%,
  100% {
    filter: brightness(0.86);
    transform: scale(0.96);
  }

  50% {
    filter: brightness(1.12);
    transform: scale(1);
  }
}

@media (max-width: 760px) {
  .page-shell {
    gap: 0.6rem;
    padding:
      max(0.6rem, env(safe-area-inset-top))
      max(0.6rem, env(safe-area-inset-right))
      max(0.6rem, env(safe-area-inset-bottom))
      max(0.6rem, env(safe-area-inset-left));
  }

  .topbar {
    align-items: flex-start;
  }

  .brand-mark {
    width: 2.35rem;
    border-radius: 0.68rem;
  }

  .brand-copy > span,
  .control-chip > span,
  .fullscreen-button > span,
  .data-note {
    display: none;
  }

  .game-actions {
    gap: 0.35rem;
  }

  .control-chip,
  .fullscreen-button {
    min-height: 2.15rem;
  }

  .control-chip {
    padding: 0.3rem;
  }

  .fullscreen-button {
    padding: 0.42rem 0.52rem;
  }

  .fullscreen-button svg {
    width: 1.05rem;
  }

  .unity-container {
    width: 100%;
    border-radius: 0.75rem;
  }

  .loading-panel {
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.7rem;
    padding: 1rem;
  }

  .loading-mark {
    width: 2.35rem;
  }

  .loading-progress-row {
    min-width: 0;
  }

  .page-footer {
    justify-content: space-between;
    gap: 0.55rem;
  }

  .prototype-note {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .keyboard-note {
    display: inline;
  }
}

@media (max-width: 430px) {
  .brand-copy strong {
    max-width: 8.5rem;
  }

  .prototype-note > span[aria-hidden="true"] {
    display: none;
  }

  .prototype-note > span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .keyboard-note {
    display: none;
  }
}

@media (max-height: 650px) and (orientation: landscape) {
  .page-shell {
    gap: 0.4rem;
    padding-top: max(0.4rem, env(safe-area-inset-top));
    padding-bottom: max(0.4rem, env(safe-area-inset-bottom));
  }

  .topbar {
    min-height: 2.45rem;
  }

  .brand-mark {
    width: 2.2rem;
  }

  .brand-copy > span,
  .control-chip > span,
  .fullscreen-button > span,
  .data-note {
    display: none;
  }

  .control-chip,
  .fullscreen-button {
    min-height: 2rem;
  }

  .control-chip {
    padding: 0.25rem 0.32rem;
  }

  .fullscreen-button {
    padding: 0.35rem 0.48rem;
  }

  .unity-container {
    width: min(100%, calc((100svh - 6.3rem) * var(--game-ratio)));
  }

  .page-footer {
    min-height: 1.7rem;
  }
}

@media (pointer: coarse) {
  .keyboard-note {
    display: inline;
  }
}

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