@import url("https://fonts.googleapis.com/css2?family=Fraunces:wght@400;600;700&family=Space+Grotesk:wght@400;500;600&display=swap");

:root {
  --ink: #151412;
  --ink-soft: rgba(21, 20, 18, 0.75);
  --paper: #f7f1e8;
  --gold: #d9a75b;
  --stone: #6a5b4f;
  --accent: #ce5f3a;
  --accent-dark: #7a3520;
  --glow: rgba(217, 167, 91, 0.6);
  --shadow: rgba(21, 20, 18, 0.2);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #fef7e9 0%, #d7c3aa 45%, #ae9478 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 32px 18px 48px;
  transition: background 0.6s ease;
}

body.is-escape {
  background: radial-gradient(circle at top, #fff7e2 0%, #e2ccb1 45%, #b49877 100%);
}

.back-link {
  position: fixed;
  top: 18px;
  left: 18px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
  border: 1px solid rgba(21, 20, 18, 0.12);
  box-shadow: 0 12px 24px var(--shadow);
}

.back-link:hover,
.back-link:focus-visible {
  transform: translateY(-2px);
  outline: 2px solid var(--accent-dark);
  outline-offset: 2px;
}

.scene {
  width: min(960px, 100%);
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "title"
    "room"
    "panels";
}

.title {
  text-align: center;
  padding: 16px 24px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 12px 30px var(--shadow);
  position: relative;
  overflow: hidden;
  grid-area: title;
}

.title::after {
  content: "";
  position: absolute;
  inset: -60% 0 auto 0;
  height: 120%;
  background: radial-gradient(circle at center, rgba(217, 167, 91, 0.4), transparent 70%);
  pointer-events: none;
}

.title h1 {
  font-family: "Fraunces", "Yu Mincho", serif;
  font-size: clamp(2rem, 4vw, 3.2rem);
  margin: 4px 0 8px;
  letter-spacing: 0.04em;
}

.difficulty {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: inset 0 0 0 1px rgba(21, 20, 18, 0.12);
  font-size: 0.85rem;
}

.difficulty label {
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--ink-soft);
}

.difficulty select {
  border: 1px solid rgba(21, 20, 18, 0.2);
  border-radius: 999px;
  padding: 4px 12px;
  background: #fff;
  font-weight: 600;
  font-family: inherit;
}

