/* ---------- tokens ---------- */
:root {
  --wall: oklch(96% 0.012 230);
  --wall-deep: oklch(92% 0.02 230);
  --floor: oklch(80% 0.055 70);
  --floor-line: oklch(74% 0.06 70);
  --mat: oklch(66% 0.11 200);
  --mat-edge: oklch(58% 0.11 200);
  --surface: oklch(99% 0.003 230);
  --ink: oklch(26% 0.03 250);
  --ink-soft: oklch(48% 0.03 250);
  --accent: oklch(68% 0.18 35);
  --accent-deep: oklch(58% 0.18 35);
  --accent-ink: oklch(99% 0.01 35);
  --ok: oklch(72% 0.17 150);
  --danger: oklch(60% 0.2 25);
  --bug: oklch(80% 0.14 145);
  --dress: oklch(86% 0.1 350);
  --shadow-soft: 0 6px 20px oklch(30% 0.04 250 / 0.12);
  --shadow-press: 0 2px 6px oklch(30% 0.04 250 / 0.16);
  --radius-lg: 28px;
  --radius-md: 18px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --fast: 160ms;
  --normal: 260ms;
  --z-stage: 1;
  --z-shoe: 2;
  --z-drag: 3;
  --z-chrome: 10;
  --z-overlay: 20;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--wall);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen[hidden] { display: none; }

/* ---------- profile ---------- */
#screen-profile {
  background: radial-gradient(120% 80% at 50% 0%, var(--surface) 0%, var(--wall) 60%, var(--wall-deep) 100%);
}

.profile-pair {
  display: flex;
  gap: clamp(24px, 6vw, 72px);
}

.profile-btn {
  width: clamp(180px, 30vw, 300px);
  aspect-ratio: 1;
  border: none;
  border-radius: 36px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 10%;
  position: relative;
  transition: transform var(--fast) var(--ease-out), box-shadow var(--fast) var(--ease-out);
}

.profile-btn::before {
  content: '';
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: var(--bug);
  z-index: 0;
}

.profile-dress::before { background: var(--dress); }

.profile-btn svg { position: relative; width: 100%; height: 100%; z-index: 1; }

.profile-btn:active { transform: scale(0.95); box-shadow: var(--shadow-press); }

.profile-btn:focus-visible { outline: 4px solid var(--accent); outline-offset: 4px; }

.gear {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-soft);
  opacity: 0.35;
  padding: 12px;
  z-index: var(--z-chrome);
}

.gear svg { width: 100%; height: 100%; }

/* ---------- game scene ---------- */
#stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.floor {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 18vw, var(--floor-line) 18vw calc(18vw + 2px)),
    linear-gradient(180deg, var(--floor-line) 0, var(--floor) 6px, var(--floor) 100%);
}

.mat {
  position: absolute;
  left: 50%;
  top: 36vh;
  width: 62vw;
  height: 78vh;
  transform: translateX(-50%);
  border-radius: 999px;
  background: var(--mat);
  box-shadow: inset 0 0 0 6px var(--mat-edge), 0 8px 18px oklch(30% 0.05 250 / 0.14);
}

/* First-person: legs rise from the bottom edge, feet sit mid-screen. */
#char {
  position: absolute;
  left: 50%;
  top: 22vh;
  width: 50vh;
  height: 78vh;
  transform: translateX(-50%);
  z-index: var(--z-stage);
}

#char svg { width: 100%; height: 100%; }

.foot {
  position: absolute;
  top: 42vh;
  width: 17vh;
  height: 22vh;
  z-index: var(--z-stage);
  transition: opacity var(--normal) var(--ease-out);
}

.foot svg { width: 100%; height: 100%; }

/* Own feet seen from above: left foot on the left, toes pointing away. */
.foot[data-foot="left"]  { left: calc(50% - 17.5vh); }
.foot[data-foot="right"] { left: calc(50% + 0.5vh); }

.foot.worn { opacity: 0; }

.shoe {
  position: absolute;
  width: 32vh;
  height: 30.4vh;
  z-index: var(--z-shoe);
  touch-action: none;
  filter: drop-shadow(0 6px 6px oklch(30% 0.05 250 / 0.22));
  transition: transform var(--normal) var(--ease-out), left var(--normal) var(--ease-out), top var(--normal) var(--ease-out);
}

.shoe svg { width: 100%; height: 100%; overflow: visible; }

/* Only the painted drawing is grabbable, so overlapping shoe boxes never
   block each other's straps. */
.shoe { pointer-events: none; }
.shoe svg * { pointer-events: visiblePainted; }

.shoe.dragging { transition: none; z-index: var(--z-drag); transform: scale(1.08); filter: drop-shadow(0 14px 14px oklch(30% 0.05 250 / 0.28)); }

/* strap states */
.strap-tab { --rest: 75deg; transform: rotate(calc(var(--rest) + var(--sway, 0deg))); transition: transform 180ms var(--ease-out); pointer-events: all; }
.shoe[data-strap="closed"] .strap-tab { display: none; }
.shoe[data-strap="open"] .strap-closed { display: none; }
.shoe.settling .strap-tab { animation: settle 700ms var(--ease-out); }
.shoe.tab-hint .strap-tab { animation: nudge 1.4s ease-in-out infinite; }
.shoe.tab-grab .strap-tab { transition: none; }

