:root {
  color-scheme: dark;
  --bg: #10161d;
  --ink: #f4f1de;
  --muted: #aab3b7;
  --line: #34454d;
  --panel: rgba(16, 22, 29, 0.9);
  --panel-2: rgba(25, 34, 42, 0.9);
  --stone: #18242b;
  --stone-2: #23333a;
  --edge: #51676d;
  --edge-strong: #8aa0a0;
  --accent: #e3b44b;
  --accent-2: #67c7b4;
  --danger: #e15d59;
  --focus: #f8d56a;
  --button-shadow: rgba(0, 0, 0, 0.42);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(10, 15, 21, 0.72), rgba(10, 15, 21, 0.78)),
    url("assets/site/background.webp");
  background-position: center;
  background-size: cover;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100svh;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-content: stretch;
  justify-items: center;
  gap: 10px;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.play-surface {
  width: min(100%, 896px);
  align-self: center;
  display: grid;
  gap: 10px;
  min-width: 0;
}

.hud {
  min-height: 46px;
  display: grid;
  grid-template-columns: repeat(2, minmax(92px, max-content)) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.hud-meter,
.asset-readout {
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.hud-meter {
  min-height: 44px;
  display: grid;
  align-content: center;
  gap: 1px;
  padding: 5px 9px;
  border-radius: 6px;
}

.hud-meter span {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1;
}

.hud-meter strong {
  font-size: 1.02rem;
  line-height: 1.1;
  white-space: nowrap;
}

.hud-actions,
.share-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.command-button,
.icon-button,
.pad-button,
.action-button {
  position: relative;
  border: 1px solid var(--edge);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 38%),
    linear-gradient(180deg, #273941 0%, #16242b 58%, #0d151a 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    inset 0 -2px 0 rgba(0, 0, 0, 0.36),
    0 2px 0 #06090b,
    0 10px 18px var(--button-shadow);
  color: var(--ink);
  min-height: 40px;
  border-radius: 6px;
  cursor: pointer;
  overflow: hidden;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.72);
  touch-action: manipulation;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease,
    filter 120ms ease,
    transform 120ms ease;
}

.command-button::after,
.icon-button::after,
.pad-button::after,
.action-button::after {
  content: "";
  position: absolute;
  inset: 1px;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 4px;
  pointer-events: none;
}

.command-button {
  padding: 0 14px;
  color: #fff5cf;
  font-size: 0.86rem;
  font-weight: 700;
  white-space: nowrap;
}

.icon-button {
  width: 42px;
  flex: 0 0 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
}

.icon-button svg,
.pad-button svg,
.action-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pad-button svg,
.action-button svg {
  fill: currentColor;
  stroke: none;
}

.icon-button svg.brand-logo {
  fill: currentColor;
  stroke: none;
  stroke-width: 0;
}

.share-row .x-logo {
  width: 21px;
  height: 21px;
  color: #f7f4e8;
}

.share-row .facebook-logo {
  width: 24px;
  height: 24px;
}

.facebook-logo .facebook-disc {
  fill: #1877f2;
}

.facebook-logo .facebook-mark {
  fill: #ffffff;
}

.command-button:hover,
.icon-button:hover,
.pad-button:hover,
.action-button:hover,
.command-button:focus-visible,
.icon-button:focus-visible,
.pad-button:focus-visible,
.action-button:focus-visible {
  border-color: var(--focus);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.16),
    inset 0 -2px 0 rgba(0, 0, 0, 0.38),
    0 2px 0 #06090b,
    0 0 0 2px rgba(248, 213, 106, 0.18),
    0 12px 22px rgba(0, 0, 0, 0.48);
  filter: brightness(1.08);
  outline: none;
}

.command-button:hover,
.icon-button:hover,
.pad-button:hover,
.action-button:hover {
  transform: translateY(-1px);
}

.command-button:active,
.icon-button:active,
.pad-button:active,
.action-button:active {
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.42),
    0 1px 0 #06090b;
  filter: brightness(0.96);
  transform: translateY(1px);
}

