:root {
  --bg: #fff4ec;
  --bg2: #ffe7d9;
  --card: #ffffff;
  --ink: #3b2a22;
  --muted: #8d776b;
  --line: #f1dccf;
  --accent: #ff7aa2;
  --accent-ink: #fff;
  --radius: 22px;
  --shadow: 0 6px 20px rgba(120, 70, 40, .10);
  --font: "Fredoka", system-ui, -apple-system, sans-serif;
  --hand: "Caveat", "Fredoka", cursive;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
html { background: var(--bg); }
body {
  background: radial-gradient(circle at 20% 0%, var(--bg2), var(--bg) 55%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  transition: background .6s, color .6s;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; }
code { font-family: ui-monospace, monospace; }

.boot { display: grid; place-items: center; min-height: 80vh; font-size: 64px; animation: bob 1.2s ease-in-out infinite; }
.page { max-width: 860px; margin: 0 auto; padding: 16px 16px 60px; display: flex; flex-direction: column; gap: 16px; }
.center-screen { min-height: 92vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 16px; text-align: center; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.pad { padding: 18px; }
.stack { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center { text-align: center; }
.err { color: #d8434b; min-height: 1.2em; font-size: 15px; }
.brand { font-family: var(--hand); font-size: 46px; line-height: 1; font-weight: 700; }

.btn {
  appearance: none; border: 0; border-radius: 999px; padding: 12px 20px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 0 rgba(0,0,0,.12); transition: transform .08s;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.btn.big { padding: 16px 26px; font-size: 20px; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid var(--line); box-shadow: none; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); text-decoration: none; font-size: 20px; border: 0; cursor: pointer; }

input, textarea, select {
  width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; background: #fffaf6; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
label { font-weight: 600; font-size: 15px; }

.topbar { display: flex; align-items: center; gap: 12px; }
.topbar h1 { font-size: 26px; }
.topbar .sub { color: var(--muted); font-size: 14px; }
.back { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); text-decoration: none; font-size: 30px; line-height: 1; padding-bottom: 4px; }

/* lock / who */
.duo { display: flex; align-items: end; gap: 0; }
.duo svg { width: 110px; height: auto; }
.lock form { width: min(360px, 100%); }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; width: min(460px, 100%); }
.who-btn { padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.who-btn svg { width: 90px; height: auto; }

/* home */
.home-head { display: flex; justify-content: space-between; align-items: center; }
.clocks { display: flex; align-items: center; justify-content: space-around; padding: 14px; text-align: center; }
.clocks div { display: flex; flex-direction: column; }
.clocks b { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.clocks .heart { font-size: 26px; animation: bob 2s ease-in-out infinite; }
.nudge { display: block; padding: 14px 18px; text-decoration: none; background: #2f3a6b; color: #fff; border: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.mode {
  --c: #ff7aa2;
  text-decoration: none; padding: 18px; border-radius: var(--radius); min-height: 150px;
  background: var(--c); color: #fff; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--c) 70%, #000), var(--shadow);
  position: relative; overflow: hidden; transition: transform .1s;
}
.mode:active { transform: translateY(3px); }
.mode b { font-size: 20px; }
.mode .small { opacity: .9; }
.mode-emoji { position: absolute; top: 10px; right: 12px; font-size: 44px; filter: drop-shadow(0 3px 0 rgba(0,0,0,.12)); }
.codebox { display: block; padding: 10px 12px; background: #fff3ea; border-radius: 10px; user-select: all; word-break: break-all; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 30px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px; opacity: 0; pointer-events: none;
  transition: .25s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 40; overflow: hidden; }
.confetti span { position: absolute; top: -40px; animation: fall 2.8s ease-in forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(360deg); } }
@keyframes bob { 50% { transform: translateY(-6px); } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid var(--line); background: #fffaf6; border-radius: 999px; padding: 8px 14px; cursor: pointer; font-size: 15px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ============ Same Time (night) ============ */
html[data-mode="sametime"] {
  --bg: #151a36; --bg2: #2a2f63; --card: rgba(255,255,255,.07); --ink: #f5f0ff; --muted: #b3acd6; --line: rgba(255,255,255,.12);
  --accent: #ffd66b; --accent-ink: #2a2350;
}
html[data-mode="sametime"] input, html[data-mode="sametime"] textarea { background: rgba(255,255,255,.06); }
.sky { position: relative; height: 330px; border-radius: var(--radius); overflow: hidden; background: linear-gradient(#1c2250, #3a3f7a 70%, #4d5aa0); }
.sky .stars span { position: absolute; width: 3px; height: 3px; background: #fff; border-radius: 50%; animation: twinkle 3s infinite; }
@keyframes twinkle { 50% { opacity: .2; } }
.sky .moon { position: absolute; top: 24px; right: 34px; width: 60px; height: 60px; border-radius: 50%; background: #fff3c4; box-shadow: 0 0 40px #fff3c480; }
.sky .water { position: absolute; left: 0; right: 0; bottom: 0; height: 70px; background: linear-gradient(#5d79c9aa, #2f3f86); }
.sky .water::before { content: ""; position: absolute; top: -8px; left: -10%; width: 120%; height: 16px; background: radial-gradient(circle at 10px -2px, transparent 12px, #5d79c9aa 13px) repeat-x; background-size: 24px 16px; animation: wave 4s linear infinite; }
@keyframes wave { to { transform: translateX(24px); } }
.sky .o { position: absolute; bottom: 26px; transition: left 1.6s cubic-bezier(.5,0,.3,1), opacity .6s; }
.sky .o svg { width: 108px; height: auto; display: block; }
.sky .o.float { animation: floaty 3.5s ease-in-out infinite; }
.sky .o.r.float { animation-delay: .4s; }
@keyframes floaty { 50% { transform: translateY(-8px) rotate(-2deg); } }
.sky .o.away { opacity: .35; filter: grayscale(.4); }
.sky .hearts { position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); font-size: 26px; opacity: 0; transition: opacity .8s; }
.sky.together .hearts { opacity: 1; animation: bob 2s ease-in-out infinite; }
.sky .zz { position: absolute; font-size: 20px; color: #fff; opacity: .8; animation: zz 2.4s ease-in infinite; }
@keyframes zz { from { transform: translateY(0); opacity: .9; } to { transform: translateY(-40px); opacity: 0; } }
.status-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.status-row .card { padding: 14px; text-align: center; }
.status-row b.t { font-size: 32px; display: block; font-variant-numeric: tabular-nums; }
.status-pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.1); font-size: 13px; margin-top: 6px; }
.status-pill.on { background: #ffd66b; color: #2a2350; }
.gn-note { font-family: var(--hand); font-size: 26px; line-height: 1.1; }

/* ============ Seen Police ============ */
html[data-mode="seen"] { --accent: #e2574c; --bg: #f3f5fa; --bg2: #e3e8f4; --line: #dde3ef; --ink: #1f2a44; --muted: #6b7690; }
.agency { display: flex; gap: 12px; align-items: center; padding: 14px 18px; background: #1f2a44; color: #fff; border: 0; }
.agency .badge { font-size: 34px; }
.agency b { letter-spacing: .08em; text-transform: uppercase; font-size: 15px; }
.cases { display: flex; flex-direction: column; gap: 10px; }
.case { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 12px 16px; cursor: pointer; }
.case .num { font-family: ui-monospace, monospace; font-size: 13px; color: var(--muted); }
.stamp-mini { font-weight: 700; color: #e2574c; border: 2px solid #e2574c; border-radius: 6px; padding: 2px 6px; transform: rotate(-6deg); font-size: 12px; white-space: nowrap; }
.stamp-mini.served { color: #2f9e6a; border-color: #2f9e6a; }
.verdict-wrap canvas { width: 100%; height: auto; border-radius: 12px; box-shadow: var(--shadow); display: block; }

/* ============ Small Details ============ */
html[data-mode="details"] { --accent: #e77fa8; }
.qa { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.qa .q { font-weight: 600; }
.qa .ans { font-family: var(--hand); font-size: 28px; line-height: 1.1; color: #b44f7a; }
.grade { display: flex; gap: 8px; }
.grade button { flex: 1; border: 2px solid var(--line); background: #fffaf6; border-radius: 14px; padding: 10px 4px; cursor: pointer; font-size: 15px; }
.grade button.on[data-g="yes"] { background: #7fd1a8; border-color: #7fd1a8; color: #fff; }
.grade button.on[data-g="close"] { background: #ffc864; border-color: #ffc864; }
.grade button.on[data-g="no"] { background: #ff8e8e; border-color: #ff8e8e; color: #fff; }
.result-card { text-align: center; padding: 26px 18px; background: linear-gradient(135deg, #ffd1e2, #ffe9c9); border: 0; }
.result-card .score { font-size: 72px; font-weight: 700; line-height: 1; }
.result-card .title { font-family: var(--hand); font-size: 36px; }
.progress { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .3s; }

/* ============ Cat lab ============ */
html[data-mode="catlab"] { --accent: #e79a3f; --bg: #fff8e6; --bg2: #ffeec2; }
.lab-q { font-size: 24px; font-weight: 600; text-align: center; }
.answers { display: flex; flex-direction: column; gap: 10px; }
.answers button { text-align: left; padding: 16px 18px; border-radius: 16px; border: 2px solid var(--line); background: #fff; cursor: pointer; font-size: 18px; }
.answers button:active { background: #fff1d6; }
.scan { font-family: ui-monospace, monospace; font-size: 15px; line-height: 1.7; min-height: 190px; }
.certificate { text-align: center; padding: 22px; border: 4px double #e79a3f; background: #fffdf6; }
.certificate .big { font-size: 34px; font-weight: 700; color: #c26d12; }
.meter { height: 22px; border-radius: 99px; background: #f4e3c2; overflow: hidden; margin: 8px 0; }
.meter i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffc864, #e77f3f); transition: width 1.8s cubic-bezier(.2,.8,.2,1); }

/* ============ Passport ============ */
html[data-mode="passport"] { --accent: #3e8f7d; --bg: #eef6f1; --bg2: #d9ece2; --line: #d3e6dc; }
.passport-cover { background: #1e4f45; color: #f3e3b3; text-align: center; padding: 22px; border: 0; }
.passport-cover .brand { color: #f3e3b3; font-size: 40px; }
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.pp { position: relative; padding: 16px; min-height: 150px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 4px; background: #fffdf7; }
.pp .em { font-size: 38px; }
.pp b { font-size: 19px; }
.stamp {
  position: absolute; top: 12px; right: 10px; width: 74px; height: 74px; border-radius: 50%;
  border: 3px solid var(--c); color: var(--c); display: grid; place-items: center; text-align: center;
  font-size: 11px; font-weight: 700; line-height: 1.05; transform: rotate(-14deg); opacity: .85; text-transform: uppercase;
  outline: 2px dashed var(--c); outline-offset: -8px; background: #fffdf7cc;
}
.stamp.pop { animation: stampIn .45s cubic-bezier(.3,1.6,.5,1); }
@keyframes stampIn { from { transform: scale(2.2) rotate(-30deg); opacity: 0; } }
.note { padding: 12px 14px; border-radius: 14px; background: #f6faf8; border: 1px solid var(--line); }
.note .who-tag { font-size: 13px; color: var(--muted); }
.note p { font-family: var(--hand); font-size: 25px; line-height: 1.1; white-space: pre-wrap; }

/* ============ Doodle ============ */
html[data-mode="doodle"] { --accent: #7a63d6; --bg: #f4f1ff; --bg2: #e6e0ff; --line: #e2dcf7; }
.wall { position: relative; background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; aspect-ratio: 4 / 3; touch-action: none; }
.wall canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 3px var(--ink); }
.sizes button { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: #fff; display: grid; place-items: center; cursor: pointer; }
.sizes button.on { border-color: var(--ink); }
.sizes i { display: block; background: var(--ink); border-radius: 50%; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; background: #fff; padding: 8px 8px 4px; border-radius: 12px; box-shadow: var(--shadow); transform: rotate(var(--r, 0deg)); }
.gallery img { width: 100%; display: block; border-radius: 6px; aspect-ratio: 4/3; object-fit: cover; background: #fafafa; }
.gallery figcaption { font-family: var(--hand); font-size: 20px; text-align: center; }

/* ============ Mot ============ */
html[data-mode="mot"] { --accent: #3f73d9; --bg: #f1f5ff; --bg2: #ffe3e3; --line: #dfe6f7; }
.word-card { text-align: center; padding: 30px 20px; position: relative; overflow: hidden; }
.word-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 8px; background: linear-gradient(#3f73d9 33%, #fff 33% 66%, #e2574c 66%); }
.word-card .date { color: var(--muted); font-size: 14px; }
.word-card .w { font-family: var(--hand); font-size: 64px; line-height: 1; margin: 10px 0 4px; color: #2c4fa0; }
.word-card .t { color: var(--muted); font-size: 18px; }
.word-card .ex { font-size: 22px; margin-top: 18px; font-weight: 500; }
.word-card .exT { color: var(--muted); margin-top: 4px; }
.archive { display: flex; flex-direction: column; gap: 8px; }
.archive button { display: flex; justify-content: space-between; gap: 10px; padding: 12px 16px; text-align: left; cursor: pointer; width: 100%; }
.rec { background: #e2574c; }
.rec.live { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(560px, calc(100% - 32px)); max-height: calc(100% - 40px); background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
html[data-mode="sametime"] dialog { background: #262c5c; }
dialog::backdrop { background: rgba(30, 20, 15, .45); }
dialog .pad { max-height: calc(100vh - 60px); overflow: auto; }

@media (max-width: 480px) {
  .brand { font-size: 40px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .mode { min-height: 130px; padding: 14px; }
  .mode b { font-size: 17px; }
  .mode-emoji { font-size: 34px; }
  .sky { height: 280px; }
  .sky .o svg { width: 84px; }
  .word-card .w { font-size: 50px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
