:root {
  --bg: #fbfaf7;
  --bg-deep: #f5f4ef;
  --surface: #fffefa;
  --surface-raised: #f0efe9;
  --text: #272a27;
  --text-soft: #515750;
  --muted: #70756d;
  --line: #dcded5;
  --line-strong: #a9afa3;
  --accent: #e9ece3;
  --accent-ink: #303a2f;
  --focus: #596d53;
  --danger-soft: #80635b;
  --shadow: rgba(32, 38, 27, 0.12);
  --blink-duration: 7.8s;
  --tail-duration: 9s;
  color-scheme: light;
  font-family: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  min-height: 100%;
  overflow-x: hidden;
  background: var(--bg);
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  color: inherit;
}

a {
  color: var(--text-soft);
  text-decoration-color: var(--line-strong);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.28em;
}

a:hover {
  color: var(--text);
  text-decoration-color: currentColor;
}

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

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 1280px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) clamp(18px, 4vw, 56px) max(22px, env(safe-area-inset-bottom));
}

.site-header,
.site-footer {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.network-mark {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.18em;
}

.companion {
  position: relative;
  flex: 1;
  min-height: clamp(650px, 78vh, 840px);
  padding: clamp(28px, 5vh, 62px) 0;
}

.room {
  position: absolute;
  inset: 2% -10% 3%;
  overflow: hidden;
  background:
    linear-gradient(90deg, transparent 0 13%, rgba(147, 165, 152, 0.055) 13% 13.2%, transparent 13.2% 100%),
    linear-gradient(180deg, rgba(151, 169, 156, 0.045), transparent 42%);
  opacity: 1;
  pointer-events: none;
}

.room::after {
  content: "";
  position: absolute;
  left: 1%;
  right: 1%;
  bottom: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(155, 172, 159, 0.24) 18%, rgba(155, 172, 159, 0.13) 67%, transparent);
  box-shadow: 0 28px 70px rgba(4, 8, 6, 0.45);
}

.room-line {
  position: absolute;
  display: block;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(125, 138, 128, 0.16), transparent);
}

.room-line-one {
  top: 4%;
  bottom: 22%;
  left: 13%;
}

.room-line-two {
  top: 20%;
  bottom: 10%;
  left: 87%;
}

.room-glow {
  position: absolute;
  width: 42%;
  height: 72%;
  left: -3%;
  top: 3%;
  background: linear-gradient(135deg, rgba(141, 161, 146, 0.12), transparent 68%);
  filter: blur(36px);
}

.cat-stage {
  --cat-size: clamp(210px, 25vw, 340px);
  --cat-opacity: 1;
  position: absolute;
  z-index: 2;
  width: var(--cat-size);
  margin: 0;
  opacity: var(--cat-opacity);
  transform-origin: 0 0;
}

.cat-pet-zone {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: ew-resize;
}

.cat-pet-zone:focus-visible {
  outline: 2px dashed var(--focus);
  outline-offset: 7px;
  border-radius: 45%;
}

.cat-pose {
  display: block;
  width: 100%;
  height: auto;
  filter: brightness(1.1) contrast(1.02) drop-shadow(0 20px 18px rgba(0, 0, 0, 0.42));
  transition: opacity 180ms ease, filter 500ms ease;
}

.cat-stage[data-place="far_corner"] {
  --cat-size: clamp(260px, 26vw, 360px);
  --cat-opacity: .96;
  left: 2%;
  top: 30%;
  right: auto;
  bottom: auto;
  filter: saturate(.9) brightness(.98);
}

.cat-stage[data-place="near_card"] {
  --cat-size: clamp(270px, 27vw, 370px);
  left: 5%;
  top: calc(89% - var(--cat-size) * 2 / 3);
  right: auto;
  bottom: auto;
}

.cat-stage[data-place="under_title"] {
  --cat-size: clamp(210px, 20vw, 285px);
  --cat-opacity: .96;
  left: 32%;
  top: 16%;
  right: auto;
  bottom: auto;
}

.cat-stage[data-place="screen_edge"] {
  --cat-size: clamp(275px, 28vw, 380px);
  left: -8%;
  top: calc(91% - var(--cat-size) * 2 / 3);
  right: auto;
  bottom: auto;
}

.cat-stage[data-place="foreground"] {
  --cat-size: clamp(330px, 36vw, 470px);
  left: 3%;
  top: calc(105% - var(--cat-size) * 2 / 3);
  right: auto;
  bottom: auto;
  z-index: 4;
}

