:root {
  --ink: #2a1115;
  --muted: #73595d;
  --red: #bd1830;
  --red-dark: #821020;
  --blush: #ffd9d2;
  --cream: #fff8f3;
  --line: rgba(142, 28, 43, 0.18);
  --shadow: 0 24px 60px rgba(78, 17, 25, 0.16);
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 8%, rgba(255, 178, 157, 0.32), transparent 25%),
    radial-gradient(circle at 92% 16%, rgba(255, 218, 139, 0.3), transparent 24%),
    linear-gradient(180deg, #fff8f5, #fffdf9 48%, #fff0ec);
}

button, a { font: inherit; }

.game-shell {
  width: min(1520px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.utility-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
}

.utility-nav a,
.secondary-button {
  min-height: 40px;
  padding: 0 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--red-dark);
  background: rgba(255, 255, 255, 0.74);
  font-weight: 800;
  text-decoration: none;
}

.game-header { margin-bottom: 22px; }

.title-lockup {
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-lockup > img {
  width: 74px;
  height: 74px;
  object-fit: contain;
  padding: 6px;
  border-radius: 8px;
  background: var(--blush);
  box-shadow: 0 12px 26px rgba(126, 27, 39, 0.13);
}

.eyebrow,
.dialog-kicker {
  display: block;
  margin-bottom: 6px;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: clamp(2rem, 5vw, 4.25rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.game-header p {
  margin-top: 8px;
  color: var(--muted);
  font-weight: 650;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.game-sidebar {
  position: sticky;
  top: 18px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.level-heading { display: grid; gap: 5px; }
.level-heading span { color: var(--red); font-weight: 900; }
.level-heading strong { font-size: 1.55rem; line-height: 1.05; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 20px 0 14px;
}

.stats > div {
  min-width: 0;
  padding: 11px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--cream);
}

.stats span { display: block; color: var(--muted); font-size: 0.68rem; font-weight: 850; text-transform: uppercase; }
.stats strong { display: block; margin-top: 5px; font-size: 1.08rem; }
.stats strong span { display: inline; color: inherit; font-size: inherit; }

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(189, 24, 48, 0.1);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--red), #ff826f);
  transition: width 240ms ease;
}

.side-actions { display: grid; gap: 9px; margin-top: 18px; }

.primary-button,
.secondary-button,
.start-cover button {
  min-height: 44px;
  padding: 0 17px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
  text-decoration: none;
}

.primary-button,
.start-cover button {
  color: #fff;
  background: var(--red);
  box-shadow: 0 10px 20px rgba(189, 24, 48, 0.22);
}

.secondary-button { border: 1px solid var(--line); }

button:disabled { cursor: not-allowed; opacity: 0.48; }

button:not(:disabled):not(.jeguri-target), a { transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease; }
button:not(:disabled):not(.jeguri-target):hover, a:hover { transform: translateY(-2px); filter: saturate(1.05); }
button:focus-visible, a:focus-visible { outline: 4px solid rgba(255, 117, 106, 0.38); outline-offset: 3px; }

.zoom-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
}

.zoom-controls > div { display: grid; grid-template-columns: 34px 58px 34px; align-items: center; }
.zoom-controls button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 7px; color: var(--red); background: #fff; cursor: pointer; font-size: 1.15rem; font-weight: 900; }
.zoom-controls output { text-align: center; color: var(--ink); }

.status-message { min-height: 3em; margin-top: 16px; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }

.scene-viewport {
  max-height: calc(100vh - 36px);
  overflow: auto;
  border: 3px solid rgba(189, 24, 48, 0.14);
  border-radius: 8px;
  background: #3a171a;
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
  scrollbar-color: rgba(255,255,255,0.54) rgba(42,17,21,0.3);
}

.scene-stage {
  --scene-aspect: 1122 / 1402;
  position: relative;
  width: 100%;
  aspect-ratio: var(--scene-aspect);
  overflow: hidden;
  background: #392023;
  transition: width 180ms ease;
}

.scene-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  -webkit-user-drag: none;
  transition: filter 220ms ease, opacity 220ms ease, transform 220ms ease;
}
.target-layer { position: absolute; inset: 0; }
.scene-stage.is-loading .scene-image { opacity: 0.34; filter: blur(18px); transform: scale(1.035); }
.scene-stage.is-loading .target-layer { visibility: hidden; }

.scene-loader {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 28px;
  color: #fff;
  text-align: center;
  background: rgba(42, 17, 21, 0.88);
  backdrop-filter: blur(14px);
}