.hud-actions .command-button {
  border-color: rgba(227, 180, 75, 0.62);
  background:
    linear-gradient(180deg, rgba(255, 239, 181, 0.18), transparent 42%),
    linear-gradient(180deg, #514328 0%, #2a261e 58%, #171614 100%);
}

.hud-actions .icon-button,
.share-row .icon-button {
  color: #cfe8df;
}

.hud-actions .icon-button:hover,
.hud-actions .icon-button:focus-visible,
.share-row .icon-button:hover,
.share-row .icon-button:focus-visible {
  color: #fff5cf;
}

.canvas-wrap {
  position: relative;
  width: min(100%, 512px);
  aspect-ratio: 4 / 3;
  justify-self: center;
  overflow: hidden;
  background: #000000;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.36);
}

#gameCanvas {
  display: block;
  aspect-ratio: 512 / 384;
  width: 100%;
  height: 100%;
  border: 1px solid #708090;
  background: #000000;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.touch-controls {
  --touch-button-height: clamp(54px, 14vw, 86px);
  --touch-gap: clamp(4px, 1.4vw, 8px);
  width: min(100%, 512px);
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  min-height: calc(var(--touch-button-height) * 2 + 16px);
}

.dpad {
  justify-self: center;
  align-self: center;
  width: min(calc(100% - 12px), 360px);
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr) minmax(0, 1.12fr);
  grid-template-rows: repeat(2, var(--touch-button-height));
  column-gap: var(--touch-gap);
  row-gap: 0;
}

.pad-button,
.action-button {
  display: grid;
  place-items: center;
  padding: 0;
  touch-action: none;
}

.pad-button {
  width: 100%;
  min-height: var(--touch-button-height);
  border-color: rgba(103, 199, 180, 0.62);
  background:
    linear-gradient(180deg, rgba(121, 223, 203, 0.16), transparent 38%),
    linear-gradient(180deg, #21393b 0%, #15262c 60%, #0c1519 100%);
  color: #aee8d8;
}

.dpad [data-command="move_up"] {
  grid-column: 2;
  grid-row: 1;
}

.dpad [data-command="move_left"] {
  grid-column: 1;
  grid-row: 1 / 3;
}

.dpad [data-command="move_right"] {
  grid-column: 3;
  grid-row: 1 / 3;
}

.dpad [data-command="move_down"] {
  grid-column: 2;
  grid-row: 2;
}

.action-pad {
  display: grid;
  place-items: center;
  border-left: 1px solid rgba(244, 241, 222, 0.2);
}

.action-button {
  width: min(calc(100% - 12px), 168px);
  height: calc(var(--touch-button-height) * 2);
  border-color: rgba(227, 180, 75, 0.82);
  background:
    radial-gradient(circle at 50% 32%, rgba(255, 233, 167, 0.18), transparent 35%),
    linear-gradient(180deg, #5b421f 0%, #322515 61%, #17110b 100%);
  color: #f4ca66;
}

body[data-touch-controls="off"] .touch-controls {
  display: none;
}

@media (min-width: 1040px) and (min-height: 790px) {
  .canvas-wrap,
  .touch-controls,
  .asset-readout {
    width: min(100%, 896px);
  }
}

.settings-grid {
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
  min-width: 0;
}

.toggle-row,
.volume-row,
.select-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-height: 34px;
  color: var(--muted);
}

.toggle-row input {
  justify-self: start;
  position: relative;
  width: 42px;
  height: 22px;
  margin: 0;
  border: 1px solid #4b5f62;
  border-radius: 999px;
  -webkit-appearance: none;
  appearance: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent),
    #0d1519;
  box-shadow:
    inset 0 2px 4px rgba(0, 0, 0, 0.52),
    0 1px 0 rgba(255, 255, 255, 0.08);
  accent-color: var(--accent-2);
  cursor: pointer;
}

.toggle-row input::before {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  inset-block-start: 2px;
  inset-inline-start: 3px;
  border-radius: 50%;
  background:
    linear-gradient(180deg, #f7f0d1, #a4aaa4);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.62),
    inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition:
    background 120ms ease,
    transform 120ms ease;
}

.toggle-row input:checked {
  border-color: rgba(103, 199, 180, 0.9);
  background:
    linear-gradient(180deg, rgba(149, 239, 220, 0.22), transparent),
    #173633;
}

.toggle-row input:checked::before {
  background:
    linear-gradient(180deg, #e8fff7, #67c7b4);
  transform: translateX(18px);
}

.toggle-row input:focus-visible {
  outline: 2px solid rgba(248, 213, 106, 0.82);
  outline-offset: 3px;
}

.volume-row {
  grid-template-columns: minmax(0, 0.56fr) minmax(70px, 1fr) 34px;
}

.volume-row span,
.select-row span {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.15;
}

.volume-row input {
  min-width: 0;
  width: 100%;
  height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
}

.volume-row input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

.volume-row input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid #42565c;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(227, 180, 75, 0.48), rgba(103, 199, 180, 0.42)),
    #0d1519;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.62);
}

.volume-row input[type="range"]::-moz-range-track {
  height: 8px;
  border: 1px solid #42565c;
  border-radius: 999px;
  background:
    linear-gradient(90deg, rgba(227, 180, 75, 0.48), rgba(103, 199, 180, 0.42)),
    #0d1519;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.62);
}

.volume-row input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 1px solid #fff0b6;
  border-radius: 4px;
  appearance: none;
  background:
    linear-gradient(180deg, #f8d56a, #9f6b25);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.56),
    inset 0 1px 0 rgba(255, 255, 255, 0.38);
}

.volume-row input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 1px solid #fff0b6;
  border-radius: 4px;
  background:
    linear-gradient(180deg, #f8d56a, #9f6b25);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.56),
    inset 0 1px 0 rgba(255, 255, 255, 0.38);
}

.volume-row output {
  text-align: right;
  color: #fff0b6;
  font-variant-numeric: tabular-nums;
}

.select-row {
  grid-template-columns: minmax(84px, 0.48fr) minmax(0, 1fr);
}

.settings-dialog .select-row {
  grid-template-columns: minmax(0, 0.56fr) minmax(70px, 1fr) 34px;
}

.settings-dialog .select-row select {
  grid-column: 2;
}

.select-row select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 45%),
    #14202a;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 1px 0 rgba(0, 0, 0, 0.42);
  color: var(--ink);
  padding: 0 8px;
}

