@font-face {
  font-family: "DotGothic16";
  src: url("../assets/fonts/DotGothic16-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --cream: #fff8df;
  --orange: #f39a2f;
  --gold: #ffd65a;
  --brown: #1f120c;
  --panel: #332016;
  --wall: #e0aa43;
  --red: #e74b37;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--brown);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% 0, rgba(243, 154, 47, 0.24), transparent 42rem),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(255, 255, 255, 0.025) 3px 4px),
    var(--brown);
  font-family: "DotGothic16", "Yu Gothic", sans-serif;
}

button,
a {
  font: inherit;
}

.game-shell {
  width: min(1050px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 36px;
}

.game-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 126px;
  margin-bottom: 16px;
  text-align: center;
}

.back-link {
  position: absolute;
  top: 4px;
  left: 0;
  border: 0;
  padding: 8px 10px;
  color: var(--cream);
  background: transparent;
  cursor: pointer;
  text-decoration: none;
}

.back-link:hover,
.back-link:focus-visible {
  color: var(--gold);
}

.title-copy > p {
  margin: 0;
  color: var(--gold);
  font-size: 0.8rem;
  letter-spacing: 0.16em;
}

h1 {
  margin: 4px 0;
  font-size: clamp(2.2rem, 8vw, 4.6rem);
  font-weight: 400;
  line-height: 1;
  text-shadow: 5px 5px 0 #000;
}

h1 span {
  color: var(--gold);
}

.title-copy .subtitle {
  color: var(--cream);
  letter-spacing: 0.03em;
}

.play-panel,
.rules {
  border: 4px solid #fff;
  background: #050505;
  box-shadow: 0 0 0 2px #050505, 0 0 0 4px #fff;
}

.play-panel {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 12px;
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  margin-bottom: 9px;
  font-size: clamp(0.66rem, 2.5vw, 0.9rem);
}

.phase-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gold);
}

.status-dot {
  width: 8px;
  height: 8px;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.stats {
  display: flex;
  gap: 13px;
  color: #c6bba6;
  white-space: nowrap;
}

.stats strong {
  color: #fff;
}

.maze-guide {
  display: grid;
  min-height: 46px;
  margin-bottom: 8px;
  padding: 0 3px;
  align-items: center;
  grid-template-columns: 1fr auto 1fr;
}

.guide-endpoint {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 6px 9px;
  border: 2px solid currentColor;
  background: #0c0907;
  font-size: clamp(0.65rem, 2.5vw, 0.82rem);
  line-height: 1;
  white-space: nowrap;
}

.guide-endpoint b {
  margin-right: 5px;
  color: #fff;
  font-weight: 400;
}

.guide-start {
  color: #55ee88;
  box-shadow: 3px 3px 0 #174f29;
  justify-self: start;
}

.guide-start::before {
  margin-right: 6px;
  content: "▼";
}

.guide-goal {
  color: #67e8ff;
  box-shadow: 3px 3px 0 #174b56;
  justify-self: end;
}

.guide-goal b {
  margin-right: 0;
  margin-left: 5px;
}

.guide-goal::after {
  margin-left: 6px;
  content: "▲";
}

.maze-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  border: 3px solid var(--orange);
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    #160d09;
  background-size: 22px 22px;
  aspect-ratio: 1;
  touch-action: none;
  user-select: none;
}

.maze-grid {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  border: 3px solid var(--wall);
  transition: border-color 420ms ease;
}

.maze-grid.walls-off {
  border-color: rgba(255, 214, 90, 0.2);
}

.maze-cell {
  position: relative;
  display: grid;
  min-width: 0;
  place-items: center;
  border: 2px solid transparent;
  transition: border-color 420ms ease;
}

.maze-cell.start-cell {
  isolation: isolate;
}

.maze-cell.start-cell::before {
  position: absolute;
  z-index: 0;
  width: 72%;
  border: 2px solid rgba(85, 238, 136, 0.92);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(85, 238, 136, 0.32), rgba(85, 238, 136, 0.08) 60%, transparent 72%);
  box-shadow:
    0 0 8px rgba(85, 238, 136, 0.7),
    0 0 18px rgba(85, 238, 136, 0.35);
  content: "";
  aspect-ratio: 1;
}

.maze-cell.goal-cell {
  background: rgba(103, 232, 255, 0.2);
  box-shadow: inset 0 0 0 3px #67e8ff, inset 0 0 18px rgba(103, 232, 255, 0.34);
}

.maze-cell.hit {
  animation: cell-hit 260ms ease;
}

@keyframes cell-hit {
  45% {
    background: rgba(231, 75, 55, 0.7);
    box-shadow: inset 0 0 18px var(--red);
  }
}

.cell-label {
  position: absolute;
  z-index: 6;
  padding: 2px 4px;
  border: 1px solid #fff;
  color: #fff;
  font-size: clamp(0.48rem, 1.7vw, 0.72rem);
  line-height: 1;
  text-shadow: 1px 1px 0 #000;
}

