:root {
  color-scheme: dark;
  --bg: #080c0d;
  --panel: #101817;
  --panel-2: #15231e;
  --line: #355146;
  --text: #eef8f1;
  --muted: #acc2b8;
  --accent: #d8b95f;
  --danger: #c95b57;
  --control: #1c332b;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
  -webkit-user-select: none;
  user-select: none;
}

body {
  position: relative;
  isolation: isolate;
  min-height: 100svh;
  color: var(--text);
  background: #080c0d;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  letter-spacing: 0;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

body::before {
  z-index: -2;
  background: url("assets/generated/page-background.webp") center / cover no-repeat;
  filter: saturate(1.14) contrast(1.08) brightness(0.94);
  transform: scale(1.02);
}

body::after {
  z-index: -1;
  background: linear-gradient(rgba(4, 8, 9, 0.06), rgba(4, 8, 9, 0.28));
}

button,
select,
input {
  font: inherit;
}

input,
select,
textarea {
  -webkit-user-select: auto;
  user-select: auto;
}

button {
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--text);
  min-height: 40px;
  border-radius: 6px;
  padding: 0 12px;
  cursor: pointer;
}

button:disabled {
  border-color: rgba(172, 194, 184, 0.34);
  background: rgba(28, 51, 43, 0.72);
  color: rgba(172, 194, 184, 0.78);
  cursor: not-allowed;
  opacity: 0.88;
}

button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.topbar {
  width: min(100%, 1120px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  text-shadow: 0 2px 0 #000;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.tool-button {
  min-width: 84px;
}

.game-shell {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  min-height: 0;
}

.canvas-wrap {
  position: relative;
  width: min(100%, 512px);
  aspect-ratio: 4 / 3;
  background: #000;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  touch-action: none;
}

#game-canvas[data-main-state="2"],
#game-canvas[data-main-state="6"] {
  image-rendering: auto;
}

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

.status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  background: rgba(0, 0, 0, 0.72);
  color: var(--text);
  font-size: 16px;
  text-align: center;
  padding: 16px;
}

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

body[data-touch-controls="off"]:not([data-touch-action-button="give-up"]) .touch-controls {
  display: none;
}

body[data-touch-controls="off"][data-touch-action-button="give-up"] .touch-controls {
  position: fixed;
  top: var(--floating-touch-top, calc(50svh + 8px));
  left: var(--floating-touch-left, 50vw);
  z-index: 10;
  width: auto;
  grid-template-columns: minmax(0, 1fr);
  justify-items: stretch;
  min-height: 0;
  transform: translateX(-50%);
  pointer-events: none;
}

body[data-touch-controls="off"][data-touch-action-button="give-up"] .dpad {
  display: none;
}

body[data-touch-controls="off"][data-touch-action-button="give-up"] .action-pad {
  grid-column: 1;
  width: auto;
  margin-inline: 0;
  border-left: 0;
  pointer-events: auto;
}

body[data-touch-controls="off"][data-touch-action-button="give-up"] .action-button {
  width: auto;
  min-width: 96px;
  height: 40px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 16px;
}

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

  body[data-touch-controls="auto"][data-touch-action-button="give-up"] .touch-controls {
    position: fixed;
    top: var(--floating-touch-top, calc(50svh + 8px));
    left: var(--floating-touch-left, 50vw);
    z-index: 10;
    width: auto;
    grid-template-columns: minmax(0, 1fr);
    justify-items: stretch;
    min-height: 0;
    transform: translateX(-50%);
    pointer-events: none;
  }

  body[data-touch-controls="auto"][data-touch-action-button="give-up"] .dpad {
    display: none;
  }

  body[data-touch-controls="auto"][data-touch-action-button="give-up"] .action-pad {
    grid-column: 1;
    width: auto;
    margin-inline: 0;
    border-left: 0;
    pointer-events: auto;
  }

  body[data-touch-controls="auto"][data-touch-action-button="give-up"] .action-button {
    width: auto;
    min-width: 96px;
    height: 40px;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 6px;
    font-size: 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;
}

.dpad button {
  width: 100%;
  min-height: var(--touch-button-height);
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

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

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

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

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

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

.action-button {
  width: min(calc(100% - 12px), 168px);
  height: calc(var(--touch-button-height) * 2);
  padding: 0 14px;
  border-radius: 8px;
  background: #5b1f21;
  border-color: #c95b57;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
}

.action-button:disabled {
  border-color: rgba(201, 91, 87, 0.5);
  background: rgba(91, 31, 33, 0.74);
  color: rgba(238, 248, 241, 0.74);
}

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

@media (min-aspect-ratio: 16 / 9) and (max-height: 540px) {
  body {
    height: 100svh;
    min-height: 100svh;
    overflow: hidden;
    gap: 6px;
    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));
  }

  .topbar {
    align-items: center;
    gap: 8px;
  }

  .topbar h1 {
    font-size: 14px;
    line-height: 1.15;
    max-width: 118px;
  }

  .toolbar {
    gap: 6px;
  }

  .tool-button {
    min-width: 64px;
    min-height: 34px;
    padding: 0 8px;
  }

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

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

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

  .dpad {
    grid-column: 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;
    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);
  }
}

