:root {
  --ink: #2b1d2e;
  --bg: #fde7ef;
  --paper: #fff8fb;
  --pink: #ff8fb0;
  --pink-d: #e86a9a;
  --hot: #ff4f8b;
  --green: #7cc855;
  --blue: #4f86d9;
  --muted: #8a6f80;
  --night: #2d2752;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: radial-gradient(#f8cddc 1px, transparent 1px);
  background-size: 12px 12px;
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
.hidden { display: none !important; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
h1, h2, h3 { margin: 0 0 10px; font-weight: 400; font-family: 'Press Start 2P', monospace; line-height: 1.4; }
h1 { font-size: 17px; }
h3 { font-size: 12px; }
p { margin: 6px 0; line-height: 1.35; }

/* пиксельные рамки */
.card, .btn, .stage, .seg, .stat, .banner, .pop, .bubble-msg, .composer textarea, .keybox input, #dream-input {
  border: 3px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
}
.card { background: var(--paper); padding: 14px; margin: 12px 16px; border-radius: 4px; }
.card.big { margin: 0; width: min(92vw, 380px); text-align: center; }
.screen.center { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.url { font-family: monospace; word-break: break-all; background: #fff; padding: 8px; }
.err { color: #c92f66; min-height: 1.2em; }

.btn {
  font: inherit; font-weight: 800; color: var(--ink); background: #fff; padding: 10px 14px;
  border-radius: 4px; cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--pink); }
.btn.sm { padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.row .btn { flex: 1; }

/* вход */
.duo { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 6px 0 12px; }
.duo canvas { width: 64px; height: 96px; }
.bigheart { font-size: 36px; color: var(--hot); animation: beat 1s infinite; }
@keyframes beat { 50% { transform: scale(1.25); } }
.keybox { margin-top: 14px; text-align: left; }
.keybox summary { cursor: pointer; color: var(--muted); }
.keybox input { width: 100%; font: inherit; padding: 8px; margin: 8px 0; border-radius: 4px; -webkit-user-select: text; user-select: text; }
#join-btn { width: 100%; margin-top: 10px; font-size: 18px; }

/* шапка */
#app { display: flex; flex-direction: column; height: 100dvh; }
.top {
  background: var(--ink); color: #fff; padding: calc(8px + var(--safe-t)) 16px 8px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none;
}
.pair { display: flex; align-items: center; gap: 6px; font-family: 'Press Start 2P', monospace; font-size: 10px; }
.amp { color: var(--hot); }
.nm .dot { display: inline-block; width: 8px; height: 8px; background: #6b5a68; margin-right: 5px; vertical-align: middle; }
.nm.on .dot { background: #6fe36f; box-shadow: 0 0 6px #6fe36f; }
.decay { font-size: 13px; color: #f8cddc; text-align: right; }

main { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; }
.view { display: none; padding-bottom: 16px; }
.view.active { display: block; }

/* сцена */
.stage { position: relative; margin: 12px 16px 0; background: #f9d9e4; border-radius: 4px; overflow: hidden; }
.stage.night { background: var(--night); }
.stage canvas { width: 100%; aspect-ratio: 4 / 3; touch-action: manipulation; }
.tag {
  position: absolute; transform: translateX(-50%); bottom: 4%;
  background: var(--ink); color: #fff; font-family: 'Press Start 2P', monospace; font-size: 7px; padding: 3px 5px; pointer-events: none; white-space: nowrap;
}
.tag.me::after { content: ' (я)'; color: var(--pink); }

.banner { display: flex; gap: 8px; align-items: center; background: #fff4c9; margin: 12px 16px 0; padding: 8px 10px; font-size: 14px; border-radius: 4px; }
.banner span { flex: 1; }

/* переключатель персонажа */
.seg { display: flex; margin: 12px 16px 0; border-radius: 4px; overflow: hidden; background: #fff; }
.seg button { flex: 1; font: inherit; font-weight: 700; border: 0; background: transparent; padding: 9px 0; color: var(--ink); }
.seg button + button { border-left: 3px solid var(--ink); }
.seg button.on { background: var(--pink); }

/* показатели */
#panel { padding: 0 16px; }
.stat { display: flex; align-items: center; gap: 10px; background: var(--paper); margin-top: 12px; padding: 10px; border-radius: 4px; }
.stat .ico { font-size: 26px; width: 34px; text-align: center; flex: none; }
.stat .info { flex: 1; min-width: 0; }
.stat .head { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.stat .head b { font-family: 'Press Start 2P', monospace; font-weight: 400; font-size: 10px; }
.stat .head span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bar { display: grid; grid-template-columns: repeat(10, 1fr); gap: 2px; margin-top: 6px; height: 12px; }
.bar i { background: #eadbe2; border: 1px solid #cdb6c2; }
.bar i.f { background: var(--c, var(--pink)); border-color: var(--ink); }
.stat .plus { flex: none; width: 46px; height: 46px; padding: 0; font-size: 22px; background: var(--pink); }
.stat .pct { font-size: 9px; margin-left: 6px; color: var(--hot); }
.partner-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 14px; }
.partner-actions .btn { padding: 10px 4px; font-size: 14px; }
.who { margin-top: 12px; font-size: 14px; color: var(--muted); }

/* спальня */
.hint { margin: 10px 16px 0; font-size: 14px; color: var(--muted); text-align: center; }
.bed-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 16px 0; }
.bedstats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 16px 0; }
.bedstats .stat { margin: 0; flex-direction: column; align-items: stretch; text-align: center; gap: 2px; }
.bedstats .big { font-family: 'Press Start 2P', monospace; font-size: 18px; margin: 6px 0; color: var(--hot); }
.pop {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%); width: min(80%, 290px);
  background: var(--paper); padding: 10px 12px; border-radius: 4px; text-align: center; animation: popin .18s ease-out;
}
.pop .big { font-family: 'Press Start 2P', monospace; font-size: 20px; color: var(--hot); line-height: 1; margin: 4px 0; }
.pop .bar { height: 14px; }
.pop small { color: var(--muted); display: block; margin-top: 6px; }
@keyframes popin { from { transform: translateX(-50%) scale(.7); opacity: 0; } }

/* чат */
#v-chat.active { display: flex; flex-direction: column; height: 100%; padding: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: #fff; padding: 2px 8px; border: 2px solid var(--ink); margin: 6px 0; }
.bubble-msg {
  max-width: 80%; padding: 8px 10px 6px; border-radius: 4px; background: #fff; align-self: flex-start;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; line-height: 1.3;
  -webkit-user-select: text; user-select: text;
}
.bubble-msg.mine { align-self: flex-end; background: #ffd3e2; }
.bubble-msg.f { background: #e3f6d6; }
.bubble-msg .meta { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; }
.empty { text-align: center; color: var(--muted); margin-top: 30px; }
.composer { display: flex; gap: 8px; padding: 10px 16px; background: var(--bg); border-top: 3px solid var(--ink); }
.composer textarea {
  flex: 1; resize: none; font: inherit; padding: 9px 10px; border-radius: 4px; max-height: 120px; background: #fff;
  -webkit-user-select: text; user-select: text; box-shadow: none;
}
.composer .send { width: 48px; padding: 0; font-size: 20px; }

/* вкладки */
.tabs {
  flex: none; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--ink);
  padding-bottom: var(--safe-b); height: calc(var(--tabs-h) + var(--safe-b));
}
.tabs a { color: #cdb6c2; text-decoration: none; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: 'Press Start 2P', monospace; font-size: 7px; position: relative; gap: 4px; }
.tabs a .ti { font-size: 22px; font-family: system-ui; filter: grayscale(.6); }
.tabs a.on { color: #fff; background: #44304a; }
.tabs a.on .ti { filter: none; }
.badge { position: absolute; top: 6px; right: calc(50% - 26px); background: var(--hot); color: #fff; font-size: 11px; min-width: 18px; height: 18px; line-height: 18px; text-align: center; border: 2px solid var(--ink); font-style: normal; }

/* модалка / тосты */
.modal { position: fixed; inset: 0; background: rgba(43, 29, 46, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; }
#dream-input { width: 100%; font: inherit; padding: 8px; border-radius: 4px; resize: none; margin-top: 6px; -webkit-user-select: text; user-select: text; }
#toasts { position: fixed; left: 16px; right: 16px; top: calc(56px + var(--safe-t)); display: flex; flex-direction: column; gap: 8px; z-index: 30; pointer-events: none; }
.toast { background: var(--paper); border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); padding: 10px 12px; border-radius: 4px; font-weight: 600; animation: slide .25s ease-out; }
@keyframes slide { from { transform: translateY(-20px); opacity: 0; } }

.key { display: block; margin-top: 10px; word-break: break-all; background: #fff; padding: 8px; border: 2px dashed var(--ink); -webkit-user-select: all; user-select: all; }
.me-head { display: flex; gap: 12px; align-items: center; }
.me-head canvas { width: 48px; height: 72px; flex: none; }

/* ---------- v2 ---------- */
.pair { font-size: 8px; }
.nm { white-space: nowrap; }
.tag { font-size: 6px; }
.tabs { grid-template-columns: repeat(5, 1fr); }
.tabs a { font-size: 6px; }

.stat.tap { cursor: pointer; }
.stat.tap:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.stat .chev { flex: none; font-size: 20px; color: var(--muted); padding-left: 2px; }
.stat .quote { font-size: 13px; margin-top: 6px; background: #ffe9f1; border-left: 3px solid var(--hot); padding: 4px 8px; overflow-wrap: anywhere; }
.stat .hearts { font-size: 14px; letter-spacing: 1px; margin-top: 6px; min-height: 18px; }
.stat.col { flex-direction: column; align-items: stretch; }
.stat .row-top { display: flex; align-items: center; gap: 10px; }
.stat .plus.sm { width: 40px; height: 40px; font-size: 18px; }
.meals { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.meal { display: flex; align-items: center; gap: 6px; background: #fff; border: 2px solid #e6d3dc; padding: 4px 6px; border-radius: 4px; }
.meal.done { border-color: var(--green); background: #f1fbe9; }
.meal .ml { font-weight: 800; font-size: 13px; width: 84px; flex: none; }
.meal .mv { font-size: 14px; flex: 1; overflow-wrap: anywhere; }
.meal input { flex: 1; min-width: 0; font: inherit; font-size: 14px; border: 0; background: transparent; padding: 6px 2px; -webkit-user-select: text; user-select: text; outline: none; }
.meal .btn.sm { padding: 4px 9px; box-shadow: 2px 2px 0 var(--ink); border-width: 2px; }

/* шторка */
.sheet { text-align: left; max-height: 86dvh; overflow-y: auto; }
.sheet textarea { width: 100%; font: inherit; padding: 8px; border: 3px solid var(--ink); border-radius: 4px; resize: none; margin: 8px 0; -webkit-user-select: text; user-select: text; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn.hot { background: #ffd0dd; font-size: 17px; padding: 14px; }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--muted); }
.opt { background: #fff; border: 3px dashed var(--pink-d); border-radius: 4px; padding: 10px; }
.opt-head { display: flex; align-items: center; gap: 8px; }
.opt-ico { font-size: 28px; }
.or { text-align: center; color: var(--muted); margin: 10px 0 2px; font-size: 13px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0; }
.btn.choice { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 18px 6px; font-size: 14px; }
.btn.choice span { font-size: 40px; }
.flist { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.fitem { background: #ffe9f1; border-left: 3px solid var(--hot); padding: 8px; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.fitem small { display: block; color: var(--muted); margin-top: 4px; font-size: 11px; }

/* тапалка */
.tapper { margin-top: 12px; text-align: center; }
.tap-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tap-head b { font-size: 14px; text-align: left; }
#tap-combo { font-family: 'Press Start 2P', monospace; font-size: 12px; color: var(--hot); }
.tap-btn {
  margin: 8px auto 8px; width: 96px; height: 96px; border-radius: 50%; border: 4px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #ffd0dd, var(--pink) 60%, var(--pink-d));
  box-shadow: 4px 4px 0 var(--ink); display: flex; flex-direction: column; align-items: center; justify-content: center;
  font: inherit; color: var(--ink); touch-action: manipulation; cursor: pointer;
}
.tap-btn span { font-size: 38px; line-height: 1; }
.tap-btn small { font-family: 'Press Start 2P', monospace; font-size: 8px; margin-top: 6px; }
.tap-btn.pulse { animation: tappulse .18s ease-out; }
@keyframes tappulse { 50% { transform: scale(.9); box-shadow: 1px 1px 0 var(--ink); } }
.tap-meter { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 800; }
.tap-meter > div { flex: 1; }
.tap-meter .bar { margin: 0; }
.tap-sub { display: block; color: var(--muted); margin-top: 6px; white-space: pre-line; }

/* итоги */
.love-row { display: flex; align-items: baseline; gap: 12px; }
.love-num { font-family: 'Press Start 2P', monospace; font-size: 24px; color: var(--hot); }
.love-mood { font-weight: 800; }
.streak { font-size: 14px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { font-size: 11px; text-align: center; padding: 4px 2px; color: var(--muted); }
.tbl td { padding: 5px 2px; border-top: 1px dashed #e6d3dc; }
.tbl td + td { text-align: center; font-weight: 800; width: 26%; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { font-size: 18px; width: 40px; height: 36px; border: 2px solid var(--ink); background: #fff; border-radius: 4px; }
.chip.on { background: var(--pink); box-shadow: 2px 2px 0 var(--ink); }
.chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; height: 140px; align-items: end; border-bottom: 3px solid var(--ink); padding-top: 14px; }
.cd { display: flex; flex-direction: column; height: 100%; justify-content: flex-end; }
.cbars { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.cb { width: 40%; border: 2px solid var(--ink); border-bottom: 0; position: relative; min-height: 2px; }
.cb span { position: absolute; top: -14px; left: 50%; transform: translateX(-50%); font-size: 10px; font-weight: 800; }
.cl { text-align: center; font-size: 11px; color: var(--muted); padding-top: 4px; margin-bottom: -22px; }
.legend { margin-top: 28px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--ink); margin: 0 4px 0 8px; vertical-align: -1px; }

/* облачка с репликами над тамагочи */
.say {
  position: absolute; transform: translateX(-50%); max-width: 62%; width: max-content;
  background: #fff; color: var(--ink); border: 2px solid var(--ink); border-radius: 6px;
  padding: 4px 7px; font-size: 12px; font-weight: 800; line-height: 1.25; text-align: center;
  box-shadow: 2px 2px 0 var(--ink); pointer-events: none; overflow-wrap: anywhere; animation: popin2 .15s ease-out;
}
.say::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; width: 8px; height: 8px; margin-left: -4px;
  background: #fff; border-right: 2px solid var(--ink); border-bottom: 2px solid var(--ink); transform: rotate(45deg);
}
@keyframes popin2 { from { transform: translateX(-50%) scale(.6); opacity: 0; } }
.stat.locked { opacity: .55; pointer-events: none; }

/* «Дом»: цифры и заметки вместо полосок */
.nums { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 6px; font-size: 13px; color: var(--muted); }
.nums b { font-family: 'Press Start 2P', monospace; font-size: 14px; color: var(--ink); margin-right: 2px; }
.stat .quote { -webkit-user-select: text; user-select: text; }
.stat .quote small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.stat .quote.dream { border-left-color: #a99cff; background: #f0edff; }
.meal .lock { flex: none; font-size: 13px; opacity: .7; }

/* 100% в спальне */
.climax { text-align: center; padding: 12px; }
.climax-note { font-weight: 800; font-size: 17px; margin: 2px 0 10px; }
.climax-stage { position: relative; border: 3px solid var(--ink); border-radius: 4px; overflow: hidden; }
.climax-stage canvas { width: 100%; aspect-ratio: 4 / 3; }
#climax-say { top: 6px; bottom: auto; left: 50%; max-width: 86%; font-size: 14px; }
#climax-say::after { display: none; }
#climax .btn { margin-top: 12px; }

/* облачко «какой пуш ушёл партнёру» над тем, кто дотапал */
.say.push { background: #e6f3ff; border-color: #2b5ea8; color: #1d3f73; font-size: 11px; }
.say.push::after { background: #e6f3ff; border-color: #2b5ea8; }

/* в спальне облачка прижаты к своим краям, чтобы не налезали друг на друга */
#bsay-sasha, #bsay-zhabka { max-width: 47%; transform: none; animation: popin3 .15s ease-out; }
#bsay-sasha { left: 2% !important; }
#bsay-zhabka { left: auto !important; right: 2%; }
#bsay-sasha::after { left: 55%; }
#bsay-zhabka::after { left: 45%; }
@keyframes popin3 { from { transform: scale(.6); opacity: 0; } }
