/* Happy Path — every color/font comes from the user's theme (see js/themes.js) */
:root {
  --bg: #ffe4ec; --text: #5a2a3a; --accent: #ff6f91; --accent-text: #fff; --link: #d6336c;
  --panel: rgba(255, 247, 250, .92); --panel-solid: #fff7fa; --muted: rgba(0, 0, 0, .55); --line: rgba(0, 0, 0, .1);
  --radius: 18px; --font: 'Itim', system-ui, sans-serif; --heading-font: 'Pacifico', cursive; --bg-layers: none;
  --tabbar-h: 64px;
  color-scheme: light;
}
:root[data-dark="1"] { color-scheme: dark; }
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--font); font-size: 17px; line-height: 1.45; color: var(--text);
  background: var(--bg-layers), var(--bg); background-color: var(--bg); background-attachment: fixed;
  -webkit-tap-highlight-color: transparent; overflow-x: hidden;
}
a { color: var(--link); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h2.page-title, .brand, .ms-name, .ms-head, .modal-card h2 { font-family: var(--heading-font); font-weight: 400; }
h3 { font-size: 1.05rem; }
img { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.page { max-width: 760px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom)); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.row > input, .row > textarea { flex: 1; min-width: 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.boot { display: grid; place-items: center; height: 100vh; font-size: 64px; animation: pulse 1.2s ease-in-out infinite; }

/* cards & forms */
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; box-shadow: 0 6px 24px rgba(0, 0, 0, .07); border: 1px solid var(--line); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-weight: 700; font-size: .9rem; }
.help { color: var(--muted); font-size: .8rem; }
input:not([type=checkbox]):not([type=color]):not([type=range]):not([type=file]), select, textarea {
  width: 100%; padding: 11px 12px; border-radius: calc(var(--radius) * .6); border: 1.5px solid var(--line);
  background: var(--panel-solid); color: var(--text); outline: none; font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
textarea { resize: vertical; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 999px;
  border: 1.5px solid var(--line); background: var(--panel-solid); color: var(--text); text-decoration: none; cursor: pointer;
  font-weight: 700; transition: transform .1s ease, opacity .2s; white-space: nowrap;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: #c92a2a; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn:disabled, .btn.busy { opacity: .55; pointer-events: none; }
.link-btn { background: none; border: 0; color: var(--link); text-decoration: underline; cursor: pointer; padding: 4px 0; }
.error { color: #e03131; margin: 0; font-size: .9rem; }
.note { background: color-mix(in srgb, var(--accent) 14%, transparent); padding: 10px 12px; border-radius: calc(var(--radius) * .6); margin: 0; }
.section-title { margin-top: 8px; opacity: .85; }

/* toasts & fx */
#toasts { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; padding: 0 16px; }
.toast { background: var(--panel-solid); color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; box-shadow: 0 8px 28px rgba(0, 0, 0, .18); animation: toastIn .3s ease; max-width: 100%; transition: opacity .4s, transform .4s; }
.toast.love { background: var(--accent); color: var(--accent-text); }
.toast.error { border-color: #ff8787; }
.toast.out { opacity: 0; transform: translateY(-10px); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-14px) scale(.96); } }
.burst { position: fixed; z-index: 60; pointer-events: none; font-size: 22px; transform: translate(-50%, -50%); animation: burst 1.1s cubic-bezier(.2, .8, .3, 1) forwards; }
@keyframes burst { to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(.6); opacity: 0; } }
.float-heart { position: fixed; bottom: -40px; z-index: 55; pointer-events: none; font-size: 30px; animation: floatUp 3s ease-in forwards; }
@keyframes floatUp { to { transform: translateY(-110vh) rotate(25deg); opacity: .2; } }
.spark { position: fixed; z-index: 70; pointer-events: none; font-size: 14px; transform: translate(-50%, -50%); animation: spark .8s ease-out forwards; }
@keyframes spark { to { transform: translate(-50%, 20px) scale(.3); opacity: 0; } }
@keyframes pulse { 50% { transform: scale(1.15); } }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* tab bar */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 40;
  display: flex; gap: 2px; padding: 6px; width: min(560px, calc(100% - 20px));
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 999px; box-shadow: 0 10px 30px rgba(0, 0, 0, .15);
}
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 2px; border-radius: 999px; text-decoration: none; color: var(--text); font-size: .7rem; }
.tabbar .ico { font-size: 1.35rem; line-height: 1.1; }
.tabbar a.active { background: var(--accent); color: var(--accent-text); }