.cat-stage[data-place="beside_user"] {
  --cat-size: clamp(230px, 23vw, 310px);
  left: 18%;
  top: calc(95% - var(--cat-size) * 2 / 3);
  right: auto;
  bottom: auto;
}

.cat-stage[data-activity="walking"] .cat-pose,
.cat-stage[data-activity="returning"] .cat-pose,
.cat-stage[data-activity="leaving"] .cat-pose {
  animation: walk-weight var(--walk-cycle, 520ms) ease-in-out infinite;
}

.cat-stage[data-pose="sleep_curl"] .cat-pose {
  animation: sleeping-breath 6.8s ease-in-out infinite;
  transform-origin: 48% 76%;
}

.cat-eyelid {
  display: none;
  position: absolute;
  width: 5.2%;
  height: 6.8%;
  top: 32.6%;
  border-radius: 50%;
  background: url('/assets/cat/poses/loaf.webp') 26.6% 31.2% / 1923% 1470%;
  box-shadow: inset 0 -1px 0 #191b1a;
  transform: scaleY(0);
  transform-origin: center top;
  pointer-events: none;
}
.cat-eyelid-left { left: 25.3%; }
.cat-eyelid-right { left: 37.8%; top: 33.2%; background-position: 39.8% 31.2%; }
.cat-stage[data-pose="loaf"][data-activity="slow-blink"] .cat-eyelid {
  display: block;
  animation: slow-blink 900ms ease-in-out 1;
}
@keyframes slow-blink {
  0%, 100% { transform: scaleY(0); }
  35%, 65% { transform: scaleY(1); }
}

.content-panel {
  position: relative;
  pointer-events: none;
  z-index: 3;
  width: 100%;
  max-width: 540px;
  min-width: 0;
  min-height: 600px;
  margin-left: auto;
  margin-right: clamp(0px, 4vw, 54px);
  padding-top: clamp(76px, 11vh, 124px);
}

/* The room-sized transparent padding must not intercept petting. */
.content-panel > * {
  pointer-events: auto;
}

.eyebrow {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.8;
  letter-spacing: 0.05em;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5.4vw, 4.1rem);
  font-weight: 400;
  line-height: 1.35;
  letter-spacing: 0.03em;
  overflow-wrap: anywhere;
}

.entrust-form,
.active-card {
  margin-top: clamp(42px, 8vh, 72px);
}

.entrust-form label,
.card-label {
  display: block;
  margin: 0 0 14px;
  color: var(--text-soft);
  font-size: 0.83rem;
  line-height: 1.7;
  letter-spacing: 0.04em;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: stretch;
}

input {
  width: 100%;
  min-width: 0;
  min-height: 50px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--text);
}

input:hover,
input:focus {
  border-color: var(--line-strong);
}

.primary-button,
.quiet-button,
.beside-button,
.danger-quiet-button,
.text-button {
  min-height: 46px;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  padding: 10px 18px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

.primary-button:hover {
  background: #dde3d6;
  border-color: #c2ccb8;
}

.quiet-button,
.beside-button,
.danger-quiet-button {
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text-soft);
}

.quiet-button:hover,
.beside-button:hover {
  border-color: var(--text-soft);
  color: var(--text);
}

.danger-quiet-button {
  border-color: #77625f;
  color: var(--danger-soft);
}

.danger-quiet-button:hover {
  border-color: var(--danger-soft);
  color: var(--text);
}

.field-help,
.field-error,
.status-message,
.compact-note {
  min-height: 1.7em;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.7;
}

.field-error {
  color: var(--danger-soft);
}

.card-text {
  min-height: 3.4em;
  margin: 0;
  color: var(--text);
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
}

.beside-button {
  width: 100%;
  margin-top: 18px;
}

.site-footer {
  padding-top: 10px;
}

.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 24px;
}

.site-footer a,
.text-button {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.74rem;
}

.text-button {
  padding: 0;
  border: 0;
  background: transparent;
  text-decoration: underline;
  text-decoration-color: var(--line-strong);
  text-underline-offset: 0.28em;
}

.text-button:hover {
  color: var(--text);
}

body.is-compact .site-footer,
body.is-compact .eyebrow,
body.is-compact .room,
body.is-compact .network-mark {
  display: none;
}

body.is-compact .app-shell {
  width: min(100%, 460px);
  padding: 14px;
}

body.is-compact .site-header {
  justify-content: flex-end;
}

body.is-compact .companion {
  min-height: 0;
  padding: 0;
}

body.is-compact .cat-stage {
  position: relative;
  inset: auto;
  width: min(82vw, 330px);
  margin: 0 auto -22px;
  filter: none;
}

