:root {
  color-scheme: light;
  --paper: #efe7d8;
  --paper-light: #f9f4e9;
  --paper-deep: #dfd1bc;
  --ink: #28232a;
  --muted: #776f69;
  --line: #c9baa5;
  --dark: #17131a;
  --rose: #bb5966;
  --rose-soft: #efd3d3;
  --moss: #65735a;
  --gold: #c99a45;
  --shadow: 0 10px 35px rgba(50, 38, 28, .11);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-width: 300px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 12% 2%, rgba(255, 255, 255, .65), transparent 28rem),
    linear-gradient(105deg, transparent 49.6%, rgba(95, 69, 43, .025) 50%, transparent 50.4%),
    var(--paper);
}

button, summary { font: inherit; }
button { color: inherit; }
button:focus-visible, summary:focus-visible, details:focus-visible {
  outline: 3px solid rgba(187, 89, 102, .48);
  outline-offset: 3px;
}

[hidden] { display: none !important; }

.site-home {
  position: fixed;
  z-index: 20;
  top: max(14px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-decoration: none;
  text-transform: uppercase;
}
.site-home:hover { color: var(--ink); }

.app-shell {
  width: min(720px, calc(100% - 28px));
  margin: 0 auto;
  padding: 62px 0 max(36px, env(safe-area-inset-bottom));
}

.title-row, .section-heading, .monster-heading, .speech-row, .game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.title-row { margin: 0 3px 18px; align-items: flex-end; }
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3rem, 10vw, 5.5rem);
  font-weight: 500;
  letter-spacing: -.07em;
  line-height: .78;
}
h1 span { color: var(--rose); }
h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.65rem;
  font-weight: 500;
}
.eyebrow, .section-kicker {
  margin-bottom: 7px;
  color: var(--muted);
  font-size: .69rem;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}

.text-button {
  min-height: 38px;
  padding: 7px 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 750;
}
.text-button:hover { color: var(--ink); }
.text-button:disabled { opacity: .35; cursor: default; }

.monster-card, .pocket-card, .catalogue-card, .journal-card {
  border: 1px solid rgba(116, 93, 68, .22);
  border-radius: 22px;
  background: rgba(249, 244, 233, .86);
  box-shadow: var(--shadow);
}

.monster-card {
  position: sticky;
  z-index: 9;
  top: 10px;
  padding: 14px;
  overflow: hidden;
  backdrop-filter: blur(14px);
}