.subtitle {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.tagline {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.room {
  position: relative;
  min-height: clamp(360px, 55vh, 520px);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 20px 40px var(--shadow);
  background: linear-gradient(180deg, #f2e5d3 0%, #e2d1bc 60%, #c8b097 100%);
  transition: filter 0.4s ease;
  grid-area: room;
  display: flex;
  flex-direction: column;
}

.room[data-wall="0"] {
  background: radial-gradient(circle at top, rgba(217, 167, 91, 0.4), transparent 65%),
    linear-gradient(180deg, #f2e5d3 0%, #e2d1bc 60%, #c8b097 100%);
}

.room[data-wall="1"] {
  background: radial-gradient(circle at 20% 30%, rgba(206, 95, 58, 0.35), transparent 60%),
    linear-gradient(180deg, #f2e5d3 0%, #e2d1bc 60%, #c8b097 100%);
}

.room[data-wall="2"] {
  background: radial-gradient(circle at 80% 30%, rgba(106, 91, 79, 0.35), transparent 60%),
    linear-gradient(180deg, #f2e5d3 0%, #e2d1bc 60%, #c8b097 100%);
}

.room[data-wall="3"] {
  background: radial-gradient(circle at 50% 70%, rgba(21, 20, 18, 0.25), transparent 65%),
    linear-gradient(180deg, #f2e5d3 0%, #e2d1bc 60%, #c8b097 100%);
}

.panels {
  grid-area: panels;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-areas:
    "inventory hints"
    "log log";
  gap: 20px;
}

.room.is-bright {
  filter: brightness(1.12) saturate(1.12);
}

.room.is-bright::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255, 245, 220, 0.55), transparent 70%);
  animation: glow 3s ease-in-out infinite;
  pointer-events: none;
}

.walls {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.wall {
  display: none;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  align-items: center;
  justify-items: center;
  column-gap: 18px;
  row-gap: 18px;
  padding: 24px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.08);
}

.wall.is-active {
  display: grid;
  animation: wallFade 0.25s ease;
}


.floor {
  height: 80px;
  background: linear-gradient(180deg, #8a6f52 0%, #6b513a 100%);
  box-shadow: inset 0 10px 20px rgba(0, 0, 0, 0.25);
}

.nav {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.nav-btn {
  pointer-events: auto;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
  letter-spacing: 0.05em;
  cursor: pointer;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
}

.nav-btn:hover,
.nav-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.compass {
  pointer-events: none;
  position: relative;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 12px;
  padding: 6px 12px;
  min-width: 64px;
  text-align: center;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
  gap: 2px;
}

.compass.has-unvisited::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px rgba(206, 95, 58, 0.7);
  animation: blink 1.2s ease-in-out infinite;
}

.compass-label {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.compass-face {
  font-weight: 700;
  font-size: 1.1rem;
}

.compass-note {
  font-size: 0.65rem;
  color: var(--accent-dark);
  letter-spacing: 0.14em;
}

@keyframes blink {
  0%,
  100% {
    opacity: 0.2;
    transform: scale(0.9);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes glow {
  0%,
  100% {
    opacity: 0.15;
  }
  50% {
    opacity: 0.45;
  }
}

@keyframes hintGlow {
  0%,
  100% {
    box-shadow: 0 0 0 2px rgba(206, 95, 58, 0.15), 0 10px 22px rgba(21, 20, 18, 0.16);
  }
  50% {
    box-shadow: 0 0 0 3px rgba(206, 95, 58, 0.28), 0 16px 26px rgba(21, 20, 18, 0.22);
  }
}

@keyframes tap {
  0% {
    transform: scale(1);
  }
  30% {
    transform: scale(0.98) rotate(-1deg);
  }
  60% {
    transform: scale(1.02) rotate(1deg);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes safeFlash {
  0% {
    opacity: 0;
    transform: scale(0.9);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1.05);
  }
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-6px);
  }
  40% {
    transform: translateX(6px);
  }
  60% {
    transform: translateX(-4px);
  }
  80% {
    transform: translateX(4px);
  }
}

@keyframes wallFade {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.object {
  border: none;
  border-radius: 16px;
  background: #fdf6ec;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 10px 20px rgba(21, 20, 18, 0.12);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 320px;
  height: 160px;
  background-repeat: no-repeat;
  background-position: center 58%;
  background-size: 80% auto;
}

.object.is-unseen {
  box-shadow: 0 0 0 2px rgba(206, 95, 58, 0.18), 0 10px 24px rgba(21, 20, 18, 0.18);
  animation: hintGlow 1.6s ease-in-out infinite;
}

.object.is-tapped {
  animation: tap 0.35s ease;
}

.object::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 12px;
  border: 1px dashed rgba(21, 20, 18, 0.15);
}

.object:hover,
.object:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 16px 24px rgba(21, 20, 18, 0.2);
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.label {
  display: none;
}

.poster {
  background-image: url("assets/poster.svg"), linear-gradient(160deg, #fbf1e3, #e6d3bd);
  background-size: 68% auto, cover;
  background-position: center 56%, center;
}

.shelf {
  background-image: url("assets/shelf.svg"), linear-gradient(160deg, #d3b98f, #b69a74);
  background-size: 72% auto, cover;
  background-position: center 60%, center;
}

.safe {
  background-image: url("assets/safe-closed.svg"), linear-gradient(160deg, #c7c2bb, #9b9288);
  background-size: 64% auto, cover;
  background-position: center 58%, center;
}

.safe.is-open {
  background-image: url("assets/safe-open.svg"), linear-gradient(160deg, #c7c2bb, #9b9288);
}

.safe.is-opening::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 12px;
  background: radial-gradient(circle at center, rgba(255, 232, 190, 0.8), transparent 70%);
  animation: safeFlash 0.8s ease;
  pointer-events: none;
}

.clock {
  background-image: url("assets/clock.svg"), linear-gradient(160deg, #efe6da, #cdbba7);
  background-size: 66% auto, cover;
  background-position: center 56%, center;
}

.clock::after {
  content: attr(data-time);
  position: absolute;
  bottom: 20px;
  right: 20px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(15, 12, 10, 0.6);
  color: #f7efe5;
  font-weight: 600;
  letter-spacing: 0.08em;
  font-size: 0.85rem;
}

.drawer {
  background-image: url("assets/drawer.svg"), linear-gradient(160deg, #d3b98f, #b69a74);
  background-size: 70% auto, cover;
  background-position: center 60%, center;
}

.door {
  background-image: url("assets/door.svg"), linear-gradient(160deg, #80563e, #5b3b2a);
  background-size: 70% auto, cover;
  background-position: center 62%, center;
  color: #fef3e2;
  height: 180px;
}

.door-note {
  background-image: url("assets/door-note.svg"), linear-gradient(160deg, #f1e0c9, #d7c1a2);
  background-size: 62% auto, cover;
  background-position: center 60%, center;
  min-height: 140px;
  width: min(200px, 70%);
}

.door .status {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(15, 12, 10, 0.55);
  color: var(--glow);
}

.inventory,
.log,
.hints {
  background: rgba(255, 255, 255, 0.82);
  border-radius: 18px;
  padding: 16px 20px;
  box-shadow: 0 12px 24px var(--shadow);
}

.inventory {
  grid-area: inventory;
  display: flex;
  flex-direction: column;
  height: clamp(150px, 18vh, 210px);
}

.hints {
  grid-area: hints;
  display: flex;
  flex-direction: column;
  height: clamp(150px, 18vh, 210px);
}

.log {
  grid-area: log;
  display: flex;
  flex-direction: column;
  height: clamp(180px, 22vh, 240px);
}

.inventory h2,
.log h2,
.hints h2 {
  margin: 0 0 10px;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

.items {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.item {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 600;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
  display: none;
  width: 96px;
  height: 36px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 60% auto;
  color: transparent;
  text-indent: -999px;
  overflow: hidden;
}

.item[data-item="key"] {
  background-image: url("assets/key.svg");
}

.item[data-item="memo"] {
  background-image: url("assets/memo.svg");
  background-size: 68% auto;
}

.item.is-visible {
  display: inline-flex;
  cursor: pointer;
}

.log ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 6px;
}

.log li {
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(217, 167, 91, 0.12);
}

.log.is-new h2::after {
  content: "NEW";
  margin-left: 8px;
  font-size: 0.65rem;
  letter-spacing: 0.18em;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}

.hints ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink-soft);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.hints li {
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(122, 53, 32, 0.08);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 10, 0.45);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 10;
}

#clear-modal {
  background: rgba(255, 245, 230, 0.22);
}

.modal[hidden] {
  display: none;
}

.modal-card {
  background: var(--paper);
  border-radius: 16px;
  padding: 24px;
  width: min(360px, 100%);
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.modal-card.is-shake {
  animation: shake 0.35s ease;
}

.item-card {
  width: min(420px, 100%);
}

.item-preview {
  display: grid;
  place-items: center;
  margin: 10px 0 8px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(21, 20, 18, 0.05);
}

.item-preview img {
  width: min(200px, 100%);
  height: auto;
}

.modal-card h2 {
  font-family: "Fraunces", "Yu Mincho", serif;
  margin-top: 0;
}

.modal-card .epilogue {
  margin: 8px 0 0;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.modal-card input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1.1rem;
  border-radius: 10px;
  border: 1px solid rgba(21, 20, 18, 0.2);
  margin-top: 8px;
  text-align: center;
  letter-spacing: 0.2em;
  font-family: "Space Grotesk", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
}

button.primary {
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease;
}

button.primary:hover,
button.primary:focus-visible {
  transform: translateY(-2px);
  outline: 2px solid var(--accent-dark);
  outline-offset: 2px;
}

button.ghost {
  border: 1px solid rgba(21, 20, 18, 0.2);
  padding: 10px 18px;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

a.ghost {
  border: 1px solid rgba(21, 20, 18, 0.2);
  padding: 10px 18px;
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 720px) {
  .back-link {
    top: 12px;
    left: 12px;
  }

  .panels {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "inventory"
      "hints"
      "log";
  }

  .floor {
    height: 70px;
  }

  .nav {
    position: static;
    margin: 12px 16px 16px;
    pointer-events: auto;
  }

  .object {
    height: 150px;
  }

  .door {
    height: 180px;
  }
}

@media (min-width: 900px) {
  .scene {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "title"
      "room"
      "panels";
    align-items: start;
  }
}
