@font-face {
  font-family: "Galmuri11";
  src: url("./assets/fonts/Galmuri11.woff2") format("woff2");
  font-display: swap;
}

:root {
  --pink: #f3afc8;
  --purple: #a88bcb;
  --soft-purple: #d9c9ec;
  --deep-purple: #69557e;
  --background: #fff9fc;
  --surface: #ffffff;
  --text: #332c38;
  --muted: #766c79;
  --border: #51465a;
  --success: #47745d;
  --success-bg: #e3f3e9;
  --error: #a94e62;
  --error-bg: #fbe5ea;
  --shadow: 4px 4px 0 rgba(81, 70, 90, 0.16);
  --pixel-border: 3px solid var(--border);
  --screen-padding: clamp(20px, 6vw, 36px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #f4edf3;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(rgba(168, 139, 203, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(168, 139, 203, 0.05) 1px, transparent 1px),
    var(--background);
  background-size: 16px 16px;
  font-family: "Galmuri11", monospace;
  font-size: 15px;
  line-height: 1.7;
  word-break: keep-all;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

img {
  display: block;
  max-width: 100%;
}

.game-shell {
  width: min(100%, 580px);
  min-height: 100vh;
  margin-inline: auto;
  background: rgba(255, 249, 252, 0.96);
}

.game-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr);
  gap: 18px;
  align-items: center;
  padding: 14px 18px 12px;
  border-bottom: var(--pixel-border);
  background: rgba(255, 249, 252, 0.96);
  box-shadow: 0 3px 0 rgba(81, 70, 90, 0.08);
  backdrop-filter: blur(8px);
}

.game-title {
  color: var(--deep-purple);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-decoration: none;
}

.memory-status__label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.pixel-progress {
  height: 14px;
  padding: 2px;
  border: 2px solid var(--border);
  background: var(--surface);
}

.pixel-progress__fill {
  display: block;
  width: var(--progress, 0%);
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--pink) 0 10px, #f7bfd3 10px 13px);
  transition: width 400ms steps(5, end);
}

.game-main {
  min-height: calc(100vh - 124px);
}

.game-screen {
  width: 100%;
  padding: var(--screen-padding);
}

.game-screen.is-active {
  display: block;
  animation: screen-in 260ms ease-out both;
}

.is-hidden,
[hidden] {
  display: none !important;
}

.is-invisible {
  visibility: hidden;
}

.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;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--deep-purple);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.stage-heading {
  margin-bottom: 24px;
}

.stage-heading h2,
.save-card h1,
.save-card h2 {
  margin: 0;
  font-size: clamp(22px, 6.5vw, 30px);
  line-height: 1.45;
}

.save-card,
.ending-card {
  text-align: center;
}

