:root {
  color-scheme: dark;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #0b1018;
  color: #f6f0df;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0b1018;
}

body {
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  user-select: none;
}

button,
input {
  font: inherit;
}

input {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}

button {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #f6bd3f;
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app {
  width: 100%;
  min-height: 100svh;
  height: 100%;
  background:
    radial-gradient(circle at 50% 12%, rgba(80, 104, 145, 0.22), transparent 34rem),
    #0b1018;
}

.screen {
  width: 100%;
  height: 100%;
}

.home-screen {
  display: grid;
  place-items: center;
  grid-template-rows: auto minmax(min-content, 1fr);
  row-gap: 16px;
  overflow: auto;
  padding: max(12px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(88px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  overscroll-behavior: contain;
}

.home-topbar {
  justify-self: start;
  min-width: 0;
  max-width: 100%;
}

.home-topbar .language-field {
  font-weight: 800;
}

.home-topbar .language-field select {
  min-height: 44px;
  min-width: 44px;
  padding: 6px 10px;
  border: 1px solid #607291;
  border-radius: 12px;
  color: #f6f0df;
  background: #35445c;
  font-family: inherit;
  cursor: pointer;
}

.home-topbar .language-field select:focus-visible {
  outline: 3px solid #f6bd3f;
  outline-offset: 3px;
}

.home-card {
  width: min(100%, 34rem);
  padding: clamp(24px, 7vw, 48px);
  border: 1px solid rgba(246, 189, 63, 0.28);
  border-radius: 24px;
  background: rgba(19, 27, 40, 0.92);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.screen-kicker {
  margin: 0 0 10px;
  color: #f6bd3f;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 18px;
  font-size: clamp(2.4rem, 12vw, 4.4rem);
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.15rem, 4vw, 1.55rem);
}

.screen-lead {
  margin-bottom: 28px;
  color: #d8deeb;
  line-height: 1.9;
}

.home-steps {
  display: grid;
  gap: 10px;
  margin: 0 0 26px;
  padding: 0;
  list-style: none;
}

.home-steps li {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 11px;
  align-items: start;
  padding: 12px;
  border: 1px solid rgba(127, 148, 183, 0.20);
  border-radius: 14px;
  background: rgba(9, 11, 17, 0.34);
}

.home-steps b {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: #1a1408;
  background: #f6bd3f;
  font-size: 0.9rem;
}

.home-steps strong,
.home-steps small {
  display: block;
}

.home-steps strong {
  margin: 1px 0 4px;
  color: #fff4d1;
  font-size: 0.92rem;
}

.home-steps small {
  color: #aab5c9;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.5;
}

.player-name-field {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
  color: #f6f0df;
  font-weight: 700;
}

.player-name-field b {
  color: #ffcf64;
  font-size: 0.75rem;
}

.player-name-field input {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid #65748f;
  border-radius: 12px;
  color: #fff;
  background: #121a28;
}

.player-name-field small {
  color: #aab5c9;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.5;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  padding: 11px 18px;
  border-radius: 12px;
  font-weight: 800;
  transition: transform 120ms ease, filter 120ms ease;
}

.secondary-button,
.lab-link {
  display: grid;
  place-items: center;
  text-align: center;
  text-decoration: none;
}

.primary-button {
  width: 100%;
  margin-top: 20px;
  color: #1a1408;
  background: #f6bd3f;
  box-shadow: 0 5px 0 #9d6e18;
}

.secondary-button {
  color: #f6f0df;
  background: #35445c;
  box-shadow: 0 4px 0 #1d2738;
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(3px);
  filter: brightness(0.96);
}

button:disabled {
  cursor: default;
  opacity: 0.52;
}

.form-error {
  margin: 10px 0 0;
  color: #ffb3a9;
  line-height: 1.55;
}

.scope-note {
  margin: 26px 0 0;
  color: #8896ad;
  font-size: 0.82rem;
  line-height: 1.6;
}

.home-actions {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.home-actions .primary-button {
  margin-top: 0;
}

.share-status {
  min-height: 1.5em;
  margin: 10px 0 0;
  color: #cbd5e6;
  font-size: 0.82rem;
  line-height: 1.5;
  text-align: center;
}

.game-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100svh;
  background: #0b1018;
}

.game-header {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 70px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(127, 148, 183, 0.24);
  background: rgba(11, 16, 24, 0.92);
}

.game-header .screen-kicker {
  margin-bottom: 5px;
  font-size: 0.68rem;
}

.game-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.phase-status {
  color: #f6bd3f;
  font-size: 0.8rem;
  font-weight: 800;
  white-space: nowrap;
}

.game-header .secondary-button {
  min-height: 44px;
  padding: 9px 10px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.retire-button {
  border: 1px solid rgba(255, 169, 145, 0.42);
  color: #ffe1d8;
  background: #5a3540;
  box-shadow: 0 4px 0 #321e28;
}

.stage {
  position: relative;
  width: min(100%, 760px);
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  height: 100%;
  overflow: hidden;
  border: 1px solid rgba(255, 220, 143, 0.16);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 201, 85, 0.12), transparent 38%),
    linear-gradient(180deg, #141821, #090c12 74%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.48), inset 0 1px rgba(255, 255, 255, 0.05);
  isolation: isolate;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  outline: 0;
  -webkit-user-drag: none;
  user-select: none;
}

.loading,
.message,
.webgl-error-panel {
  position: absolute;
  z-index: 2;
}

.run-hud {
  position: absolute;
  top: 12px;
  left: 50%;
  z-index: 3;
  display: flex;
  align-items: baseline;
  gap: 12px;
  max-width: calc(100% - 24px);
  padding: 8px 13px;
  border: 1px solid rgba(255, 220, 143, 0.24);
  border-radius: 999px;
  transform: translateX(-50%);
  color: #f6f0df;
  background: rgba(9, 11, 17, 0.76);
  backdrop-filter: blur(8px);
  pointer-events: none;
  white-space: nowrap;
}

#run-time {
  color: #ffdc7a;
  font-size: clamp(1.05rem, 5vw, 1.45rem);
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

#target-progress {
  color: #d8deeb;
  font-size: 0.78rem;
  font-weight: 800;
}

.loading {
  inset: 0;
  display: grid;
  place-items: center;
  color: #d8d2c2;
  font-weight: 800;
  background: #0d1119;
  transition: opacity 0.25s ease;
}

.message {
  left: 50%;
  bottom: 14px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 9px 14px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 999px;
  transform: translateX(-50%);
  color: #d8d4ca;
  background: rgba(9, 11, 17, 0.76);
  backdrop-filter: blur(8px);
  font-size: 0.78rem;
  font-weight: 750;
  line-height: 1.45;
  text-align: center;
  pointer-events: none;
}

.message.visually-hidden {
  display: none !important;
}

.direction-controls {
  position: absolute;
  inset: 0;
  z-index: 3;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.app[data-screen="playing"] .direction-controls {
  opacity: 1;
  visibility: visible;
}

.direction-control {
  position: absolute;
  display: grid;
  place-items: center;
  width: clamp(48px, 13vw, 58px);
  height: clamp(48px, 13vw, 58px);
  padding: 0;
  border: 1px solid rgba(246, 189, 63, 0.46);
  border-radius: 50%;
  color: #ffe3a0;
  background: rgba(10, 13, 20, 0.76);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.34), inset 0 1px rgba(255, 255, 255, 0.09);
  font-size: clamp(1.65rem, 7vw, 2.15rem);
  font-weight: 950;
  line-height: 1;
  pointer-events: auto;
  touch-action: manipulation;
}

.direction-control-left,
.direction-control-up {
  top: clamp(58px, 17%, 128px);
}

.direction-control-down,
.direction-control-right {
  bottom: clamp(58px, 17%, 128px);
}

.direction-control-left,
.direction-control-down {
  left: clamp(7px, 2.5vw, 18px);
}

.direction-control-up,
.direction-control-right {
  right: clamp(7px, 2.5vw, 18px);
}

.direction-control:active,
.direction-control.is-active {
  border-color: rgba(255, 230, 168, 0.95);
  background: rgba(245, 196, 81, 0.28);
  transform: scale(1.12);
}

.webgl-error-panel {
  top: 50%;
  left: 50%;
  width: min(88%, 24rem);
  transform: translate(-50%, -50%);
  padding: 22px;
  border: 1px solid #ab625c;
  border-radius: 18px;
  background: rgba(17, 23, 35, 0.97);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.webgl-error-panel p {
  margin: 12px 0 16px;
  color: #ffd5cd;
  line-height: 1.6;
}

.webgl-error-panel .secondary-button {
  width: 100%;
}

.result-screen {
  display: grid;
  place-items: start center;
  overflow: auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(92px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

.result-card {
  width: min(100%, 38rem);
  padding: clamp(22px, 6vw, 42px);
  border: 1px solid rgba(246, 189, 63, 0.28);
  border-radius: 24px;
  background:
    linear-gradient(145deg, rgba(29, 38, 56, 0.96), rgba(16, 23, 35, 0.98));
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.38);
}

.result-score {
  display: grid;
  gap: 4px;
  margin: 22px 0 12px;
  padding: 18px;
  border: 1px solid rgba(255, 220, 143, 0.22);
  border-radius: 16px;
  background: rgba(9, 11, 17, 0.46);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.06), 0 12px 30px rgba(0, 0, 0, 0.18);
  text-align: center;
}

.result-score span {
  color: #aab5c9;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.result-score strong {
  color: #ffdc7a;
  font-size: clamp(2.25rem, 12vw, 4rem);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.result-score.is-retired strong {
  color: #ffb3a9;
  font-size: clamp(1.9rem, 9vw, 3rem);
}

.result-record-message {
  min-height: 1.5em;
  margin: 10px 0 18px;
  color: #d8deeb;
  line-height: 1.55;
  text-align: center;
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 22px;
}

.result-summary div {
  padding: 11px 8px;
  border-radius: 12px;
  background: rgba(53, 68, 92, 0.48);
  text-align: center;
}

.result-summary dt {
  color: #aab5c9;
  font-size: 0.72rem;
  font-weight: 700;
}

.result-summary dd {
  margin: 5px 0 0;
  color: #fff4d1;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.result-details,
.result-ranking {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid rgba(127, 148, 183, 0.22);
}

.result-details header,
.result-ranking header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.result-details h3,
.result-ranking h3 {
  margin: 0;
  font-size: 1rem;
}

.result-details header span,
.result-ranking header span {
  color: #aab5c9;
  font-size: 0.75rem;
  text-align: right;
}

.result-detail-list,
.result-ranking-list {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

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

.result-detail-list li,
.result-ranking-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 9px;
  color: #d8deeb;
  background: rgba(9, 11, 17, 0.42);
  font-size: 0.82rem;
}

.result-detail-list li.is-complete,
.result-ranking-list li.is-current {
  color: #fff4d1;
  background: rgba(245, 196, 81, 0.14);
}

.result-detail-list strong,
.result-ranking-list strong {
  color: #ffdc7a;
  font-variant-numeric: tabular-nums;
}

.result-ranking-list li {
  min-height: 42px;
}

.result-ranking-list .ranking-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-ranking-list .ranking-score {
  flex: 0 0 auto;
  color: #fff4d1;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.ranking-retry-button {
  width: 100%;
  margin-top: 12px;
}

.result-actions {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.result-actions .primary-button {
  margin-top: 0;
}

.result-inline-replay {
  margin: 0 0 22px;
}

.app-footer {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(10px, env(safe-area-inset-bottom));
  left: max(12px, env(safe-area-inset-left));
  z-index: 8;
  display: none;
  justify-content: flex-end;
  pointer-events: none;
}

.app[data-screen="playing"] ~ .app-footer {
  display: flex;
}

.sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid rgba(127, 148, 183, 0.34);
  border-radius: 999px;
  color: #d8deeb;
  background: rgba(9, 11, 17, 0.78);
  font-size: 0.72rem;
  font-weight: 800;
  pointer-events: auto;
  backdrop-filter: blur(8px);
}

.sound-toggle[aria-pressed="true"] {
  border-color: rgba(246, 189, 63, 0.68);
  color: #fff0bd;
}

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

img {
  -webkit-user-drag: none;
  user-select: none;
}

@media (min-width: 700px) {
  .game-header {
    padding-right: 24px;
    padding-left: 24px;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  .game-header {
    min-height: 58px;
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .message {
    top: 14px;
    left: 16px;
    width: auto;
    max-width: 45%;
    transform: none;
  }
}

@media (max-width: 420px) {
  .game-header {
    gap: 6px;
  }

  .game-header-actions {
    gap: 4px;
  }

  .game-header .secondary-button {
    padding-right: 8px;
    padding-left: 8px;
    font-size: 0.72rem;
  }

  .phase-status {
    font-size: 0.68rem;
  }

  .result-summary {
    grid-template-columns: 1fr;
  }

  .result-detail-list {
    grid-template-columns: 1fr;
  }
}

#home-share-button, #result-share-button { background: #000; color: #fff; min-height: 44px; white-space: normal; overflow-wrap: anywhere; }
#home-share-fallback, #result-share-fallback { width: 100%; min-height: 6em; font-size: 16px; }
[hidden] { display: none !important; }

.language-field, .sound-volume { display:flex; gap:10px; align-items:center; flex-wrap:wrap; }
.language-field select, .sound-volume input { min-height:44px; max-width:100%; font-size:16px; }
.player-name-field, .result-ranking li, .result-actions, .home-actions, .home-steps { overflow-wrap:anywhere; }
.app-footer { flex-wrap:wrap; }
/* Settings remain reachable on home/results; reserve space for the fixed footer. */
.app-footer { display:flex; gap:10px; align-items:center; justify-content:center; }
.sound-toggle { min-height:44px; font-size:0.85rem; }
.sound-volume { pointer-events:auto; padding:4px 10px; border-radius:12px; background:rgba(9,11,17,.94); color:#fff; }
.sound-volume input { width:130px; }
.home-card, .result-card { margin-bottom:110px; }
.app[data-screen="playing"] ~ .app-footer .sound-volume { display:none; }

/* Home/result settings reserve their own row instead of covering action targets. */
body { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.app { min-height: 0; }
.app-footer { position: static; margin: 10px max(12px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
.app[data-screen="playing"] ~ .app-footer { position: fixed; margin: 0; }