.cell-label.start {
  bottom: 2px;
  left: 2px;
  background: #16743b;
  box-shadow: 2px 2px 0 #052b14;
}

.cell-label.goal {
  top: 2px;
  right: 2px;
  background: #126478;
  box-shadow: 2px 2px 0 #042b35;
}

.character-token {
  position: relative;
  z-index: 3;
  display: block;
  width: 84%;
  height: 84%;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px #000);
  pointer-events: none;
}

.monster-token {
  z-index: 4;
  animation: monster-step 1s steps(2, end) infinite;
}

@keyframes monster-step {
  50% {
    transform: translateY(-5%) scale(1.05);
  }
}

.game-overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  align-items: center;
  flex-direction: column;
  justify-content: center;
  padding: 22px;
  background: rgba(16, 8, 4, 0.91);
  text-align: center;
}

.result-overlay {
  justify-content: flex-start;
  overflow-y: auto;
  padding-top: clamp(18px, 5vw, 38px);
}

.game-overlay[hidden],
.countdown-badge[hidden] {
  display: none;
}

.opening-ranking {
  z-index: 12;
  background:
    radial-gradient(circle at 50% 38%, rgba(243, 154, 47, 0.24), transparent 55%),
    rgba(16, 8, 4, 0.97);
}

.opening-ranking .opening-ranking-kicker {
  margin-bottom: 7px;
  color: var(--orange);
  font-size: clamp(0.58rem, 2vw, 0.76rem);
  letter-spacing: 0.18em;
}

.opening-ranking h2 {
  margin: 0 0 18px;
  color: var(--gold);
  font-size: clamp(1.45rem, 5vw, 2.5rem);
  font-weight: 400;
  text-shadow: 3px 3px 0 #000;
}

.opening-ranking ol {
  width: min(92%, 430px);
  margin: 0;
  padding: 0;
  list-style: none;
}

.opening-ranking li {
  display: grid;
  min-height: 48px;
  padding: 9px 13px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.18);
  align-items: center;
  grid-template-columns: 3em minmax(0, 1fr) 5.5em;
  gap: 8px;
  background: rgba(5, 5, 5, 0.68);
  text-align: left;
}

.opening-ranking li:first-child {
  border-top: 2px solid rgba(255, 255, 255, 0.18);
}

.opening-ranking li strong,
.opening-ranking li b {
  color: var(--gold);
  font-weight: 400;
}

.opening-ranking li b {
  text-align: right;
}

.opening-ranking .opening-ranking-loading,
.opening-ranking .opening-ranking-empty {
  display: block;
  color: #eadfc9;
  text-align: center;
}

.face-off {
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(92%, 430px);
  margin-bottom: 10px;
}

.face-off img {
  width: 43%;
  height: auto;
  margin: -7%;
  object-fit: contain;
}

.face-off span {
  z-index: 2;
  color: var(--gold);
  font-size: clamp(1.2rem, 5vw, 2.3rem);
  text-shadow: 3px 3px #000;
}

.game-overlay p {
  margin: 0 0 18px;
  color: #eadfc9;
  font-size: clamp(0.75rem, 2.7vw, 0.95rem);
}

.nickname-form {
  width: min(100%, 430px);
  margin: 0 0 16px;
}

.nickname-form[hidden],
.ranking-result[hidden] {
  display: none;
}

.nickname-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--gold);
  font-size: clamp(0.7rem, 2.5vw, 0.88rem);
}

.nickname-row {
  display: flex;
  gap: 7px;
}

.nickname-row input,
.nickname-row button {
  min-height: 42px;
  border: 2px solid #fff;
  font: inherit;
}

.nickname-row input {
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  background: #fff8df;
  color: #1f120c;
}

.nickname-row button {
  flex: 0 0 auto;
  padding: 8px 12px;
  background: var(--gold);
  color: #1f120c;
  cursor: pointer;
}

.nickname-form small {
  display: block;
  min-height: 1.4em;
  margin-top: 6px;
  color: #ff9f8f;
  font-size: 0.68rem;
}

.ranking-result {
  width: min(100%, 470px);
  margin-bottom: 14px;
}

.ranking-result .your-rank {
  margin-bottom: 8px;
  color: var(--gold);
}

.ranking-result h3 {
  margin: 0 0 6px;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 400;
}

.ranking-result ol {
  margin: 0;
  padding: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.28);
  list-style: none;
  font-size: clamp(0.6rem, 2.1vw, 0.75rem);
}

.ranking-result li {
  display: grid;
  padding: 5px 3px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.18);
  grid-template-columns: 2.4em minmax(0, 1fr) 5.4em 7.2em;
  gap: 5px;
  text-align: left;
}

.ranking-result li span:nth-child(1),
.ranking-result li span:nth-child(3) {
  color: var(--gold);
}