@keyframes settle {
  0% { transform: rotate(calc(var(--rest) + var(--sway, 0deg))); }
  40% { transform: rotate(calc(var(--rest) + var(--sway, 0deg) * -0.45)); }
  70% { transform: rotate(calc(var(--rest) + var(--sway, 0deg) * 0.18)); }
  100% { transform: rotate(var(--rest)); }
}

@keyframes nudge {
  0%, 100% { transform: rotate(var(--rest)); }
  50% { transform: rotate(calc(var(--rest) - 9deg)); }
}

.shoe.wrong-left  { transform: rotate(-22deg); }
.shoe.wrong-right { transform: rotate(22deg); }

.shoe.guide { animation: blink 0.7s infinite alternate; }

@keyframes blink {
  from { filter: drop-shadow(0 6px 6px oklch(30% 0.05 250 / 0.22)); }
  to { filter: drop-shadow(0 0 14px oklch(85% 0.18 90)) brightness(1.15); }
}

#char.happy { animation: bounce 0.4s var(--ease-out) 2; }

@keyframes bounce {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.04); }
}

#char.confused { animation: stomp 0.3s ease-in-out 3; }

@keyframes stomp {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(1.5vh); }
}

/* character reactions: exactly one visible */
#char .face { display: none; }
#char:not(.happy):not(.confused):not(.sleep) .face-normal { display: block; }
#char.happy .face-happy { display: block; }
#char.confused .face-confused { display: block; }
#char.sleep .face-sleep { display: block; }

/* ---------- chrome ---------- */
.round-btn {
  position: fixed;
  top: 16px;
  width: 64px;
  height: 64px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  color: var(--accent);
  box-shadow: var(--shadow-soft);
  padding: 16px;
  z-index: var(--z-chrome);
  transition: transform var(--fast) var(--ease-out), box-shadow var(--fast) var(--ease-out);
}

.round-btn svg { width: 100%; height: 100%; display: block; }

.round-btn:active { transform: scale(0.92); box-shadow: var(--shadow-press); }

.round-btn:focus-visible { outline: 4px solid var(--accent); outline-offset: 3px; }

.corner-left { left: 16px; }
.corner-right { right: 16px; }

.progress {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  z-index: var(--z-chrome);
}

.progress span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: oklch(88% 0.01 250);
  transition: background var(--normal) var(--ease-out), transform var(--normal) var(--ease-out);
}

.progress span.on { background: var(--accent); }

.progress .goal { width: 34px; height: 34px; margin-left: 4px; opacity: 0.9; }

.progress .goal svg { width: 100%; height: 100%; }

/* ---------- collection ---------- */
#screen-collection {
  background: radial-gradient(120% 80% at 50% 0%, var(--surface) 0%, var(--wall) 60%, var(--wall-deep) 100%);
}

.collection-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: clamp(12px, 2.5vh, 28px);
  width: min(86vw, 1100px);
}

.item {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  padding: 12%;
  transition: transform var(--fast) var(--ease-out);
}

.item svg { width: 100%; height: 100%; display: block; }

.item.locked { background: oklch(94% 0.01 250); box-shadow: none; }

.item.locked > svg { filter: brightness(0) opacity(0.12); }

.item .lock {
  position: absolute;
  right: 8%;
  bottom: 8%;
  width: 22%;
  height: 22%;
  color: oklch(70% 0.02 250);
}

.item.unlocked:active { transform: scale(1.06); }

.item.unlocked:active > svg { animation: wiggle 0.6s var(--ease-out); }

@keyframes wiggle {
  0%, 100% { transform: rotate(0); }
  25% { transform: rotate(-10deg) scale(1.12); }
  75% { transform: rotate(10deg) scale(1.12); }
}

/* ---------- settings sheet ---------- */
.sheet {
  border: none;
  padding: 0;
  margin: auto 0 0 0;
  width: 100vw;
  max-width: 100vw;
  max-height: 88vh;
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: 0 -12px 40px oklch(30% 0.04 250 / 0.2);
}

.sheet::backdrop { background: oklch(20% 0.03 250 / 0.45); }

.sheet[open] { animation: rise var(--normal) var(--ease-out); }

@keyframes rise {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px clamp(20px, 6vw, 64px) 32px;
  max-width: 720px;
  margin: 0 auto;
}

.sheet h1 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }

.field { display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 16px; }

.field input, .field select {
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  padding: 10px 14px;
  border: 1.5px solid oklch(84% 0.02 250);
  border-radius: 12px;
  background: var(--surface);
  min-width: 12em;
}

.field input:focus-visible, .field select:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.sheet-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; }

.btn {
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 600;
  transition: transform var(--fast) var(--ease-out), background var(--fast);
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-deep); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover { background: oklch(96% 0.03 25); }

/* ---------- overlay (unlock / sleep) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: oklch(98% 0.01 230 / 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay[hidden] { display: none; }

.overlay-art { width: 52vh; height: 52vh; animation: pop 500ms var(--ease-out); }

.overlay-art svg { width: 100%; height: 100%; }

@keyframes pop {
  from { transform: scale(0.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }

.confetti i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 18px;
  border-radius: 3px;
  background: var(--c, var(--accent));
  transform: translate(-50%, -50%);
  animation: burst 1.1s var(--ease-out) forwards;
}

@keyframes burst {
  0% { transform: translate(-50%, -50%) rotate(0); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(540deg); opacity: 0; }
}

/* overlay character (sleep) shows only the sleeping mark */
.overlay .face { display: none; }
.overlay .face-sleep { display: block; }

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