/* Colors follow the Caricotto business card: deep green ground, black polka dots, pink brush lines. */
:root {
  --bg: #222F28;
  --bg-deep: #18221D;
  --bg-deeper: #141C18;
  --outside: #0D1310;
  --ink: #F6EAF0;
  --ink-soft: #E9DCE3;
  --muted: #C3B6BD;
  --pink: #EDB8D8;
  --pink-hi: #F6D3E5;
  --plum: #3A2834;
  --line: #5B4B55;
  --dash: #8A7A84;
  --dot: #060707;
  --hand: 'Klee One', serif;
  --sans: 'Zen Kaku Gothic New', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--outside); color-scheme: dark; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--outside);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  /* Avoid a lone character on the last line of Japanese sentences (ignored where unsupported). */
  text-wrap: pretty;
  line-break: strict;
}

a { color: var(--pink); }
a:hover { color: var(--pink-hi); }
img { max-width: 100%; }

.app {
  position: relative;
  isolation: isolate;
  max-width: 430px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  /* Keeps the content clear of the clock and notch when opened from the home screen. */
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
  /* clip, unlike hidden, does not make .app a scroll box, so the sticky nav sticks to the screen. */
  overflow: clip;
}

.polka { position: fixed; inset: 0; max-width: 430px; margin: 0 auto; z-index: -1; pointer-events: none; overflow: hidden; }
.polka span { position: absolute; border-radius: 50%; background: var(--dot); }

main { flex: 1; display: flex; flex-direction: column; padding-bottom: 12px; }

/* ---------- type helpers ---------- */
.muted { color: var(--muted); }
.pink { color: var(--pink); }
.small { font-size: 14px; }
/* Text sizes by role; 12px is the floor, kept for footnotes only. */
.tiny { font-size: 12px; }
.strong { font-weight: 700; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.spaced { letter-spacing: 0.08em; }
.title { margin: 0; font-family: var(--hand); font-weight: 600; font-size: 25px; line-height: 1.5; }
.sub { margin: 24px 0 10px; font-family: var(--hand); font-weight: 600; font-size: 18px; color: var(--pink); }
.lead { margin: 20px 32px 0; font-family: var(--hand); font-size: 17px; line-height: 1.75; text-align: center; }
.pad { padding: 0 24px; }

/* ---------- header ---------- */
.top { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px 12px; }
.top.back { justify-content: flex-start; gap: 8px; padding: 14px 16px 6px; }
.brand { display: flex; flex-direction: column; gap: 2px; }
.logo-sm { height: 28px; width: auto; display: block; }
.chip { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 13px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; color: var(--ink); text-decoration: none; }

/* ---------- window ---------- */
.window {
  position: relative;
  aspect-ratio: 330 / 348;
  max-height: 46vh;
  margin: 4px auto 0;
  border: 3px solid var(--pink);
  border-radius: 200px 200px 14px 14px;
  overflow: hidden;
  background: #E3E8E6;
}
.window svg { display: block; width: 100%; height: 100%; }
/* The picture left from the previous visit, fading into the new one. */
.window svg.ghost { position: absolute; inset: 0; pointer-events: none; animation: ghost-out 0.9s ease-in-out forwards; }
@keyframes ghost-out { from { opacity: 1; } to { opacity: 0; } }
.window.night { background: #161D2C; }
.window.tappable { cursor: pointer; }
.window-loading {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--bg-deep);
  color: var(--muted);
  font-family: var(--hand);
  font-size: 16px;
  line-height: 1.8;
}
.hint { margin: 8px 24px 0; font-size: 13px; }

.narrative { margin: 18px 24px 0; font-family: var(--hand); font-size: 17px; line-height: 1.7; text-align: center; }

.progress { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 12px; }
.dots { display: flex; gap: 6px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--dash); }
.dots span.on { background: var(--pink); border-color: var(--pink); }

/* ---------- cards ---------- */
.card { margin: 16px 24px 0; padding: 14px 16px; background: var(--bg-deep); border-radius: 12px; display: flex; flex-direction: column; gap: 6px; }
.card.outline { background: rgba(24, 34, 29, 0.6); border: 1px solid var(--line); padding: 12px 16px; }
.card .label { font-size: 13px; color: var(--pink); letter-spacing: 0.06em; }
.clue-main { font-size: 16px; line-height: 1.6; }
.clue-sub { font-size: 14px; line-height: 1.6; color: var(--muted); }
.card.list { padding: 4px 0; gap: 0; margin: 0; }
.card.text { margin: 0; line-height: 1.7; font-size: 14px; }
.card.text p { margin: 0 0 8px; }
.card.text p:last-child { margin: 0; }

.link-row {
  display: flex;
  width: 100%;
  box-sizing: border-box;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
  padding: 0 16px;
  background: none;
  border: 0;
  border-bottom: 1px solid rgba(91, 75, 85, 0.6);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}
.link-row:last-child { border-bottom: 0; }