.monster-heading { min-height: 24px; margin: 0 2px 8px; }
.mood-badge, .restlessness, .temporary-item {
  margin: 0;
  color: var(--muted);
  font-size: .71rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.temporary-item {
  flex: 1;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.restlessness { color: #8a3340; }
.restlessness span { display: inline-block; animation: tremble 1.2s steps(2) infinite; }

.recess {
  position: relative;
  display: block;
  width: 100%;
  height: 132px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 14px;
  background: var(--dark);
  box-shadow: inset 0 16px 30px #08070a, 0 1px 0 rgba(255, 255, 255, .8);
  cursor: pointer;
  touch-action: manipulation;
}

.darkness { position: absolute; inset: 0; }
.eyes-object {
  position: absolute;
  z-index: 1;
  top: 8px;
  left: 50%;
  width: min(78%, 390px);
  height: 112px;
  border: 0;
  pointer-events: none;
  transform: translateX(-50%);
  transition: transform .25s ease, filter .2s ease;
}

.cover {
  position: absolute;
  z-index: 2;
  inset: 0;
  border-top: 1px solid #fffaf0;
  border-radius: 13px;
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,.35) 45%, transparent 55%),
    linear-gradient(#eee6d7, #d9cbb7);
  box-shadow: 0 -8px 24px rgba(0, 0, 0, .46);
  transform: translateY(70px);
  transition: transform .38s cubic-bezier(.2,.8,.2,1), rotate .35s ease;
}
.cover::before {
  position: absolute;
  inset: 15px 17px auto;
  height: 1px;
  background: rgba(90, 69, 50, .17);
  content: "";
}
.cover-handle {
  position: absolute;
  top: 11px;
  left: 50%;
  width: 58px;
  height: 5px;
  border-radius: 9px;
  background: #aa9b88;
  box-shadow: inset 0 1px 2px rgba(56, 42, 32, .35);
  transform: translateX(-50%);
}

.monster-card[data-expression="pleased"] .cover,
.monster-card[data-expression="surprised"] .cover,
.monster-card[data-mode="playing"] .cover,
.monster-card[data-mode="staying"] .cover { transform: translateY(93px); }
.monster-card[data-expression="squint"] .eyes-object { animation: refuse .32s ease 2; }
.monster-card[data-expression="frightened"] .cover { transform: translateY(42px); }
.monster-card[data-expression="unsettled"] .eyes-object { filter: drop-shadow(0 0 7px rgba(158, 32, 49, .34)); }
.monster-card[data-expression="unsettled"] .cover { animation: panel-tremble .22s steps(2) 3; }
.monster-card[data-mode="sleeping"] .cover,
.monster-card[data-mode="hibernating"] .cover,
.monster-card[data-mode="shut"] .cover { transform: translateY(12px); }
.monster-card[data-mode="escaped"] .cover { transform: translate(7px, 82px) rotate(-2.4deg); }
.monster-card[data-mode="escaped"] .recess::after {
  position: absolute;
  z-index: 4;
  inset: 0;
  background: linear-gradient(75deg, transparent 47%, #bcae9a 48%, transparent 49%) 60% 0 / 70px 100%;
  content: "";
  pointer-events: none;
}
.monster-card[data-mode="escaped"] .eyes-object { display: none; }

.play-hint {
  position: absolute;
  z-index: 5;
  top: 24px;
  left: 50%;
  width: 64px;
  height: 64px;
  border: 2px dashed rgba(255, 244, 215, .5);
  border-radius: 50%;
  opacity: 0;
  transform: translateX(-50%);
  transition: left .3s ease, opacity .2s ease;
}
.monster-card[data-mode="playing"] .play-hint { opacity: 1; }

.speech-row { min-height: 44px; padding: 8px 3px 0; align-items: flex-start; }
.speech {
  margin: 0;
  overflow: hidden;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.03rem;
  font-style: italic;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wake-button {
  flex: none;
  min-height: 34px;
  padding: 5px 13px;
  border: 1px solid var(--ink);
  border-radius: 99px;
  background: var(--ink);
  color: var(--paper-light);
  cursor: pointer;
  font-size: .74rem;
  font-weight: 800;
}

.direct-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.soft-button {
  position: relative;
  min-height: 42px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.34);
  cursor: pointer;
  font-size: .84rem;
  font-weight: 800;
}
.soft-button:hover { background: #fffaf0; }
.soft-button:disabled { opacity: .45; cursor: default; }
.stay-progress {
  position: absolute;
  inset: auto 0 0;
  width: 0;
  height: 4px;
  background: var(--rose);
  transition: width .1s linear;
}

.needs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 10px;
}
.need { min-width: 0; }
.need-label {
  display: flex;
  justify-content: space-between;
  gap: 3px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: .61rem;
  font-weight: 800;
  text-transform: uppercase;
}
.need-label span { overflow: hidden; text-overflow: ellipsis; }
.need-track {
  height: 6px;
  overflow: hidden;
  border-radius: 9px;
  background: #d9cfc0;
}
.need-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--moss);
  transition: width .5s ease, background .3s ease;
}
.need[data-level="low"] .need-fill { background: var(--rose); }
.need[data-level="middling"] .need-fill { background: var(--gold); }

.pocket-card {
  position: sticky;
  z-index: 8;
  top: 342px;
  margin-top: 12px;
  padding: 13px 14px 14px;
  backdrop-filter: blur(14px);
}
.section-heading.compact { align-items: flex-end; }
.section-heading.compact h2 { font-size: 1.24rem; }
.section-heading.compact .section-kicker { margin-bottom: 2px; font-size: .59rem; }
.pocket-note {
  max-width: 50%;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: .7rem;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pocket { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.pocket-slot {
  position: relative;
  min-width: 0;
  min-height: 66px;
}
.slot-select {
  width: 100%;
  min-height: 66px;
  padding: 7px 24px 6px 5px;
  border: 1px dashed #b4a48f;
  border-radius: 12px;
  background: rgba(255,255,255,.25);
  cursor: pointer;
  touch-action: none;
}
.pocket-slot.is-selected .slot-select {
  border-style: solid;
  border-color: var(--rose);
  background: var(--rose-soft);
  box-shadow: 0 0 0 2px rgba(187,89,102,.13);
}
.pocket-slot.is-returning { animation: return-bounce .4s ease; }
.slot-remove {
  position: absolute;
  z-index: 2;
  top: 4px;
  right: 4px;
  display: grid;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #887b6d;
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1;
  place-items: center;
}
.slot-remove:hover { background: rgba(187, 89, 102, .13); color: #913846; }
.slot-number {
  position: absolute;
  top: 5px;
  left: 7px;
  color: var(--muted);
  font-size: .54rem;
  font-weight: 800;
}
.slot-glyph { display: block; font-size: 1.35rem; line-height: 1.35; }
.slot-label {
  display: block;
  overflow: hidden;
  font-size: .62rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pocket-slot.empty { color: #a39584; }
.pocket-slot.empty .slot-select { cursor: default; }

.catalogue-card { margin-top: 12px; padding: 22px 18px 18px; }
.catalogue-card.is-drop-target {
  border-color: var(--rose);
  box-shadow: 0 0 0 4px rgba(187, 89, 102, .14), var(--shadow);
}
.catalogue-card.is-drop-target::before {
  display: block;
  margin: -7px 0 12px;
  color: var(--rose);
  content: "Return to catalogue";
  font-size: .66rem;
  font-weight: 850;
  letter-spacing: .1em;
  text-align: center;
  text-transform: uppercase;
}
.catalogue-actions { display: flex; gap: 14px; }
.breadcrumbs {
  min-height: 38px;
  margin: 14px 0 10px;
  padding: 10px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb-separator { margin: 0 7px; color: #aa9e8e; }
.catalogue-list { display: grid; gap: 8px; }
.catalogue-button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 13px;
  width: 100%;
  min-height: 58px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbf7ee;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s ease, transform .15s ease, background .15s ease;
}
.catalogue-button:hover { border-color: #887966; background: #fffdf7; transform: translateX(2px); }
.catalogue-button:active { transform: translateX(2px) scale(.995); }
.catalogue-glyph { width: 32px; font-size: 1.5rem; text-align: center; }
.catalogue-copy strong { display: block; font-family: Georgia, serif; font-size: 1rem; font-weight: 600; }
.catalogue-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: .65rem; }
.catalogue-arrow { color: var(--rose); font-size: 1.15rem; }

.journal-card { margin-top: 12px; overflow: hidden; }
.journal-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 70px;
  padding: 14px 18px;
  cursor: pointer;
  list-style: none;
  font-family: Georgia, serif;
  font-size: 1.45rem;
}
.journal-card summary::-webkit-details-marker { display: none; }
.journal-card summary small {
  display: block;
  color: var(--muted);
  font-family: Inter, "Segoe UI", sans-serif;
  font-size: .59rem;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
}
.journal-count { color: var(--muted); font-family: Inter, sans-serif; font-size: .68rem; font-weight: 800; }
.journal-body { padding: 0 18px 18px; border-top: 1px solid var(--line); }
.journal-empty { margin: 18px 0 2px; color: var(--muted); font-size: .82rem; }
.journal-group h3 { margin: 18px 0 8px; font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; }
.journal-list { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 0; padding: 0; list-style: none; }
.journal-entry { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 8px 10px; border-radius: 10px; background: rgba(226,214,195,.52); font-size: .75rem; }
.journal-entry span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.favorite-star { color: var(--rose); }

.game-footer { padding: 22px 4px 0; color: var(--muted); font-size: .7rem; }
.game-footer p { margin: 0; }
.danger-button:hover { color: #923846; }
.load-error { padding: 16px; border: 1px solid #a84050; border-radius: 12px; background: #f6d9dc; }

.drag-ghost {
  position: fixed;
  z-index: 99;
  width: 76px;
  padding: 8px;
  border: 1px solid var(--rose);
  border-radius: 11px;
  background: #fff8ec;
  box-shadow: 0 10px 25px rgba(30,20,20,.2);
  font-size: .68rem;
  font-weight: 800;
  text-align: center;
  pointer-events: none;
  transform: translate(-50%, -65%);
}
.drag-ghost b { display: block; font-size: 1.5rem; }

@keyframes refuse { 25% { transform: translateX(calc(-50% - 5px)); } 75% { transform: translateX(calc(-50% + 5px)); } }
@keyframes return-bounce { 45% { transform: translateY(-7px); } 70% { transform: translateY(2px); } }
@keyframes tremble { 50% { transform: translateX(2px); } }
@keyframes panel-tremble { 50% { translate: 2px 0; } }

@media (max-width: 620px) {
  .app-shell { width: min(100% - 16px, 720px); padding-top: 56px; }
  .site-home { position: absolute; }
  .title-row { margin-inline: 7px; }
  .title-row > .text-button { max-width: 105px; line-height: 1.1; }
  .monster-card { top: 6px; padding: 10px; border-radius: 18px; }
  .recess { height: 110px; }
  .eyes-object { top: 0; width: min(90%, 390px); }
  .cover { transform: translateY(60px); }
  .monster-card[data-expression="pleased"] .cover,
  .monster-card[data-expression="surprised"] .cover,
  .monster-card[data-mode="playing"] .cover,
  .monster-card[data-mode="staying"] .cover { transform: translateY(79px); }
  .speech-row { min-height: 38px; }
  .direct-controls { gap: 6px; }
  .soft-button { min-height: 38px; }
  .needs { gap: 5px; margin-top: 8px; }
  .need-label { font-size: .52rem; }
  .pocket-card { top: 298px; padding: 9px 10px 10px; border-radius: 16px; }
  .section-heading.compact .section-kicker, .pocket-note { display: none; }
  .pocket { gap: 5px; margin-top: 7px; }
  .pocket-slot { min-height: 51px; }
  .slot-select { min-height: 51px; padding-block: 4px; }
  .slot-glyph { font-size: 1.16rem; }
  .slot-label { font-size: .53rem; }
  .catalogue-card { padding: 19px 12px 12px; }
  .journal-list { grid-template-columns: 1fr; }
  .game-footer { align-items: flex-start; }
}

@media (max-height: 720px) {
  .monster-card { position: relative; top: 0; }
  .pocket-card { top: 6px; }
}

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