.ranking-result li span:nth-child(3),
.ranking-result li span:nth-child(4) {
  text-align: right;
}

.result-retry {
  margin-top: 2px;
}

.primary-button {
  min-width: 190px;
  padding: 13px 18px;
  border: 3px solid #fff;
  background: var(--orange);
  color: #1b0e06;
  box-shadow: 4px 4px 0 #000;
  cursor: pointer;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--gold);
  outline: 3px solid var(--orange);
  outline-offset: 3px;
}

.primary-button:active {
  box-shadow: 1px 1px 0 #000;
  transform: translate(3px, 3px);
}

.countdown-badge {
  display: flex;
  min-width: 112px;
  height: 42px;
  padding: 2px 10px;
  border: 2px solid var(--gold);
  background: #050505;
  box-shadow: 3px 3px 0 #fff;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-align: center;
}

.countdown-badge small {
  color: var(--gold);
  font-size: 0.62rem;
}

.countdown-badge strong {
  color: #fff;
  font-size: 2rem;
  font-weight: 400;
  line-height: 1;
}

.result-label {
  color: var(--gold);
  letter-spacing: 0.2em;
}

.result-overlay h2 {
  margin: 9px 0;
  font-size: clamp(1.8rem, 6vw, 3.5rem);
  font-weight: 400;
}

.result-overlay.is-lost {
  background: rgba(35, 6, 4, 0.93);
}

.result-overlay.is-lost .result-label {
  color: #ff7967;
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 10px;
}

.restart-button {
  flex: 0 0 auto;
  padding: 9px 11px;
  border: 2px solid var(--gold);
  background: #0c0907;
  color: var(--gold);
  box-shadow: 2px 2px 0 #6f4818;
  cursor: pointer;
  font-size: clamp(0.64rem, 2.2vw, 0.78rem);
  white-space: nowrap;
}

.restart-button:hover,
.restart-button:focus-visible {
  background: var(--gold);
  color: #1f120c;
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.control-hint {
  margin: 0;
  color: #c6bba6;
  font-size: clamp(0.65rem, 2.4vw, 0.8rem);
}

.d-pad {
  display: grid;
  grid-template-columns: repeat(3, 40px);
  grid-template-rows: repeat(2, 40px);
  gap: 4px;
}

.d-pad button {
  padding: 0;
  border: 2px solid #fff;
  background: var(--panel);
  color: #fff;
  cursor: pointer;
}

.d-pad button:hover:not(:disabled),
.d-pad button:focus-visible:not(:disabled) {
  background: var(--orange);
  color: #1f120c;
}

.d-pad button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.d-up {
  grid-column: 2;
}

.d-left {
  grid-column: 1;
  grid-row: 2;
}

.d-down {
  grid-column: 2;
  grid-row: 2;
}

.d-right {
  grid-column: 3;
  grid-row: 2;
}

.rules {
  width: min(100%, 720px);
  margin: 18px auto 0;
  padding: 15px 18px 17px;
}

.rules h2 {
  margin: 0 0 11px;
  color: var(--gold);
  font-size: 1rem;
  font-weight: 400;
}

.rules ol {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: clamp(0.68rem, 2.4vw, 0.83rem);
}

.rules li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rules li span {
  display: grid;
  width: 24px;
  flex: 0 0 24px;
  border: 2px solid var(--orange);
  color: var(--gold);
  aspect-ratio: 1;
  place-items: center;
}

@media (max-width: 560px) {
  .game-shell {
    width: calc(100% - 16px);
    padding-top: 13px;
  }

  .game-header {
    min-height: 112px;
    padding-top: 22px;
  }

  .back-link {
    font-size: 0.72rem;
  }

  .play-panel {
    padding: 8px;
    border-width: 3px;
  }

  .maze-frame,
  .maze-grid {
    border-width: 2px;
  }

  .maze-cell {
    border-width: 1.5px;
  }

  .maze-guide {
    min-height: 42px;
    margin-bottom: 6px;
  }

  .guide-endpoint {
    padding: 5px 6px;
    font-size: 0.62rem;
  }

  .guide-start::before,
  .guide-goal::after {
    margin-right: 4px;
    margin-left: 4px;
  }

  .countdown-badge {
    min-width: 88px;
    height: 36px;
    padding: 2px 6px;
    gap: 3px;
  }

  .countdown-badge strong {
    font-size: 1.65rem;
  }

  .cell-label {
    padding: 1px 2px;
    font-size: 0.48rem;
  }

  .controls-row {
    align-items: flex-end;
    flex-wrap: wrap;
  }

  .control-hint {
    max-width: 150px;
    line-height: 1.65;
  }

  .restart-button {
    order: 3;
  }

  .d-pad {
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(2, 44px);
  }

  .rules ol {
    grid-template-columns: 1fr;
  }
}

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