:root {
  --app-shell-scale: 1;
  --cog-yellow: #f4d66d;
  --cog-blue: #89b6ff;
  --cog-mint: #90dec9;
  --cog-pink: #f4accd;

  --ink: #1f2430;
  --ink-soft: #2f3647;
  --ink-muted: #546078;
  --white: #ffffff;
  --fog: #f2f5f8;
  --chip-dot: var(--cog-blue);

  --focus: #27395a;
  --panel-border: 2px solid var(--ink);
  --radius-soft: 18px;
  --radius-large: 24px;
  --space-1: 0.5rem;
  --space-2: 0.75rem;
  --space-3: 1rem;
  --space-4: 1.25rem;
  --space-5: 1.5rem;

  --surface-shadow: 0 12px 30px rgba(31, 36, 48, 0.1);
  --surface-shadow-soft: 0 8px 18px rgba(31, 36, 48, 0.06);
  --surface-shadow-tight: 0 6px 16px rgba(31, 36, 48, 0.08);
  --shadow: 0 10px 24px rgba(31, 36, 48, 0.1);
  --overlay-backdrop: rgba(242, 245, 248, 0.74);
  --header-bg: linear-gradient(180deg, #ffffff 0%, var(--fog) 100%);
  --anim-duration: 120ms;
  --anim-ease: cubic-bezier(0.2, 0.9, 0.2, 1);
}

* {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  transition-property: border-color, background-color, color, box-shadow, transform;
  transition-duration: var(--anim-duration);
  transition-timing-function: var(--anim-ease);
}

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

body {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 25% -10%, #ffffff 0%, rgba(242, 245, 248, 0.56) 45%, var(--fog) 100%),
    var(--fog);
  display: grid;
  place-items: center;
  padding: var(--space-3) var(--space-3) var(--space-4);
  min-height: 100vh;
  overflow: hidden;
}

.app-shell {
  width: min(96vw, 1380px);
  border: 3px solid var(--ink);
  border-radius: var(--radius-large);
  background: var(--white);
  box-shadow: var(--surface-shadow);
  overflow: hidden;
  position: relative;
}

.app-header,
.app-footer {
  padding: var(--space-3) var(--space-4);
  background: var(--header-bg);
  border-bottom: 2px solid var(--ink);
}

.app-header {
  padding: 0.68rem 1rem 0.5rem;
}

.app-footer {
  border-bottom: 0;
  border-top: 2px solid var(--ink);
  background: #ecf0f4;
  display: block;
  min-height: 0;
  padding-top: 0.32rem;
  padding-bottom: 0.32rem;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

.header-top-row {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.header-top-row::-webkit-scrollbar {
  height: 0;
}

.header-title-inline {
  display: flex;
  align-items: baseline;
  flex-wrap: nowrap;
  gap: 0.56rem;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

.header-title-inline--controls {
  flex: 0 0 auto;
  overflow: visible;
}

#appTitle {
  font-family: "Sora", "Inter", sans-serif;
  font-weight: 700;
  font-size: clamp(0.96rem, 1.45vw, 1.18rem);
  line-height: 1.05;
  letter-spacing: 0.01em;
  margin: 0;
  flex: 0 0 auto;
}

.primary-control-hints {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.46rem;
  flex: 0 0 auto;
}

.primary-control-hints .control-pill {
  min-height: 34px;
  padding: 0.22rem 0.6rem;
  gap: 0.4rem;
  font-weight: 700;
}

.control-pill--static {
  user-select: none;
  cursor: default;
}

#appPrimaryControlHints .control-pill-dot--shoot {
  background: var(--cog-blue);
  border-color: color-mix(in srgb, var(--cog-blue) 70%, var(--ink) 30%);
}

#appPrimaryControlHints .control-pill--shoot {
  border-color: color-mix(in srgb, var(--cog-blue) 58%, var(--ink) 42%);
  background: color-mix(in srgb, var(--cog-blue) 14%, var(--white) 86%);
}

#appPrimaryControlHints .control-pill--shoot:hover {
  background: color-mix(in srgb, var(--cog-blue) 22%, var(--white) 78%);
}

#appMoveHintText,
#appShootHintText {
  white-space: nowrap;
}

.app-shell::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 14px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-right-color: transparent;
  border-bottom-color: transparent;
  border-radius: 4px 0 0 0;
  opacity: 0.6;
}

.app-shell::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-left-color: transparent;
  border-top-color: transparent;
  border-radius: 0 0 4px 0;
  opacity: 0.6;
}

.game-frame {
  padding: 10px;
  background: var(--white);
  position: relative;
  outline: none;
  display: block;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--white);
  box-shadow: inset 0 0 0 2px #ffffff99;
}