/* ---------- buttons ---------- */
.actions { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.btn {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 52px;
  padding: 0 20px;
  border: 0;
  border-radius: 26px;
  background: var(--pink);
  color: var(--bg);
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { color: var(--bg); background: var(--pink-hi); }
.btn:disabled { background: var(--line); color: var(--muted); cursor: default; }
.btn-sub { font-weight: 500; font-size: 13px; }
.btn.ghost { background: none; border: 1px solid var(--pink); color: var(--pink); min-height: 48px; }
.btn.ghost:hover { background: rgba(237, 184, 216, 0.08); }
.btn.danger { border-color: var(--dash); color: var(--muted); margin-top: 24px; }
.btn.small { width: auto; min-height: 36px; padding: 0 18px; border-radius: 18px; font-size: 14px; }
.two { margin-top: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.two .btn { min-height: 48px; font-size: 15px; }
:focus-visible { outline: 2px solid var(--pink-hi); outline-offset: 3px; }

.answered { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--bg-deep); }
.answered-text { display: flex; flex-direction: column; gap: 2px; font-size: 15px; }
.answered.missed .swatch { opacity: 0.5; }

/* ---------- swatches ---------- */
.swatch { display: inline-block; flex: none; border-radius: 50%; border: 2px solid var(--line); }
.unknown-swatch {
  width: 52px;
  height: 52px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--dot);
  border: 0;
  color: var(--pink);
  font-family: var(--hand);
  font-size: 22px;
}

/* ---------- intro ---------- */
.intro { display: flex; flex-direction: column; align-items: center; padding-bottom: 32px; }
.intro-illust { margin-top: 48px; width: 236px; height: auto; }
.intro-logo { margin-top: 20px; width: 220px; height: auto; }
.intro .lead { color: var(--pink); }
.steps { margin: 22px 24px 0; align-self: stretch; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.step { padding: 10px 6px; background: var(--bg-deep); border: 1.5px solid var(--pink); border-radius: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; font-size: 13px; line-height: 1.5; }
/* Each line is kept whole: the narrow cards otherwise break 「近づいてくる」 mid-word on iPhone. */
.step-text { display: flex; flex-direction: column; align-items: center; }
.step-text span { white-space: nowrap; }
.step-title { font-family: var(--hand); font-size: 15px; font-weight: 600; color: var(--pink); }
.note { margin: 14px 24px 0; font-size: 13px; color: var(--muted); }
.intro .btn { margin: 20px 24px 0; width: calc(100% - 48px); }

/* ---------- guess ---------- */
.guess-head { margin: 4px 24px 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.deco-cat { width: 96px; height: auto; flex: none; }
.patterns { margin: 22px 24px 0; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); row-gap: 18px; column-gap: 8px; }
.pattern { display: flex; flex-direction: column; align-items: center; gap: 6px; background: none; border: 0; padding: 0; color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; }
.pattern:disabled { cursor: default; }
.pattern:disabled:not(.selected) { opacity: 0.45; }
.pattern.selected { color: var(--pink); font-weight: 700; }
.pattern.selected .swatch { border: 3px solid var(--pink); box-shadow: 0 0 0 3px var(--bg), 0 0 0 4px var(--pink); }
.bottom { margin-top: auto; padding-top: 24px; padding-bottom: 32px; display: flex; flex-direction: column; gap: 12px; }
.bottom p { margin: 0; }

/* ---------- reveal ---------- */
.reveal { margin: 14px 24px 0; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.reveal .title { font-size: 26px; font-weight: 700; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: 999px; background: var(--plum); color: var(--pink-hi); font-size: 13px; font-weight: 700; }
.badge.quiet { background: var(--bg-deep); color: var(--muted); font-weight: 500; }
.badge.rare { background: var(--pink); color: var(--bg); }
.event-note { margin: -4px 16px 8px; }
.letter { margin-top: 6px; display: flex; align-items: center; gap: 10px; text-align: left; }
.letter img { width: 44px; height: 44px; flex: none; }
.letter p { margin: 0; font-family: var(--hand); font-size: 15px; line-height: 1.6; color: var(--ink-soft); }
.product { margin-top: 16px; padding: 12px; display: flex; align-items: center; gap: 12px; background: var(--bg-deeper); border-radius: 12px; text-decoration: none; color: var(--ink); }
.product:hover { color: var(--ink); }
.product-photo { width: 56px; height: 56px; flex: none; border-radius: 8px; background: #2C3A33; display: flex; align-items: center; justify-content: center; color: var(--pink); }
.product-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; font-size: 15px; }
.foot { margin: 20px 24px 8px; }

.eyes-closed { display: none; }
.petting .eyes-open { display: none; }
.petting .eyes-closed { display: inline; }
.petting .cat-hit { animation: purr 0.4s ease-in-out 3; transform-box: fill-box; transform-origin: 50% 100%; }
.heart { position: absolute; bottom: 30%; color: var(--pink); font-size: 22px; pointer-events: none; animation: float-up 1.6s ease-out forwards; }

/* ---------- zukan ---------- */
.zukan-head { padding: 22px 24px 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.zukan-head > div { display: flex; flex-direction: column; gap: 4px; }
.zukan-head .title { font-size: 27px; }
.paws { display: inline-flex; align-items: center; gap: 4px; }
.grid { margin: 18px 24px 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.cell { padding: 12px 6px; border-radius: 14px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font: inherit; color: var(--ink); }
.cell.found { background: var(--bg-deep); border: 1.5px solid var(--pink); cursor: pointer; }
.cell.found.new { background: var(--plum); }
.cell.unknown { border: 1.5px dashed var(--dash); }
.cell.rare { background: var(--bg-deep); border: 1.5px solid var(--dash); }
.cell .small { font-size: 13px; }
.cell-name { display: flex; flex-direction: column; align-items: center; max-width: 100%; line-height: 1.5; }
.cell-name span { max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.letter .small { font-size: 13px; }

/* ---------- about ---------- */
.about { padding: 0 24px 24px; display: flex; flex-direction: column; }
.about-illust { margin: 32px auto 0; width: 180px; }
.about-logo { margin: 16px auto 0; width: 180px; }
.about .lead { margin: 16px 0 8px; font-size: 15px; }
.switch { appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; cursor: pointer; transition: background 0.2s; margin: 0; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--ink); transition: transform 0.2s; }
.switch:checked { background: var(--pink); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- nav ---------- */
.nav {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  padding: 10px 8px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  z-index: 5;
}
.nav[hidden] { display: none; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); text-decoration: none; min-height: 44px; }
.nav a.active { color: var(--pink); }

/* ---------- modal & toast ---------- */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(6, 7, 7, 0.7); }
.modal-card {
  position: relative;
  width: 100%;
  max-width: 430px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 8px 24px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 3px solid var(--pink);
  border-radius: 24px 24px 0 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: rise 0.25s ease-out;
}
.modal-card p { margin: 0; line-height: 1.7; }
.modal-x {
  position: sticky;
  top: 0;
  z-index: 2;
  align-self: flex-end;
  width: 40px;
  height: 40px;
  margin: 0 -12px -40px 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  flex: none;
}
.text-input { min-height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg-deep); color: var(--ink); font: inherit; font-size: 16px; }
.text-input::placeholder { color: var(--dash); }
.transfer-code { min-height: 84px; padding: 10px 14px; line-height: 1.4; word-break: break-all; resize: none; }
.share-preview { width: 100%; max-height: 50vh; object-fit: contain; border-radius: 12px; }
.detail { display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; }
.portrait { width: 150px; margin-top: 12px; }
.letters { align-self: stretch; margin: 8px 0; display: flex; flex-direction: column; gap: 8px; text-align: left; }
.letter-line { display: flex; align-items: center; gap: 8px; font-family: var(--hand); font-size: 15px; }
.letter-line img { width: 32px; height: 32px; flex: none; }
.letter-line img.faded { opacity: 0.3; }
.letter-line .tiny { font-family: var(--sans); }
.murmur { display: block; padding-left: 1em; text-indent: -1em; }
.phrase { display: inline-block; text-indent: 0; }
.letter.sealed img { opacity: 0.5; }
.gift-badge svg { flex: none; }
.bond { align-self: stretch; display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 4px; padding: 12px; border-radius: 14px; background: var(--bg-deep); }
.gifts { display: flex; justify-content: center; gap: 10px; }
.gift-cell { width: 76px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; border-radius: 12px; background: var(--bg); line-height: 1.3; }
.gift-q { height: 28px; font-size: 18px; line-height: 28px; color: var(--dash); }

.toast {
  position: fixed;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top));
  transform: translate(-50%, -20px);
  max-width: min(360px, calc(100% - 48px));
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--plum);
  color: var(--pink-hi);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.noscript { padding: 24px; text-align: center; }

/* ---------- play-test panel ---------- */
.debug { position: fixed; bottom: calc(84px + env(safe-area-inset-bottom)); right: 8px; opacity: 0.9; z-index: 40; padding: 8px 10px; background: rgba(6, 7, 7, 0.85); border: 1px solid var(--pink); border-radius: 10px; font-size: 11px; color: var(--ink); }
#modal:not([hidden]) ~ .debug { display: none; }
.debug-row { display: flex; gap: 4px; margin-top: 6px; }
.debug button { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; cursor: pointer; }

/* ---------- motion ---------- */
.fx-cross { animation: cross 7s ease-in-out forwards; }
.fx-rain { animation: fall 0.9s linear infinite; }
.fx-snow { animation: fall 12s linear infinite; }
.fx-sway { animation: sway 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: 0% 100%; }

@keyframes cross {
  0% { transform: translateX(-90px); }
  45% { transform: translateX(150px); }
  60% { transform: translateX(165px); }
  100% { transform: translateX(400px); }
}
@keyframes fall { from { transform: translateY(0); } to { transform: translateY(348px); } }
@keyframes sway { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg); } }
@keyframes purr { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.015, 0.985); } }
@keyframes float-up { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-80px); opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .fx-rain, .fx-snow, .fx-sway, .petting .cat-hit { animation: none; }
  .fx-cross { animation-duration: 10s; }
}

@media (min-width: 600px) {
  body { padding: 24px 0; }
  .app { min-height: calc(100vh - 48px); border-radius: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
}