/* auth */
.auth { max-width: 420px; margin: 0 auto; padding-top: 6vh; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.auth .card { text-align: left; }
.auth-heart { font-size: 64px; animation: pulse 1.6s ease-in-out infinite; }
.brand { font-size: 2.2rem; color: var(--accent); }
.tagline { margin: 0; color: var(--muted); }
.top { text-align: center; padding-top: 4px; }
.lang-toggle { display: inline-flex; align-self: center; background: var(--panel); border-radius: 999px; padding: 4px; border: 1px solid var(--line); }
.lang-toggle button { border: 0; background: none; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.lang-toggle .active { background: var(--accent); color: var(--accent-text); }

/* home: clocks */
.clocks { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.clock { position: relative; overflow: hidden; border-radius: var(--radius); padding: 14px; color: #fff; text-decoration: none; min-height: 168px; display: flex; flex-direction: column; gap: 2px; box-shadow: 0 8px 26px rgba(0, 0, 0, .14); text-shadow: 0 1px 6px rgba(0, 0, 0, .25); }
.sky-night { background: linear-gradient(160deg, #0f1638, #2b2b6b 70%, #4a3a7a); }
.sky-evening { background: linear-gradient(160deg, #2c2a6b, #6b4a9a 70%, #c06c9a); }
.sky-dawn { background: linear-gradient(160deg, #ffb07c, #ff8fa3 55%, #a38cff); }
.sky-day { background: linear-gradient(160deg, #4fc3f7, #81d4fa 60%, #b3e5fc); color: #0b3954; text-shadow: none; }
.sky-dusk { background: linear-gradient(160deg, #ff9a5a, #ff6f91 55%, #7b4fa0); }
.sky-deco { position: absolute; right: 10px; top: 8px; font-size: 1.3rem; opacity: .9; }
.clock-who { display: flex; align-items: center; gap: 6px; font-weight: 700; }
.clock-time { font-size: 2.2rem; font-weight: 800; letter-spacing: -.02em; margin-top: 6px; font-family: 'Nunito', system-ui, sans-serif; }
.clock-date, .clock-city { font-size: .85rem; opacity: .9; }
.clock-status { margin-top: auto; font-size: .9rem; }
.clock-mood { position: absolute; right: 10px; bottom: 8px; font-size: 1.8rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #adb5bd; display: inline-block; box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
.dot.on { background: #40c057; }
.overlap { text-align: center; display: flex; flex-direction: column; gap: 2px; }
.together { text-align: center; font-weight: 700; color: var(--accent); }
.together:empty, .overlap:empty { display: none; }

.heart-card { align-items: center; }
.heart-btn { display: flex; align-items: center; gap: 10px; border: 0; cursor: pointer; padding: 14px 26px; border-radius: 999px; font-size: 1.15rem; font-weight: 800; background: var(--accent); color: var(--accent-text); box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 45%, transparent); }
.heart-ico { font-size: 1.6rem; }
.heart-btn.pop { animation: pop .35s ease; }
@keyframes pop { 40% { transform: scale(1.12); } }

.teaser { display: flex; gap: 12px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; color: var(--text); text-decoration: none; }
.teaser.hot { border: 2px solid var(--accent); }
.teaser-ico { font-size: 1.6rem; }
.teaser-title { font-weight: 700; }

.moods { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
.mood-picks { display: flex; flex-wrap: wrap; gap: 4px; }
.mood-picks button { font-size: 1.4rem; border: 2px solid transparent; background: none; border-radius: 12px; padding: 2px 5px; cursor: pointer; }
.mood-picks button.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.their-mood { display: flex; gap: 12px; align-items: center; }
.mood-emoji { font-size: 2.6rem; }

.countdown { text-align: center; }
.count-boxes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.count-box { background: color-mix(in srgb, var(--accent) 14%, transparent); border-radius: calc(var(--radius) * .7); padding: 8px 4px; display: flex; flex-direction: column; }
.count-box b { font-size: 1.6rem; font-family: 'Nunito', system-ui, sans-serif; }
.count-box span { font-size: .75rem; color: var(--muted); }
.flight { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.flight-line { flex: 1; position: relative; height: 2px; border-top: 2px dashed var(--accent); }
.plane { position: absolute; top: -15px; transform: translateX(-50%); font-size: 1.3rem; }
.big-celebrate { font-size: 1.8rem; animation: pulse 1s infinite; }
.invite-card { border: 2px dashed var(--accent); }

/* avatars */
.avatar { border-radius: 50%; object-fit: cover; flex-shrink: 0; display: inline-grid; place-items: center; background: color-mix(in srgb, var(--accent) 30%, var(--panel-solid)); color: var(--text); font-weight: 800; }
.avatar.sm { width: 28px; height: 28px; font-size: .8rem; }
.avatar.md { width: 44px; height: 44px; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.4rem; }
.avatar.xl { width: 150px; height: 150px; border-radius: calc(var(--radius) * .6); font-size: 3rem; }

/* daily question */
.q-card { gap: 14px; }
.q-text { font-size: 1.35rem; font-weight: 700; text-align: center; }
.q-text-alt { text-align: center; color: var(--muted); font-style: italic; margin-top: -8px; }
.answer { display: flex; gap: 10px; align-items: flex-start; }
.answer-body { background: var(--panel-solid); border: 1px solid var(--line); border-radius: calc(var(--radius) * .8); padding: 8px 12px; flex: 1; }
.answer.theirs .answer-body { background: color-mix(in srgb, var(--accent) 14%, var(--panel-solid)); }
.answer-who { font-weight: 700; font-size: .8rem; color: var(--muted); }
.answer-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.waiting { text-align: center; }
.q-hist { gap: 8px; }
.q-hist-text { font-weight: 700; }

/* draw */
.word-picks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.word-pick { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 16px 6px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 700; }
.word-pick:hover, .word-pick:focus { border-color: var(--accent); }
.word-emoji { font-size: 2.2rem; }
.draw-word { font-size: 1.2rem; font-weight: 700; text-align: center; }
.canvas-wrap { border-radius: var(--radius); overflow: hidden; border: 2px solid var(--line); background: #fff; touch-action: none; }
.draw-canvas { width: 100%; aspect-ratio: 1; display: block; touch-action: none; cursor: crosshair; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--panel-solid); box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.active { box-shadow: 0 0 0 3px var(--accent); transform: scale(1.1); }
.sizes { display: flex; gap: 6px; }
.size { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); background: var(--panel-solid); display: grid; place-items: center; cursor: pointer; }
.size span { background: var(--text); border-radius: 50%; display: block; }
.size.active, .eraser.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--panel-solid)); }
.drawing { width: 100%; border-radius: calc(var(--radius) * .7); background: #fff; border: 1px solid var(--line); }
.waiting-card { flex-direction: row; align-items: center; }
.waiting-card .drawing { width: 96px; }
.feedback { margin: 0; font-weight: 700; min-height: 1.2em; }
.feedback.good { color: #2b8a3e; }
.feedback.bad { color: #e03131; }
.hint { margin: 0; color: var(--muted); font-size: .9rem; }
.hint:empty, .feedback:empty { display: none; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.gallery-item { margin: 0; background: var(--panel); border-radius: var(--radius); padding: 8px; border: 1px solid var(--line); }
.gallery-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: calc(var(--radius) * .6); background: #fff; }
.gallery-item figcaption { font-size: .9rem; padding: 4px 2px 0; }

/* MySpace profile */
.marquee { overflow: hidden; white-space: nowrap; background: var(--accent); color: var(--accent-text); border-radius: calc(var(--radius) * .6); padding: 6px 0; margin-bottom: 12px; font-weight: 700; }
.marquee span { display: inline-block; padding-left: 100%; animation: marquee 14s linear infinite; }
@keyframes marquee { to { transform: translateX(-100%); } }
.ms-cols { display: grid; grid-template-columns: 1fr; gap: 14px; }
.ms-left, .ms-right { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
@media (min-width: 720px) { .ms-cols { grid-template-columns: 5fr 7fr; } }
.ms-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.ms-head { background: var(--accent); color: var(--accent-text); padding: 6px 12px; font-size: 1rem; }
.ms-body { padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.ms-body h4 { color: var(--accent); margin-top: 6px; }
.ms-body p { margin: 0; }
.ms-id { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.ms-name { font-size: 1.8rem; color: var(--accent); overflow-wrap: anywhere; }
.ms-name small { font-size: .9rem; color: var(--muted); font-family: var(--font); }
.ms-id-row { display: flex; gap: 12px; align-items: flex-start; }
.ms-photo { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ms-details { display: flex; flex-direction: column; gap: 4px; font-size: .92rem; min-width: 0; overflow-wrap: anywhere; }
.ms-details p { margin: 0; }
.ms-headline { font-style: italic; }
.online-badge { color: #2b8a3e; font-weight: 800; animation: pulse 2s infinite; transform-origin: left; }
.counter { font-family: 'VT323', monospace; background: #000; color: #39ff14; padding: 0 6px; border-radius: 4px; letter-spacing: 2px; font-size: 1.1rem; }
.ms-network { text-align: center; border: 2px solid var(--accent); }
.ms-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.ms-table { width: 100%; border-collapse: collapse; }
.ms-table th { text-align: left; vertical-align: top; width: 36%; padding: 6px; background: color-mix(in srgb, var(--accent) 16%, transparent); font-size: .85rem; }
.ms-table td { padding: 6px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.contact-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.contact-btn { display: flex; align-items: center; justify-content: center; text-align: center; padding: 10px 4px; border-radius: calc(var(--radius) * .5); border: 1px solid var(--line); background: var(--panel-solid); color: var(--link); text-decoration: none; font-size: .85rem; font-weight: 700; cursor: pointer; }
.top-friends { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.top-friend { display: flex; flex-direction: column; align-items: center; gap: 4px; text-decoration: none; color: var(--link); font-size: .8rem; font-weight: 700; position: relative; text-align: center; }
.top-friend.empty { aspect-ratio: 1; justify-content: center; border: 1px dashed var(--line); border-radius: calc(var(--radius) * .5); color: var(--muted); }
.rank { position: absolute; top: -6px; left: -2px; background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: 0 6px; font-size: .7rem; }
.ms-comment { display: grid; grid-template-columns: 76px 1fr; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.ms-comment-who { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .8rem; text-decoration: none; color: var(--link); font-weight: 700; text-align: center; }
.song { width: 100%; border: 0; border-radius: calc(var(--radius) * .5); }
.song.yt { aspect-ratio: 16 / 9; }
.song.sp { height: 152px; }
.myspace.preview .ms-body { flex-direction: row; align-items: center; }

/* theme editor */
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.preset { padding: 12px 8px; border-radius: 12px; border: 3px solid; cursor: pointer; font-weight: 700; }
.preset.active { outline: 3px solid var(--text); outline-offset: 2px; }
.color-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.color-field { display: flex; align-items: center; gap: 8px; }
.color-field input { width: 44px; height: 44px; border: 0; padding: 0; background: none; cursor: pointer; }
.sticky-save { position: sticky; bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); display: flex; justify-content: center; }
.sticky-save .btn { box-shadow: 0 8px 24px rgba(0, 0, 0, .2); padding: 12px 40px; }

/* welcome letter */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; animation: toastIn .3s; }
.modal-card { background: var(--panel-solid); border-radius: var(--radius); padding: 22px; max-width: 460px; width: 100%; display: flex; flex-direction: column; gap: 14px; align-items: center; text-align: center; max-height: 90vh; overflow: auto; }
.envelope { font-size: 96px; background: none; border: 0; cursor: pointer; animation: pulse 1.4s infinite; }
.letter-paper { background: #fffdf7; color: #4a3b3b; border-radius: 10px; padding: 18px; text-align: left; width: 100%; box-shadow: inset 0 0 0 1px #f0e3d0; background-image: repeating-linear-gradient(transparent 0 27px, #f3e6d6 27px 28px); }
.letter-text { white-space: pre-wrap; margin: 0; font-family: 'Patrick Hand', 'Itim', cursive; font-size: 1.15rem; line-height: 28px; }
.letter-sign { text-align: right; margin: 10px 0 0; font-family: 'Pacifico', cursive; }

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