.overlay-restart {
  position: absolute;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 4;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
  font: 700 0.92rem/1 "Inter", sans-serif;
  padding: 0.52rem 1rem;
  cursor: pointer;
  box-shadow: var(--surface-shadow-tight);
}

.overlay-restart:hover {
  background: var(--fog);
}

.overlay-restart:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.overlay-restart.hidden {
  display: none;
}

.modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 0.85rem;
  background: var(--overlay-backdrop);
  z-index: 5;
  backdrop-filter: blur(1px);
  -webkit-backdrop-filter: blur(1px);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(620px, calc(100% - 1rem));
  background: var(--white);
  border: var(--panel-border);
  border-radius: var(--radius-soft);
  box-shadow: var(--surface-shadow);
  padding: 0.95rem 0.95rem 0.8rem;
  max-height: calc(100% - 1rem);
  overflow-y: auto;
  position: relative;
  transform-origin: center top;
  animation: panelIn 130ms ease-out;
}

.modal-accent {
  height: 6px;
  border-radius: 999px;
  background: var(--share-accent, var(--cog-yellow));
  margin-bottom: 0.72rem;
}

.modal-panel h2 {
  margin: 0;
  font-family: "Sora", "Inter", sans-serif;
  font-size: 1.4rem;
  line-height: 1.2;
  letter-spacing: 0.005em;
}

.modal-summary {
  margin: 0.4rem 0 0.66rem;
  font-size: 0.94rem;
  font-weight: 600;
}

.share-card-wrap {
  margin: 0 auto 0.62rem;
  width: min(100%, 500px);
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--white);
  padding: 6px;
  box-shadow: var(--surface-shadow-soft);
}

.share-card-preview {
  width: 100%;
  display: block;
  border: 0;
  border-radius: 8px;
  background: var(--white);
  aspect-ratio: 1200 / 627;
  object-fit: cover;
}

.share-text {
  width: 100%;
  min-height: 98px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 0.58rem 0.62rem;
  resize: vertical;
  background: var(--white);
  color: var(--ink);
  font: 500 0.9rem/1.42 "Inter", sans-serif;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 0.46rem;
  margin-top: 0.56rem;
}

.btn {
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--white);
  color: var(--ink);
  font: 600 0.88rem/1.2 "Inter", sans-serif;
  padding: 0.44rem 0.68rem;
  min-height: 40px;
  width: 100%;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(31, 36, 48, 0.08);
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background-color 120ms ease;
}

.btn:hover {
  background: var(--fog);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(31, 36, 48, 0.12);
}

.btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(31, 36, 48, 0.08);
}

.btn:focus-visible,
.share-text:focus-visible,
.modal-check input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.btn.btn-primary {
  background: var(--share-accent, var(--cog-yellow));
  color: var(--ink);
}

.btn.btn-primary:hover {
  filter: brightness(0.985);
}

.btn.btn-primary:focus-visible {
  outline-color: var(--ink);
}

.modal-check {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.5rem;
  font-size: 0.88rem;
}

.modal-check input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--ink);
}

.modal-note {
  margin: 0.26rem 0 0;
  font-size: 0.78rem;
  opacity: 0.86;
}

.modal-status {
  margin: 0.5rem 0 0;
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--ink);
  display: none;
}

.app-footer,
.app-header {
  box-shadow: inset 0 0 0 1px rgba(31, 36, 48, 0.06);
}

.app-header {
  position: relative;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.status-grid {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  flex-wrap: nowrap;
  font-size: 0.84rem;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.34rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.2rem 0.6rem;
  background: var(--white);
  color: var(--ink-muted);
  min-height: 28px;
  cursor: default;
  user-select: none;
  text-align: left;
  white-space: nowrap;
  appearance: none;
}

button.status-chip {
  cursor: pointer;
  text-align: center;
}

button.status-chip:hover {
  background: var(--fog);
}

button.status-chip:focus-visible,
.status-chip:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.status-chip::before {
  content: "";
  width: 0.46rem;
  height: 0.46rem;
  border-radius: 999px;
  background: var(--chip-dot);
  opacity: 0.9;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0.55rem;
  background: var(--ink);
  color: var(--white);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 0.4rem 0.68rem;
  font: 600 0.84rem/1.2 "Inter", sans-serif;
  z-index: 12;
}

.skip-link:focus {
  left: 1rem;
}

.status-grid > * {
  flex: 0 0 auto;
}

.control-strip {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: start;
  gap: 0.32rem;
  width: auto;
  min-width: max-content;
  overflow: visible;
  white-space: nowrap;
  padding: 0;
  border: 0;
  background: transparent;
  max-width: none;
}

.control-strip::-webkit-scrollbar {
  height: 0;
}

.control-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  border: 2px solid rgba(31, 36, 48, 0.8);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
  color: var(--ink);
  font-size: 0.68rem;
  line-height: 1.14;
  box-shadow: 0 1px 0 rgba(31, 36, 48, 0.15);
  min-height: 32px;
  white-space: nowrap;
  flex: 0 0 auto;
  max-width: max-content;
  transition:
    transform 120ms ease,
    border-color 120ms ease,
    background-color 120ms ease,
    box-shadow 120ms ease;
}