.select-row select:focus-visible {
  border-color: var(--focus);
  outline: 2px solid rgba(248, 213, 106, 0.24);
  outline-offset: 2px;
}

.share-row {
  justify-content: center;
}

.asset-readout {
  width: min(100%, 512px);
  justify-self: center;
  min-height: 42px;
  padding: 9px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.asset-readout:empty {
  display: none;
}

.toast {
  position: fixed;
  inset-inline-start: 50%;
  inset-block-end: var(--toast-bottom, calc(env(safe-area-inset-bottom) + 18px));
  z-index: 30;
  max-width: min(calc(100vw - 28px), 360px);
  padding: 10px 14px;
  border: 1px solid rgba(248, 213, 106, 0.72);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 58%),
    rgba(16, 22, 29, 0.94);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 14px 34px rgba(0, 0, 0, 0.48);
  color: #fff5cf;
  font-size: 0.88rem;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: anywhere;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, 8px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.site-footer {
  width: min(100%, 896px);
  justify-self: center;
  display: grid;
  justify-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.2;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.72);
}

.site-footer p {
  margin: 0;
  white-space: nowrap;
}

.site-footer a {
  border-radius: 3px;
  color: var(--ink);
  text-decoration: none;
  text-underline-offset: 0.18em;
}

.site-footer a:hover {
  text-decoration: underline;
}

.site-footer a:focus-visible {
  outline: 1px solid var(--focus);
  outline-offset: 3px;
}

.settings-dialog,
.help-dialog {
  box-sizing: border-box;
  width: min(560px, calc(100vw - 28px));
  max-height: min(82dvh, 620px);
  padding: 0;
  border: 1px solid var(--edge-strong);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.07), transparent 90px),
    repeating-linear-gradient(135deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 8px),
    linear-gradient(180deg, rgba(27, 39, 45, 0.98), rgba(12, 18, 22, 0.98));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.06),
    inset 0 0 0 4px rgba(0, 0, 0, 0.18),
    0 20px 54px rgba(0, 0, 0, 0.62);
  color: var(--ink);
}

.settings-dialog {
  width: min(420px, calc(100vw - 28px));
}

.help-dialog {
  overflow: hidden;
}

.settings-dialog::backdrop,
.help-dialog::backdrop {
  background:
    linear-gradient(rgba(4, 8, 10, 0.72), rgba(4, 8, 10, 0.78)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 4px);
}

.dialog-panel,
.help-panel {
  display: grid;
  gap: 0;
  position: relative;
}

.help-panel {
  max-height: min(82dvh, 620px);
  grid-template-rows: auto auto minmax(0, 1fr);
}

.dialog-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(138, 160, 160, 0.42);
  background:
    linear-gradient(90deg, rgba(227, 180, 75, 0.18), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(0, 0, 0, 0.12));
}

.dialog-header::after {
  content: "";
  position: absolute;
  inset-inline: 14px;
  inset-block-end: -1px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(248, 213, 106, 0.72), transparent);
}

.dialog-header h1 {
  margin: 0;
  color: #fff5cf;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.1;
  text-shadow: 0 2px 3px rgba(0, 0, 0, 0.72);
}

.dialog-header .icon-button {
  width: 36px;
  min-height: 36px;
  flex-basis: 36px;
  color: #f2dbc0;
}