.scene-loader[hidden] { display: none; }
.scene-loader strong { font-size: clamp(1.35rem, 3vw, 2.2rem); }
.scene-loader > span:not(.scene-loader-spinner) { color: #ffe7de; line-height: 1.5; }
.scene-loader-spinner {
  width: 48px;
  height: 48px;
  margin-bottom: 4px;
  border: 5px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: scene-loader-spin 780ms linear infinite;
}
.scene-loader.has-error .scene-loader-spinner { display: none; }
.scene-loader button {
  min-height: 42px;
  margin-top: 6px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  color: var(--red-dark);
  background: #fff;
  cursor: pointer;
  font-weight: 900;
}

.jeguri-target {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: max(var(--size), 40px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.jeguri-target:hover,
.jeguri-target:active,
.jeguri-target:disabled {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.jeguri-target img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: var(--sprite-opacity);
  mix-blend-mode: var(--blend-mode);
  filter: brightness(var(--brightness)) saturate(var(--saturation)) contrast(var(--contrast)) drop-shadow(0 1px 1px rgba(34, 14, 14, var(--shadow-opacity)));
  pointer-events: none;
  transform: scale(var(--sprite-scale)) rotate(var(--rotation)) scaleX(var(--flip));
}

.jeguri-target::after {
  content: "";
  position: absolute;
  inset: -12%;
  border: 3px solid transparent;
  border-radius: 50%;
  pointer-events: none;
}

.jeguri-target.is-hinted::after { border-color: #fff36e; animation: hint-pulse 900ms ease-in-out 3; }
.jeguri-target.is-found { cursor: default; }
.jeguri-target.is-found img { opacity: 1; mix-blend-mode: normal; filter: none; }
.jeguri-target.is-found::after { border-color: #fff; background: rgba(79, 187, 111, 0.48); animation: found-ring 420ms ease both; }
.jeguri-target.is-found::before { content: "✓"; position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; color: #fff; text-shadow: 0 2px 5px #276339; font-size: clamp(1rem, 2.2vw, 1.7rem); font-weight: 900; line-height: 1; }

.start-cover {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-content: start center;
  justify-items: center;
  gap: 10px;
  padding: clamp(42px, 8%, 86px) 24px 24px;
  color: #fff;
  text-align: center;
  background: rgba(42, 17, 21, 0.76);
  backdrop-filter: blur(5px);
}

.start-cover[hidden] { display: none; }
.start-cover img { width: clamp(86px, 15vw, 150px); height: clamp(86px, 15vw, 150px); object-fit: contain; }
.start-cover strong { font-size: clamp(1.6rem, 4vw, 2.7rem); }
.start-cover span { color: #ffe7de; }
.start-cover button { margin-top: 8px; background: #fff; color: var(--red-dark); }

.result-dialog {
  width: min(520px, calc(100% - 28px));
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--cream);
  box-shadow: 0 32px 80px rgba(42, 17, 21, 0.35);
  text-align: center;
}

.result-dialog::backdrop { background: rgba(32, 8, 12, 0.7); backdrop-filter: blur(4px); }
.result-dialog > img {
  width: min(156px, 48vw);
  height: auto;
  aspect-ratio: 3 / 4;
  border-radius: 6px;
  object-fit: cover;
}
.result-dialog h2 { margin-bottom: 10px; font-size: 2rem; }
.result-dialog p { color: var(--muted); line-height: 1.55; }
.dialog-actions { display: flex; justify-content: center; gap: 10px; margin-top: 22px; }

@keyframes hint-pulse { 0%, 100% { transform: scale(0.9); opacity: 0.35; } 50% { transform: scale(1.2); opacity: 1; } }
@keyframes found-ring { 0% { transform: scale(0.72); opacity: 0; } 70% { transform: scale(1.12); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes scene-loader-spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .game-layout { grid-template-columns: 1fr; }
  .game-sidebar { position: static; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .scene-viewport { max-height: 72vh; }
}

@media (max-width: 560px) {
  .game-shell { width: min(100% - 20px, 1520px); padding-top: 14px; }
  .utility-nav { margin-bottom: 16px; }
  .title-lockup { align-items: flex-start; }
  .title-lockup > img { width: 58px; height: 58px; }
  .game-sidebar { padding: 16px; }
  .stats { gap: 6px; }
  .stats > div { padding: 9px 6px; }
  .scene-stage { min-width: 480px; }
  .dialog-actions { flex-direction: column; }
}

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