body.is-compact .content-panel {
  min-height: 0;
  margin: 0 auto;
  padding: 0;
  text-align: center;
}

body.is-compact h1 {
  display: none;
}

body.is-compact .active-card {
  margin-top: 0;
}

body.is-compact .card-actions {
  justify-content: center;
}

body.is-compact .beside-button {
  display: none;
}

.reading-page {
  background: var(--bg);
}

.reading-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(34px, env(safe-area-inset-top)) clamp(18px, 5vw, 52px) max(54px, env(safe-area-inset-bottom));
}

.reading-shell h1 {
  margin-top: clamp(62px, 12vh, 112px);
  font-size: clamp(1.9rem, 6vw, 3rem);
}

.reading-copy {
  display: grid;
  gap: 1.45em;
  margin-top: 48px;
  color: var(--text-soft);
  font-size: 1rem;
  line-height: 2.05;
}

.reading-copy p,
.reading-copy h2 {
  margin: 0;
}

.reading-copy h2 {
  margin-top: 2.2em;
  color: var(--text);
  font-size: 1.12rem;
  font-weight: 500;
}

.reading-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-top: 64px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
}

.reading-nav a,
.beside-back {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.beside-page {
  min-height: 100vh;
  background: var(--bg-deep);
}

.beside-shell {
  width: min(100%, 430px);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 18px max(18px, env(safe-area-inset-bottom));
}

.beside-cat {
  width: min(88%, 330px);
  margin: auto auto 0;
}

.beside-cat img {
  display: block;
  width: 100%;
  height: auto;
  filter: brightness(1.1) contrast(1.02) drop-shadow(0 18px 24px var(--shadow));
  transform-origin: 48% 78%;
  animation: sleeping-breath 6.8s ease-in-out infinite;
}

.beside-card {
  padding: 12px 0 0;
}

.beside-card .card-text {
  font-size: clamp(1.2rem, 6vw, 1.7rem);
}

.empty-beside {
  min-height: 3em;
  margin: 0;
  color: var(--muted);
  line-height: 1.8;
}

.beside-back {
  margin-top: auto;
  padding-top: 20px;
  color: var(--muted);
  font-size: 0.78rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@keyframes walk-weight {
  0%, 100% { transform: translateY(0) rotate(.2deg); }
  50% { transform: translateY(-3px) rotate(-.25deg); }
}

@keyframes sleeping-breath {
  0%, 100% { transform: scale(1, 1); }
  50% { transform: scale(1.006, 1.018); }
}

@media (max-width: 760px) {
  .companion {
    min-height: 760px;
    padding: 16px 0 24px;
  }

  .room {
    inset: 0 -8% 48%;
  }

  .cat-stage[data-place="far_corner"] {
    --cat-size: min(64vw, 250px);
    left: -2%;
    top: 9%;
  }

  .cat-stage[data-place="near_card"] {
    --cat-size: min(60vw, 235px);
    left: 37%;
    top: 29%;
    bottom: auto;
  }

  .cat-stage[data-place="under_title"] {
    --cat-size: min(49vw, 190px);
    left: 34%;
    top: 15%;
  }

  .cat-stage[data-place="screen_edge"] {
    --cat-size: min(62vw, 240px);
    left: -20%;
    bottom: auto;
    top: 26%;
  }

  .cat-stage[data-place="foreground"] {
    --cat-size: min(83vw, 320px);
    left: -8%;
    bottom: auto;
    top: 21%;
  }

  .cat-stage[data-place="beside_user"] {
    --cat-size: min(54vw, 210px);
    right: -6%;
    bottom: auto;
    top: 34%;
  }

  .content-panel {
    width: auto;
    max-width: 100%;
    min-height: 0;
    margin: 0;
    padding-top: 47vh;
  }

  .eyebrow {
    margin-bottom: 12px;
  }

  h1 {
    font-size: clamp(2rem, 10vw, 3.35rem);
  }

  .entrust-form,
  .active-card {
    margin-top: 34px;
  }
}

@media (max-width: 390px) {
  .app-shell {
    padding-left: 16px;
    padding-right: 16px;
  }

  .cat-stage {
    max-width: 96vw;
  }

  .input-row {
    grid-template-columns: 1fr;
  }

  .input-row .primary-button {
    width: 100%;
  }

  .card-actions > * {
    flex: 1 1 120px;
  }

  .site-footer nav {
    gap: 0 18px;
  }
}

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

  .cat-stage {
    transition: none !important;
  }
}

body.is-hidden *,
body.is-hidden *::before,
body.is-hidden *::after {
  animation-play-state: paused !important;
}