.control-pill-button {
  cursor: pointer;
  text-align: left;
}

.control-pill-button:hover {
  background: #eef3f8;
  transform: translateY(-1px);
}

.control-pill-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.62rem;
  height: 0.62rem;
  border-radius: 999px;
  border: 1px solid rgba(31, 36, 48, 0.26);
  flex-shrink: 0;
}

.control-pill-dot--move {
  background: var(--cog-blue);
}

.control-pill-dot--bomb {
  background: var(--cog-yellow);
}

.control-pill-dot--music {
  background: var(--cog-pink);
}

.control-pill-dot--sfx {
  background: var(--cog-mint);
}

.control-pill[aria-pressed="true"] .control-pill-dot {
  box-shadow: 0 0 0 2px rgba(31, 36, 48, 0.16);
}

.control-pill--move {
  border-color: rgba(62, 121, 216, 0.48);
}

.control-pill--move:hover {
  border-color: rgba(62, 121, 216, 0.82);
}

.control-pill--bomb {
  border-color: rgba(163, 109, 45, 0.48);
}

.control-pill--bomb:hover {
  border-color: rgba(163, 109, 45, 0.78);
}

.control-pill--music {
  border-color: rgba(232, 130, 202, 0.48);
}

.control-pill--music:hover {
  border-color: rgba(232, 130, 202, 0.78);
}

.control-pill--sfx {
  border-color: rgba(23, 143, 112, 0.48);
}

.control-pill--sfx:hover {
  border-color: rgba(27, 147, 119, 0.78);
}

.control-pill--music[aria-pressed="true"],
.control-pill--sfx[aria-pressed="true"] {
  opacity: 0.87;
}

.control-pill--bomb[aria-pressed="true"] {
  opacity: 0.84;
}

.control-pill-button:active {
  transform: translateY(0);
  box-shadow: inset 0 2px 7px rgba(31, 36, 48, 0.12);
}

.control-pill-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.control-pill-key {
  font: 700 0.62rem/1 "Sora", "Inter", sans-serif;
  letter-spacing: 0.02em;
  padding: 0.16rem 0.3rem 0.13rem;
  border-radius: 7px;
  border: 1px solid rgba(31, 36, 48, 0.24);
  background: #f1f5f9;
  color: var(--ink);
  box-shadow: inset 0 -1px 0 rgba(31, 36, 48, 0.1);
}

.control-pill span {
  font: 600 0.67rem/1.1 "Inter", sans-serif;
  color: var(--ink-soft);
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}

.control-pill-state {
  font: 600 0.56rem/1.1 "Inter", sans-serif;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  padding: 0.05rem 0.34rem 0.03rem;
  margin-left: 0.08rem;
  border-radius: 999px;
  border: 1px solid rgba(31, 36, 48, 0.25);
  background: #eef2f6;
  flex-shrink: 0;
}

@media (max-width: 860px) {
  .app-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .status-grid {
    width: 100%;
    flex-wrap: nowrap;
  }

  .control-strip {
    gap: 0.3rem;
  }

  .control-pill-key {
    font-size: 0.58rem;
  }

  .control-pill-state,
  .control-pill span {
    white-space: nowrap;
  }

  .app-shell {
    width: 100%;
  }

  .modal {
    padding: 0.6rem;
  }

  .modal-panel {
    width: 100%;
    border-radius: 16px;
  }

  .overlay-restart {
    width: calc(100% - 1.2rem);
    left: 0.6rem;
    transform: none;
    text-align: center;
  }

  .modal-actions {
    grid-template-columns: 1fr;
  }

  .share-card-wrap {
    width: 100%;
  }
}

@media (max-width: 540px) {
  .app-header {
    padding: 0.56rem 0.78rem 0.44rem;
  }

  .app-footer {
    padding: 0.7rem 0.9rem;
  }

  .modal {
    padding: 0.6rem;
  }

  .modal-panel {
    padding: 0.8rem 0.78rem 0.72rem;
  }

  .modal-panel h2 {
    font-size: 1.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 1ms !important;
    transition-delay: 0ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }

  .overlay-restart,
  .btn,
  .status-chip,
  .modal-panel {
    transform: none !important;
  }
}

@keyframes panelIn {
  from {
    opacity: 0.95;
    transform: translateY(3px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