.ios-hint {
  width: min(100%, 760px);
  margin: 0 auto;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

dialog {
  width: min(94vw, 460px);
  max-height: calc(100svh - 24px);
  border: 1px solid rgba(216, 185, 95, 0.36);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(26, 45, 38, 0.96), rgba(9, 14, 15, 0.98)),
    var(--panel);
  box-shadow:
    0 24px 72px rgba(0, 0, 0, 0.58),
    inset 0 1px 0 rgba(238, 248, 241, 0.08);
  color: var(--text);
  overflow: auto;
  padding: 18px;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(216, 185, 95, 0.22);
  margin: -2px 0 14px;
  padding-bottom: 12px;
}

.dialog-head h2 {
  margin: 0;
  color: var(--accent);
  font-size: 20px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.55);
}

.icon-button {
  width: 36px;
  min-height: 36px;
  border-color: rgba(216, 185, 95, 0.28);
  background: rgba(21, 35, 30, 0.92);
  padding: 0;
}

.menu-grid {
  display: grid;
  gap: 10px;
}

.menu-command {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  color: var(--text);
  font-weight: 700;
  text-align: left;
}

.menu-link {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  padding: 0 12px;
  text-decoration: none;
}

.menu-command kbd {
  min-width: 34px;
  border: 1px solid rgba(216, 185, 95, 0.32);
  border-radius: 6px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.24);
  color: #fff2b8;
  font: 700 12px/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace;
  text-align: center;
}

.shortcut-list {
  display: inline-flex;
  gap: 6px;
}

.menu-command:disabled kbd {
  border-color: rgba(172, 194, 184, 0.16);
  background: rgba(0, 0, 0, 0.14);
  color: rgba(172, 194, 184, 0.42);
}

.dialog-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.help-text {
  display: grid;
  gap: 10px;
  color: var(--muted);
}

.help-section {
  display: grid;
  gap: 8px;
}

.help-section h3 {
  margin: 0;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.help-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.help-link-row {
  margin: 0;
  overflow-wrap: anywhere;
}

.help-link-row a {
  color: var(--accent);
}

.help-language-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(142px, 188px);
  align-items: center;
  gap: 14px;
  color: var(--text);
}

.help-language-row span {
  overflow-wrap: anywhere;
}

.about-title {
  margin: 0;
  font-weight: 700;
}

#settings-form {
  display: grid;
  gap: 10px;
}

#settings-form label,
.switch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(142px, 188px);
  align-items: center;
  gap: 14px;
}

.menu-command,
.share-option,
.help-section,
#settings-form label {
  min-height: 54px;
  border: 1px solid rgba(216, 185, 95, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(238, 248, 241, 0.055), rgba(8, 12, 13, 0.02)),
    rgba(21, 35, 30, 0.86);
  box-shadow: inset 0 1px 0 rgba(238, 248, 241, 0.08);
  padding: 10px 12px;
}

#settings-form label > span:first-child {
  min-width: 0;
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

#settings-form input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-width: 0;
  height: 24px;
  background: transparent;
  accent-color: var(--accent);
}

#settings-form input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  border: 1px solid rgba(216, 185, 95, 0.2);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(216, 185, 95, 0.42), rgba(90, 137, 115, 0.62));
}

#settings-form input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border: 2px solid #fff2b8;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

#settings-form input[type="range"]::-moz-range-track {
  height: 8px;
  border: 1px solid rgba(216, 185, 95, 0.2);
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(216, 185, 95, 0.42), rgba(90, 137, 115, 0.62));
}

#settings-form input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid #fff2b8;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}

.switch-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

#settings-form input[type="checkbox"] {
  appearance: none;
  position: relative;
  width: 52px;
  height: 30px;
  border: 1px solid rgba(172, 194, 184, 0.34);
  border-radius: 999px;
  background: rgba(8, 12, 13, 0.58);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

#settings-form input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.48);
  transition: transform 0.16s ease, background 0.16s ease;
}

#settings-form input[type="checkbox"]:checked {
  border-color: rgba(216, 185, 95, 0.68);
  background: linear-gradient(90deg, rgba(147, 95, 45, 0.88), rgba(216, 185, 95, 0.9));
}

#settings-form input[type="checkbox"]:checked::before {
  background: #fff2b8;
  transform: translateX(22px);
}

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

.volume-control {
  direction: ltr;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.volume-control output {
  display: inline-grid;
  min-height: 30px;
  border: 1px solid rgba(216, 185, 95, 0.32);
  border-radius: 6px;
  place-items: center;
  background: rgba(0, 0, 0, 0.24);
  color: #fff2b8;
  font: 700 14px/1 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

#settings-form select,
.help-language-row select {
  width: 100%;
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid rgba(216, 185, 95, 0.24);
  background: rgba(8, 12, 13, 0.44);
  color: var(--text);
  padding: 0 8px;
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.share-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
}

.share-option svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: currentColor;
}

.share-option span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.copy-status {
  margin: 10px 0 0;
  color: var(--accent);
  min-height: 20px;
}

@media (max-width: 540px) {
  body {
    gap: 8px;
  }

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

  .topbar h1 {
    font-size: 16px;
    max-width: 128px;
    line-height: 1.2;
  }

  .tool-button {
    min-width: 72px;
    padding: 0 8px;
  }

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

  dialog {
    padding: 14px;
  }

  #settings-form label,
  .help-language-row,
  .volume-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .share-grid {
    grid-template-columns: 1fr;
  }

  .switch-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .volume-control {
    grid-template-columns: 42px minmax(0, 1fr);
  }
}