.dialog-header .icon-button:hover,
.dialog-header .icon-button:focus-visible {
  color: #fff5cf;
}

.settings-dialog .settings-grid {
  max-height: calc(min(82dvh, 620px) - 66px);
  overflow: auto;
}

.settings-dialog .toggle-row,
.settings-dialog .volume-row,
.settings-dialog .select-row,
.help-language-row {
  border: 1px solid rgba(81, 103, 109, 0.52);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.045), transparent),
    rgba(9, 15, 18, 0.38);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.05),
    0 1px 0 rgba(0, 0, 0, 0.28);
  padding: 8px 10px;
}

.settings-dialog .toggle-row span,
.settings-dialog .volume-row span,
.settings-dialog .select-row span,
.help-language-row span {
  color: #cdd3c8;
  font-weight: 650;
}

.help-language-row {
  margin: 12px 16px 0;
}

.help-content {
  min-height: 0;
  overflow: auto;
  padding: 14px 16px 16px;
  line-height: 1.65;
  font-family: "Yu Gothic", "Meiryo", "Segoe UI", system-ui, sans-serif;
  scrollbar-color: rgba(227, 180, 75, 0.72) rgba(9, 15, 18, 0.62);
}

.help-content p {
  margin: 0 0 0.9em;
  color: #dce0d3;
}

.help-content h2 {
  margin: 1.25em 0 0.5em;
  padding: 0.35em 0.55em;
  border: 1px solid rgba(227, 180, 75, 0.4);
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(227, 180, 75, 0.16), transparent),
    rgba(7, 12, 15, 0.42);
  color: #fff0b6;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.2;
}

.help-content ul {
  margin: 0 0 0.9em;
  padding-inline-start: 1.35em;
}

.help-content li {
  margin: 0 0 0.35em;
  color: #dce0d3;
}

.help-content li::marker {
  color: var(--accent);
}

[hidden] {
  display: none !important;
}

@media (hover: hover) and (pointer: fine) {
  body[data-touch-controls="auto"] .touch-controls {
    display: none;
  }
}

@media (min-width: 901px) and (hover: hover) and (pointer: fine) {
  body[data-touch-controls="auto"] .touch-controls {
    display: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    gap: 10px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

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

  .hud-actions {
    grid-column: 1 / -1;
  }

  .hud-actions {
    justify-content: stretch;
  }

  .hud-actions > .command-button {
    flex: 1;
  }

  .touch-controls {
    min-height: calc(var(--touch-button-height) * 2 + 12px);
  }
}

@media (min-aspect-ratio: 16 / 9) and (max-height: 540px) {
  body {
    height: 100svh;
    min-height: 100svh;
    overflow: hidden;
  }

  .app-shell {
    height: 100svh;
    grid-template-rows: minmax(0, 1fr) auto;
    align-content: stretch;
    align-items: stretch;
    gap: 4px;
    padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .play-surface {
    --landscape-canvas-width: min(52svw, 512px);
    --touch-button-height: clamp(42px, 18svh, 64px);
    width: 100%;
    height: 100%;
    grid-template-columns: minmax(96px, 1fr) minmax(0, var(--landscape-canvas-width)) minmax(96px, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    align-content: center;
    align-items: center;
    justify-items: center;
    gap: 6px 0;
  }

  .hud {
    grid-column: 1 / 4;
    width: 100%;
  }

  .canvas-wrap {
    grid-column: 2;
    grid-row: 2;
    width: var(--landscape-canvas-width);
  }

  .touch-controls {
    grid-column: 1 / 4;
    grid-row: 2;
    align-self: stretch;
    width: 100%;
    height: 100%;
    min-height: 0;
    grid-template-columns: minmax(96px, 1fr) minmax(0, var(--landscape-canvas-width)) minmax(96px, 1fr);
    pointer-events: none;
  }

  .dpad {
    grid-column: 1;
    grid-row: 1;
    align-self: end;
    justify-self: end;
    width: min(calc(100% - 8px), 220px);
    margin-inline-end: 8px;
    pointer-events: auto;
  }

  .action-pad {
    grid-column: 3;
    grid-row: 1;
    align-self: end;
    justify-self: start;
    width: min(calc(100% - 8px), 220px);
    margin-inline-start: 8px;
    border-left: 0;
    pointer-events: auto;
  }

  .action-button {
    width: min(100%, 168px);
    height: calc(var(--touch-button-height) * 2);
  }

  .asset-readout {
    display: none;
  }

  .site-footer {
    font-size: 0.68rem;
    line-height: 1;
  }

  .site-footer p {
    white-space: normal;
  }
}