.save-card--intro,
.save-card--complete {
  display: flex;
  min-height: calc(100vh - 190px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.save-date {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 10px 0 28px;
  color: var(--muted);
  font-size: 13px;
}

.pixel-pair {
  position: relative;
  width: 150px;
  height: 62px;
  margin-bottom: 22px;
}

.pixel-friend {
  position: relative;
  display: block;
  width: 48px;
  height: 44px;
  border: 3px solid var(--border);
  border-radius: 50% 50% 42% 42%;
  box-shadow: inset -5px -5px 0 rgba(81, 70, 90, 0.12);
}

.pixel-friend::before,
.pixel-friend::after {
  position: absolute;
  top: 16px;
  width: 4px;
  height: 7px;
  background: var(--border);
  content: "";
}

.pixel-friend::before { left: 12px; }
.pixel-friend::after { right: 12px; }
.pixel-friend--pink {
  position: absolute;
  right: 0;
  bottom: 0;
  background: var(--pink);
}

.pixel-friend--purple {
  position: absolute;
  top: 0;
  left: 0;
  background: var(--purple);
}

.pixel-heart {
  position: absolute;
  top: 20px;
  left: 70px;
  color: var(--pink);
}
.pixel-heart::before { content: "♥"; }

.dialog-box,
.letter-box,
.obstacle-card {
  position: relative;
  width: 100%;
  border: var(--pixel-border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dialog-box {
  margin-bottom: 24px;
  padding: 18px;
  text-align: left;
}

.dialog-box::after {
  position: absolute;
  right: 12px;
  bottom: 8px;
  width: 0;
  height: 0;
  border-top: 6px solid var(--purple);
  border-right: 5px solid transparent;
  border-left: 5px solid transparent;
  content: "";
  animation: cursor-blink 1s steps(2, end) infinite;
}

.dialog-box p,
.letter-box p {
  margin: 0;
}

.pixel-button {
  min-height: 48px;
  padding: 11px 18px;
  border: var(--pixel-border);
  border-radius: 0;
  background: var(--surface);
  box-shadow: 4px 4px 0 var(--border);
  font-weight: 700;
  cursor: pointer;
  transition: transform 80ms ease, box-shadow 80ms ease, background-color 160ms ease;
}

.pixel-button:hover { background: #fff2f7; }
.pixel-button:active {
  transform: translate(4px, 4px);
  box-shadow: 0 0 0 var(--border);
}

.pixel-button--primary { background: var(--pink); }
.pixel-button--primary:hover { background: #f6bfd3; }
.pixel-button--secondary { width: 100%; margin-top: 12px; background: var(--soft-purple); }
.pixel-button--ghost { color: var(--deep-purple); background: transparent; }
.pixel-button--choice {
  display: grid;
  width: 100%;
  grid-template-columns: 1fr 20px;
  gap: 10px;
  align-items: center;
  text-align: left;
}
.pixel-button--choice:disabled { opacity: 1; }

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 4px solid rgba(105, 85, 126, 0.32);
  outline-offset: 4px;
}

.photo-frame {
  margin: 0 0 24px;
  padding: 7px;
  border: var(--pixel-border);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.photo-frame img {
  width: 100%;
  background: var(--soft-purple);
  object-fit: cover;
}

.photo-frame--hero img { aspect-ratio: 4 / 3; }
.photo-frame--ending img { aspect-ratio: 1 / 1; }

.photo-frame figcaption {
  padding: 8px 4px 1px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.stage-form,
.choice-list {
  display: grid;
  gap: 12px;
}

.choice-list {
  padding: 0;
  margin: 0;
  border: 0;
}

.choice-option {
  position: relative;
  display: grid;
  min-height: 52px;
  grid-template-columns: 30px 1fr 20px;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

.choice-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.choice-option__number {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  background: var(--soft-purple);
  font-size: 13px;
}

.choice-option:hover,
.choice-option:where(:has(input:checked)) {
  border-color: var(--deep-purple);
  background: #faf5ff;
  box-shadow: 3px 3px 0 var(--soft-purple);
}

.choice-option.is-correct,
.pixel-button--choice.is-correct {
  border-color: var(--success);
  background: var(--success-bg);
  box-shadow: 3px 3px 0 var(--success);
}

.choice-option.is-wrong,
.pixel-button--choice.is-wrong {
  border-color: var(--error);
  background: var(--error-bg);
  box-shadow: 3px 3px 0 var(--error);
}

.choice-option.is-correct .choice-option__mark::after,
.pixel-button--choice.is-correct .choice-option__mark::after {
  color: var(--success);
  content: "○";
}

.choice-option.is-wrong .choice-option__mark::after,
.pixel-button--choice.is-wrong .choice-option__mark::after {
  color: var(--error);
  content: "×";
}
.choice-option__mark {
  display: grid;
  width: 20px;
  min-height: 24px;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
}

.result-message {
  min-height: 46px;
  margin: 4px 0;
  padding: 10px 12px;
  border-left: 4px solid var(--purple);
  background: var(--soft-purple);
  color: var(--deep-purple);
}

.result-message.is-success { border-color: var(--success); background: var(--success-bg); color: #315943; }
.result-message.is-error { border-color: var(--error); background: var(--error-bg); color: #7e3548; }

.date-files {
  display: grid;
  gap: 10px;
  margin-bottom: 28px;
}

.date-file {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  border: 2px solid var(--border);
  background: var(--surface);
}

.date-file h3,
.date-file p { margin: 0; }
.date-file h3 { color: var(--muted); font-size: 13px; font-weight: 400; }
.date-file p { font-size: 17px; letter-spacing: 0.04em; }
.missing-number { color: var(--error); animation: cursor-blink 1.2s steps(2, end) infinite; }

.input-label {
  font-weight: 700;
}

.answer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.pixel-input {
  width: 100%;
  min-height: 48px;
  padding: 8px 12px;
  border: var(--pixel-border);
  border-radius: 0;
  color: var(--text);
  background: var(--surface);
  appearance: textfield;
}

.pixel-input::-webkit-inner-spin-button,
.pixel-input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.pixel-input:focus { border-color: var(--deep-purple); box-shadow: inset 0 -4px 0 var(--soft-purple); outline: 0; }
.pixel-input.is-correct { border-color: var(--success); background: var(--success-bg); }
.pixel-input.is-wrong { border-color: var(--error); background: var(--error-bg); }

.timeline-grid {
  display: grid;
  gap: 14px;
}

.timeline-card {
  position: relative;
  min-height: 44px;
  padding: 6px;
  overflow: hidden;
  border: var(--pixel-border);
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.timeline-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: var(--soft-purple);
  object-fit: cover;
}

.timeline-card.is-selected { border-color: var(--deep-purple); box-shadow: 5px 5px 0 var(--purple); }
.timeline-card.is-correct { border-color: var(--success); }

.order-badge {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 12px;
  display: none;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 2px solid var(--border);
  background: var(--pink);
  box-shadow: 2px 2px 0 var(--border);
  font-weight: 700;
}

.timeline-card.is-selected .order-badge { display: grid; }
.timeline-card__date { display: block; padding: 8px 4px 2px; color: var(--deep-purple); font-size: 12px; }

.stage-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 22px;
}

.journey-track {
  position: relative;
  display: grid;
  min-height: 190px;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  margin: 4px 0 28px;
  padding: 24px 6px 48px;
  border: var(--pixel-border);
  background: linear-gradient(180deg, var(--soft-purple), #faf6ff 62%);
  overflow: hidden;
}

.track-line {
  position: absolute;
  right: 10%;
  bottom: 79px;
  left: 10%;
  height: 5px;
  background: var(--border);
}

.track-point {
  position: relative;
  z-index: 2;
  display: flex;
  align-self: end;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.track-point__marker {
  width: 18px;
  height: 18px;
  border: 3px solid var(--border);
  background: var(--surface);
}

.track-point:not(.track-point--start):not(.track-point--finish) .track-point__marker::after {
  position: absolute;
  bottom: 50px;
  width: 24px;
  height: 36px;
  margin-left: -6px;
  border: 3px solid var(--border);
  background: var(--purple);
  content: "";
}

.track-point.is-cleared .track-point__marker { background: var(--pink); }
.track-point.is-cleared:not(.track-point--start) .track-point__marker::after { opacity: 0; transform: translateY(15px); }

.player-marker {
  position: absolute;
  z-index: 5;
  bottom: 93px;
  left: calc(10% - 13px);
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 2px solid var(--border);
  background: var(--pink);
  box-shadow: 2px 2px 0 var(--border);
  color: var(--deep-purple);
  transition: left 350ms steps(4, end);
}

.journey-track[data-position="1"] .player-marker { left: calc(30% - 13px); }
.journey-track[data-position="2"] .player-marker { left: calc(50% - 13px); }
.journey-track[data-position="3"] .player-marker { left: calc(70% - 13px); }
.journey-track[data-position="4"] .player-marker { left: calc(90% - 13px); }

.obstacle-card {
  padding: 18px;
}

.obstacle-card__count { margin: 0 0 6px; color: var(--deep-purple); font-size: 11px; letter-spacing: 0.08em; }
.obstacle-card h3 { margin: 0 0 16px; font-size: 16px; }
.obstacle-summary { margin: -6px 0 18px; color: var(--muted); }
.obstacle-choices { display: grid; gap: 10px; }
.obstacle-choices + .result-message { margin-top: 16px; }
.obstacle-confirm { width: 100%; margin-top: 12px; }

.puzzle-layout {
  display: grid;
  gap: 28px;
}

.puzzle-board,
.puzzle-pieces {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
}

.puzzle-board {
  width: min(100%, 390px);
  aspect-ratio: 1;
  gap: 5px;
  padding: 7px;
  margin-inline: auto;
  border: var(--pixel-border);
  background: var(--border);
  box-shadow: var(--shadow);
}

.puzzle-slot,
.puzzle-piece {
  min-width: 0;
  min-height: 44px;
  border: 2px dashed var(--purple);
  border-radius: 0;
  background-color: #f9f5fb;
  cursor: pointer;
}

.puzzle-slot.is-locked { border-style: solid; cursor: default; }

.puzzle-pieces {
  gap: 10px;
  width: min(100%, 320px);
  margin-inline: auto;
}

.puzzle-piece {
  aspect-ratio: 1;
  border: var(--pixel-border);
  background-image: url("./assets/photos/final-memory.jpg");
  background-repeat: no-repeat;
  background-size: 200% 200%;
  box-shadow: 3px 3px 0 var(--border);
}

.puzzle-piece--0 { background-position: left top; }
.puzzle-piece--1 { background-position: right top; }
.puzzle-piece--2 { background-position: left bottom; }
.puzzle-piece--3 { background-position: right bottom; }
.puzzle-piece.is-selected { outline: 5px solid var(--pink); outline-offset: 2px; }
.puzzle-piece.is-placed { display: none; pointer-events: none; }

.puzzle-board.is-complete { gap: 0; padding: 0; border: 0; box-shadow: var(--shadow); }
.puzzle-board.is-complete .puzzle-slot { border: 0; }
#stage-5-result { margin-top: 12px; }

.ending-card .eyebrow { margin-bottom: 20px; }
.letter-box { padding: 24px 18px; margin: 24px 0; text-align: left; }
.letter-box p + p { margin-top: 18px; }

.save-card--complete .save-icon {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  margin-bottom: 24px;
  border: var(--pixel-border);
  background: var(--pink);
  box-shadow: var(--shadow);
  color: var(--deep-purple);
  font-size: 26px;
}

.save-card--complete h2 { margin-bottom: 8px; }
.save-card--complete > p:last-child { color: var(--muted); }

.game-footer {
  padding: 18px;
  border-top: 2px solid var(--border);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.05em;
  text-align: center;
}

.game-footer p { margin: 0; }

@keyframes screen-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cursor-blink {
  50% { opacity: 0.35; }
}

@media (min-width: 560px) {
  body { padding: 30px 0; }
  .game-shell { min-height: calc(100vh - 60px); border: var(--pixel-border); box-shadow: 10px 10px 0 rgba(81, 70, 90, 0.16); }
  .timeline-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 370px) {
  .game-header { gap: 10px; padding-inline: 12px; }
  .game-title { font-size: 13px; }
  .save-date { flex-wrap: wrap; }
  .track-point { font-size: 9px; }
}

@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;
  }
}
