:root {
    --primary: #FF6B9D;
    --primary-dark: #E91E63;
    --primary-light: #FFC1D9;
    --primary-soft: #FFE0EC;
    --bg-gradient-start: #FFF5F8;
    --bg-gradient-end: #FFE5EE;
    --surface: #FFFFFF;
    --surface-alt: #FFF9FB;
    --text: #3D3D3D;
    --text-muted: #8A8A8A;
    --text-on-primary: #FFFFFF;
    --border: #FFE0EC;
    --shadow-sm: 0 2px 8px rgba(255, 107, 157, 0.08);
    --shadow-md: 0 8px 24px rgba(255, 107, 157, 0.15);
    --shadow-lg: 0 16px 48px rgba(255, 107, 157, 0.18);
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 22px;
    --radius-xl: 28px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
        "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
    color: var(--text);
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--primary-dark);
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

/* ===== Smartphone frame ===== */
.app-shell {
    display: flex;
    justify-content: center;
    align-items: stretch;
    min-height: 100vh;
    padding: 0;
}

.phone {
    position: relative;
    width: 100%;
    max-width: 420px;
    min-height: 100vh;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

@media (min-width: 480px) {
    .app-shell {
        padding: 32px 16px;
    }
    .phone {
        min-height: 760px;
        max-height: 880px;
        border-radius: 36px;
        box-shadow: var(--shadow-lg);
        border: 8px solid #fff;
    }
}

/* ===== Header ===== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 18px 14px;
    background: linear-gradient(135deg, var(--primary) 0%, #FF93BA 100%);
    color: var(--text-on-primary);
    box-shadow: var(--shadow-sm);
}

.app-header .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.02em;
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    overflow: hidden;
    display: inline-block;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
    background: rgba(255, 255, 255, 0.2);
}

.brand-mark img {
    width: 100%;
    height: 100%;
    display: block;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    position: relative;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--text-on-primary);
    transition: background 120ms ease, transform 120ms ease;
    position: relative;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.icon-btn:active {
    transform: scale(0.94);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon-btn .badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #fff;
    color: var(--primary-dark);
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    display: grid;
    place-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
    border: 1.5px solid var(--primary);
}

.icon-btn .badge[hidden] { display: none; }

.ico-chat {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
}

.icon-btn.chat-btn { padding: 0; position: relative; }

/* Default (no unread): show sleep, hide awake */
.chat-btn .ico-chat-awake { display: none; }

/* Has unread: hide sleep, show awake (with glow pulse) */
.chat-btn.has-unread .ico-chat-sleep { display: none; }
.chat-btn.has-unread .ico-chat-awake {
    display: block;
    transform-origin: center;
    animation: chat-glow 1.8s ease-in-out infinite;
}

@keyframes chat-glow {
    0%, 100% {
        filter: drop-shadow(0 0 0 rgba(255, 235, 130, 0));
        transform: scale(1);
    }
    50% {
        filter: drop-shadow(0 0 8px rgba(255, 235, 130, 0.95));
        transform: scale(1.1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-btn.has-unread .ico-chat-awake {
        animation: none;
        filter: drop-shadow(0 0 4px rgba(255, 235, 130, 0.6));
    }
}

.user-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary-dark);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 0.95rem;
    border: 2px solid rgba(255,255,255,0.6);
    cursor: pointer;
    transition: transform 120ms ease;
}

.user-avatar:hover {
    transform: scale(1.05);
}

.user-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 200px;
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 8px;
    display: none;
    z-index: 50;
    border: 1px solid var(--border);
}

.user-menu.open {
    display: block;
    animation: menu-pop 140ms ease-out;
}

@keyframes menu-pop {
    from { opacity: 0; transform: translateY(-4px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.user-menu .menu-header {
    padding: 10px 12px 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}

.user-menu .menu-header .name {
    font-weight: 700;
    font-size: 0.95rem;
}

.user-menu .menu-header .sub {
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 2px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 0.92rem;
    transition: background 120ms ease;
}

.menu-item:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.menu-item svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.menu-item.danger {
    color: #c62828;
}

.menu-item.danger:hover {
    background: #ffe9ec;
    color: #b71c1c;
}

/* ===== Main content ===== */
.app-main {
    flex: 1;
    overflow-y: auto;
    padding: 20px 18px 24px;
}

.greet {
    margin: 4px 0 18px;
}

.greet h1 {
    margin: 0;
    font-size: 1.5rem;
    line-height: 1.3;
    color: var(--text);
}

.greet p {
    margin: 4px 0 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

/* Stat row */
.stat-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}

.stat-card {
    background: linear-gradient(135deg, #FFF0F6 0%, #FFE0EC 100%);
    border-radius: var(--radius-md);
    padding: 14px;
    border: 1px solid var(--border);
}

.stat-card .label {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-card .value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary-dark);
}

.stat-card .delta {
    font-size: 0.75rem;
    color: #2e7d32;
    margin-top: 4px;
}

/* Today's mood card (button variant of stat-card) */
.mood-card {
    cursor: pointer;
    text-align: left;
    width: 100%;
    font-family: inherit;
    transition: transform 120ms ease, box-shadow 120ms ease;
    color: var(--text);
}

.mood-card:hover { box-shadow: var(--shadow-sm); }
.mood-card:active { transform: scale(0.98); }

.mood-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
}

.mood-emoji {
    font-size: 1.9rem;
    line-height: 1;
    flex-shrink: 0;
}

.mood-info { min-width: 0; }

.mood-name {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mood-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Mood picker modal */
.mood-modal-card {
    max-width: 340px;
}

.mood-options {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.mood-option {
    aspect-ratio: 1;
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    border: 1.5px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px;
    cursor: pointer;
    transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
    font-family: inherit;
}

.mood-option:hover {
    background: color-mix(in srgb, var(--mood-color) 18%, white);
    border-color: var(--mood-color);
    transform: translateY(-2px);
}

.mood-option:active { transform: translateY(0) scale(0.96); }

.mood-em {
    font-size: 1.6rem;
    line-height: 1;
}

.mood-label-text {
    font-size: 0.66rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: 0.02em;
}

/* Year calendar */
.year-cal {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 4px 12px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
}

.year-cal::-webkit-scrollbar { height: 6px; }
.year-cal::-webkit-scrollbar-thumb { background: var(--primary-soft); border-radius: 999px; }

.month {
    flex: 0 0 196px;
    scroll-snap-align: start;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 8px;
}

.month-name {
    font-weight: 700;
    font-size: 0.78rem;
    color: var(--primary-dark);
    margin-bottom: 6px;
    text-align: center;
    letter-spacing: 0.04em;
}

.dow-row {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    text-align: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
}

.days-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}

.day-cell {
    aspect-ratio: 1;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.6);
    display: grid;
    place-items: center;
    font-size: 0.95rem;
    line-height: 1;
    transition: transform 140ms ease, box-shadow 140ms ease;
    cursor: pointer;
    border: 1px solid transparent;
    user-select: none;
}

.day-cell.pad {
    background: transparent;
    cursor: default;
    pointer-events: none;
}

.day-cell .day-num {
    font-size: 0.62rem;
    color: var(--text-muted);
    font-weight: 500;
}

.day-cell.has-mood {
    color: #fff;
}

.day-cell.has-mood:hover {
    transform: scale(1.18);
    box-shadow: 0 4px 10px rgba(255, 107, 157, 0.25);
    z-index: 2;
}

.day-cell.today {
    border-color: var(--primary);
    box-shadow: 0 0 0 1.5px var(--primary);
    font-weight: 700;
}

.day-cell.today .day-num { color: var(--primary-dark); font-weight: 700; }

.day-cell.future {
    opacity: 0.35;
    cursor: not-allowed;
}

.day-cell.mood-great    { background: #FFB347; }
.day-cell.mood-loved    { background: #FF6B9D; }
.day-cell.mood-calm     { background: #86EFAC; }
.day-cell.mood-okay     { background: #D1D5DB; }
.day-cell.mood-tired    { background: #C4B5FD; }
.day-cell.mood-down     { background: #93C5FD; }
.day-cell.mood-stressed { background: #FCA5A5; }

/* Section card */
.section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.section-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-title h2 {
    font-size: 1rem;
    margin: 0;
    color: var(--text);
}

.section-title .link {
    font-size: 0.82rem;
    color: var(--primary-dark);
    font-weight: 600;
}

/* Slideshow */
.slideshow .section-title {
    margin-bottom: 8px;
}

.slideshow-stage {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, #FFF5F8 0%, #FFEAF2 100%);
    border: 1px solid var(--border);
}

.slides {
    display: flex;
    transition: transform 360ms cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
}

.slide {
    flex: 0 0 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 28px 18px;
    text-align: center;
}

.slide-art {
    width: 100%;
    max-width: 240px;
    height: 140px;
    display: grid;
    place-items: center;
    margin-bottom: 6px;
}

.slide-art svg {
    width: 100%;
    height: 100%;
    display: block;
}

.slide-text h3 {
    font-size: 1.02rem;
    margin: 6px 0 4px;
    color: var(--primary-dark);
    font-weight: 700;
}

.slide-text p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.86rem;
    line-height: 1.55;
    max-width: 280px;
}

.slide-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.95);
    color: var(--primary-dark);
    display: grid;
    place-items: center;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: transform 120ms ease, background 120ms ease;
    z-index: 2;
    opacity: 0.85;
}

.slide-nav:hover {
    background: #fff;
    transform: translateY(-50%) scale(1.06);
    opacity: 1;
}

.slide-nav.prev { left: 8px; }
.slide-nav.next { right: 8px; }

.slide-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

.slide-dot {
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: var(--primary-soft);
    transition: width 240ms ease, background 240ms ease;
    border: none;
    padding: 0;
    cursor: pointer;
}

.slide-dot.active {
    width: 22px;
    background: var(--primary);
}

/* === Paywall (unlock chat) — credit card form === */
.paywall-main {
    flex: 1;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 10px 12px 12px;
    background:
        radial-gradient(circle at 20% 0%, rgba(255, 192, 217, 0.45) 0%, transparent 55%),
        radial-gradient(circle at 100% 100%, rgba(255, 192, 217, 0.35) 0%, transparent 55%),
        var(--bg-gradient-start);
    overflow: hidden;
}

.paywall-card {
    width: 100%;
    max-width: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 16px 16px 14px;
    box-shadow: var(--shadow-md);
}

.paywall-head {
    text-align: center;
    margin-bottom: 12px;
}

.paywall-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 3px 9px;
    border-radius: 999px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 6px;
}

.paywall-title {
    margin: 0 0 4px;
    font-size: 1.1rem;
    color: var(--primary-dark);
    font-weight: 800;
}

.paywall-price {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 1px;
    line-height: 1;
}

.paywall-price .currency {
    font-size: 0.85rem;
    color: var(--primary-dark);
    font-weight: 700;
    margin-right: 1px;
}

.paywall-price .amount {
    font-size: 1.7rem;
    color: var(--primary-dark);
    font-weight: 800;
    letter-spacing: -0.02em;
}

.paywall-price .cents {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 700;
}

.paywall-price .usd {
    font-size: 0.55rem;
    color: var(--text-muted);
    font-weight: 700;
    margin-left: 6px;
    align-self: center;
    background: var(--primary-soft);
    padding: 2px 6px;
    border-radius: 5px;
    letter-spacing: 0.06em;
}

/* Credit-card form */
.cc-form { display: flex; flex-direction: column; gap: 10px; }

.cc-field { display: flex; flex-direction: column; gap: 4px; }

.cc-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: end;
}

.cc-label {
    font-size: 0.66rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 700;
    line-height: 1.4;
    min-height: 1.4em;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cc-hint {
    color: var(--primary-dark);
    text-transform: none;
    letter-spacing: 0;
    font-weight: 700;
    font-size: 0.65rem;
    background: var(--primary-soft);
    padding: 1px 6px;
    border-radius: 4px;
    line-height: 1.3;
}

.cc-input {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface-alt);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    padding: 9px 10px;
    height: 38px;
    box-sizing: border-box;
    transition: border-color 120ms ease, background 120ms ease;
}

.cc-input .cc-ico {
    width: 16px;
    height: 16px;
    stroke: var(--text-muted);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.cc-input input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9rem;
    color: var(--text);
    letter-spacing: 0.04em;
    min-width: 0;
    padding: 0;
}

.cc-readonly { opacity: 0.7; }

.cc-readonly input {
    color: var(--text-muted);
    cursor: not-allowed;
}

.cc-active {
    background: var(--surface-alt);
    border-color: var(--primary);
}

.cc-active input {
    text-align: center;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: 0.3em;
}

.cc-active input::placeholder {
    color: var(--primary-light);
    letter-spacing: 0.3em;
}

.cc-brand {
    font-style: italic;
    font-weight: 800;
    color: #1a4a8e;
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    flex-shrink: 0;
}

.btn-pay {
    width: 100%;
    margin-top: 4px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(255, 107, 157, 0.3);
    transition: transform 120ms ease, box-shadow 120ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-family: inherit;
}

.btn-pay:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 22px rgba(255, 107, 157, 0.4);
}

.btn-pay:active { transform: translateY(0); }

.paywall-fineprint {
    margin: 4px 0 0;
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.4;
    text-align: center;
}

.paywall-fineprint code {
    background: var(--primary-soft);
    color: var(--primary-dark);
    padding: 1px 6px;
    border-radius: 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 700;
    letter-spacing: 0.05em;
}

/* === Profile page === */
.profile-hero {
    text-align: center;
    padding: 12px 0 18px;
}

.profile-avatar {
    width: 76px;
    height: 76px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: #fff;
    display: inline-grid;
    place-items: center;
    font-weight: 800;
    font-size: 1.6rem;
    box-shadow: var(--shadow-md);
    margin-bottom: 10px;
}

.profile-name {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.profile-username {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.code-display {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--primary-soft);
    border: 1px dashed var(--primary);
    border-radius: var(--radius-md);
    padding: 10px 14px;
}

.code-text {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    letter-spacing: 0.12em;
    user-select: all;
}

.profile-form .field {
    margin-bottom: 12px;
}

.profile-form .field label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 600;
}

.form-msg {
    font-size: 0.82rem;
    margin: 8px 0 6px;
    min-height: 1em;
}

.form-msg.success { color: #2e7d32; }
.form-msg.error { color: #c62828; }

/* Friend summary card on profile */
.friend-summary {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
    padding: 4px;
    margin: -4px;
    border-radius: var(--radius-md);
    transition: background 120ms ease;
}

.friend-summary:hover { background: var(--primary-soft); }

.friend-summary-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    display: grid;
    place-items: center;
    color: #fff;
    flex-shrink: 0;
}

.friend-summary-text { flex: 1; min-width: 0; }
.friend-summary-text .title { font-weight: 700; font-size: 0.96rem; }
.friend-summary-text .sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* === Friends page === */
.friend-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.friend-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px;
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    border: 1px solid var(--border);
}

.friend-link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    min-width: 0;
}

.friend-row-body { flex: 1; min-width: 0; }

.friend-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friend-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 1px;
}

.friend-row-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-mini {
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
    font-family: inherit;
}

.btn-mini.accept {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-mini.accept:hover {
    background: var(--primary-dark);
}

.btn-mini.decline:hover {
    background: #ffe9ec;
    color: #c62828;
    border-color: #ffd0d6;
}

/* Quick actions grid (kept for backwards compatibility) */
.quick-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.quick-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px;
    background: var(--surface-alt);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 0.72rem;
    text-align: center;
    border: 1px solid var(--border);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.quick-tile:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.quick-tile .ico {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: var(--primary-soft);
    display: grid;
    place-items: center;
    color: var(--primary-dark);
}

.quick-tile .ico svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Task list */
.task-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    border: 1px solid var(--border);
}

.task-time {
    width: 56px;
    text-align: center;
    font-weight: 700;
    color: var(--primary-dark);
    font-size: 0.85rem;
}

.task-body {
    flex: 1;
}

.task-body .title {
    font-size: 0.92rem;
    font-weight: 600;
}

.task-body .meta {
    font-size: 0.76rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.task-status {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid var(--primary-light);
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    transition: background 140ms ease, border-color 140ms ease, transform 120ms ease;
}

.task-status::after {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    transition: opacity 140ms ease, transform 140ms ease;
}

.task-status:hover {
    border-color: var(--primary);
}

.task-status.done {
    background: #4caf50;
    border-color: #4caf50;
}

.task-status.done::after {
    content: '✓';
    width: auto;
    height: auto;
    background: transparent;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1;
}

.task-item {
    cursor: pointer;
    transition: background 120ms ease, transform 120ms ease;
}

.task-item:hover {
    background: var(--primary-soft);
}

.task-item:active {
    transform: scale(0.99);
}

/* Add button (in section title) */
.btn-add {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: var(--shadow-sm);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.btn-add:hover {
    transform: scale(1.06);
    box-shadow: var(--shadow-md);
}

.btn-add:active {
    transform: scale(0.94);
}

/* Empty state */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 18px 12px;
    font-size: 0.88rem;
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(58, 18, 36, 0.45);
    display: grid;
    place-items: center;
    padding: 16px;
    z-index: 100;
    backdrop-filter: blur(2px);
    animation: modal-fade 140ms ease-out;
}

.modal[hidden] {
    display: none;
}

@keyframes modal-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 20px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    animation: modal-pop 180ms ease-out;
}

@keyframes modal-pop {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-title {
    margin: 0 0 14px;
    font-size: 1.1rem;
    color: var(--primary-dark);
}

.modal-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.btn-ghost {
    padding: 9px 14px;
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
    background: transparent;
    transition: background 120ms ease;
}

.btn-ghost:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.btn-ghost.danger {
    color: #c62828;
}

.btn-ghost.danger:hover {
    background: #ffe9ec;
    color: #b71c1c;
}

/* ===== Login page ===== */
.login-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 32px 24px;
    background:
        radial-gradient(circle at 20% 0%, rgba(255, 192, 217, 0.55) 0%, transparent 55%),
        radial-gradient(circle at 100% 100%, rgba(255, 192, 217, 0.45) 0%, transparent 50%),
        linear-gradient(180deg, var(--surface) 0%, #FFF5F8 100%);
}

.brand-block {
    text-align: center;
    margin-top: 28px;
    margin-bottom: 28px;
}

.brand-block .logo {
    width: 92px;
    height: 92px;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    margin-bottom: 14px;
    display: inline-block;
    background: var(--primary-soft);
}

.brand-block .logo img {
    width: 100%;
    height: 100%;
    display: block;
}

.brand-block h1 {
    margin: 6px 0 4px;
    font-size: 1.6rem;
    color: var(--primary-dark);
    letter-spacing: 0.02em;
}

.brand-block p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 22px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
}

.field {
    margin-bottom: 14px;
}

.field label {
    display: block;
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.field .input-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.field .input-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.field .input-wrap svg {
    width: 18px;
    height: 18px;
    stroke: var(--primary);
    fill: none;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.field input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 0.95rem;
    color: var(--text);
    font-family: inherit;
}

.btn-primary {
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--text-on-primary);
    font-weight: 700;
    border-radius: var(--radius-md);
    font-size: 1rem;
    box-shadow: var(--shadow-sm);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.alert {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: #ffeef1;
    color: #c62828;
    font-size: 0.85rem;
    margin-bottom: 12px;
    border: 1px solid #ffd0d6;
}

.helper {
    text-align: center;
    margin-top: 16px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.helper code {
    background: var(--primary-soft);
    color: var(--primary-dark);
    padding: 2px 6px;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ===== Chat list ===== */
.chat-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.chat-empty {
    padding: 18px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.chat-row {
    display: flex;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    color: var(--text);
    transition: background 120ms ease;
    align-items: center;
}

.chat-row:hover {
    background: var(--primary-soft);
}

.chat-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 1.05rem;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.chat-row-body {
    flex: 1;
    min-width: 0;
}

.chat-row-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.chat-name {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 0.72rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.chat-row-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.chat-preview {
    font-size: 0.84rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.chat-preview.unread {
    color: var(--text);
    font-weight: 600;
}

.chat-unread {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 700;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

/* ===== Conversation ===== */
.conv-header {
    gap: 8px;
}

.conv-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.conv-name {
    font-weight: 700;
    font-size: 0.98rem;
    line-height: 1.1;
}

.conv-sub {
    font-size: 0.75rem;
    opacity: 0.85;
    margin-top: 2px;
}

.user-avatar.small {
    width: 34px;
    height: 34px;
    font-size: 0.85rem;
    cursor: default;
}

.selection-header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
}

.sel-count {
    font-weight: 700;
    font-size: 1rem;
    color: #fff;
}

.chat-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background:
        radial-gradient(circle at 0% 0%, rgba(255, 192, 217, 0.2) 0%, transparent 40%),
        radial-gradient(circle at 100% 100%, rgba(255, 192, 217, 0.18) 0%, transparent 40%),
        var(--bg-gradient-start);
}

.bubble-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 100%;
    transition: background 120ms ease, padding 120ms ease;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    user-select: none;
    -webkit-user-select: none;
}

.bubble-wrap.mine {
    flex-direction: row-reverse;
}

.bubble-wrap.theirs {
    flex-direction: row;
}

.bubble-check {
    width: 0;
    height: 22px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid transparent;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    color: #fff;
    font-size: 0.75rem;
    transition: width 160ms ease, opacity 160ms ease, background 160ms ease, border-color 160ms ease;
    opacity: 0;
}

.messages.selecting .bubble-wrap[data-mine="1"] .bubble-check {
    width: 22px;
    opacity: 1;
    border-color: var(--primary);
    background: #fff;
}

.messages.selecting .bubble-wrap.selected .bubble-check {
    background: var(--primary);
    border-color: var(--primary);
}

.messages.selecting .bubble-wrap.selected .bubble-check::after {
    content: '✓';
    color: #fff;
    font-weight: 700;
}

.bubble-wrap.selected {
    background: rgba(255, 107, 157, 0.12);
}

.bubble {
    max-width: min(78%, 320px);
    padding: 9px 13px 6px;
    border-radius: 18px;
    font-size: 0.92rem;
    line-height: 1.4;
    box-shadow: var(--shadow-sm);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    position: relative;
}

.bubble.in {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 6px;
}

.bubble.out {
    background: linear-gradient(135deg, var(--primary) 0%, #FF93BA 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.bubble-body {
    white-space: pre-wrap;
}

.bubble-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 4px;
    font-size: 0.68rem;
    opacity: 0.78;
}

.bubble.in .bubble-meta { color: var(--text-muted); }
.bubble.out .bubble-meta { color: rgba(255,255,255,0.92); }

.bubble-meta .edited {
    font-style: italic;
}

.bubble-meta .ticks {
    font-size: 0.78rem;
    letter-spacing: -1px;
}

.bubble-meta .ticks.read {
    color: #66d0ff;
    text-shadow: 0 0 1px rgba(0,0,0,0.1);
}

.chat-form {
    display: flex;
    gap: 8px;
    padding: 8px 10px 12px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    align-items: end;
}

.input-pill {
    flex: 1;
    display: flex;
    align-items: end;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 4px 6px 4px 4px;
    min-height: 44px;
    transition: border-color 120ms ease, box-shadow 120ms ease;
}

.input-pill:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}

.pill-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    flex-shrink: 0;
    transition: background 120ms ease, color 120ms ease;
}

.pill-icon-btn:hover {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.input-pill textarea {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text);
    padding: 8px 6px;
    max-height: 120px;
    line-height: 1.4;
    overflow-y: auto;
}

.input-pill textarea::placeholder {
    color: var(--text-muted);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: #fff;
    display: grid;
    place-items: center;
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
    transition: transform 120ms ease;
}

.chat-send-btn:hover { transform: scale(1.05); }
.chat-send-btn:active { transform: scale(0.95); }
.chat-send-btn svg { width: 20px; height: 20px; }

/* Emoji picker */
.emoji-panel {
    background: var(--surface);
    border-top: 1px solid var(--border);
    height: 240px;
    display: flex;
    flex-direction: column;
}

.emoji-panel[hidden] { display: none; }

.emoji-tabs {
    display: flex;
    gap: 2px;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.emoji-tab {
    width: 38px;
    height: 32px;
    flex-shrink: 0;
    font-size: 1.1rem;
    border-radius: 10px;
    background: transparent;
    transition: background 120ms ease;
}

.emoji-tab:hover { background: var(--primary-soft); }
.emoji-tab.active {
    background: var(--primary-soft);
    box-shadow: inset 0 -2px 0 var(--primary);
}

.emoji-grid {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 6px;
}

.emoji-cell {
    height: 36px;
    font-size: 1.4rem;
    line-height: 1;
    border-radius: 8px;
    background: transparent;
    transition: background 120ms ease, transform 120ms ease;
}

.emoji-cell:hover { background: var(--primary-soft); }
.emoji-cell:active { transform: scale(0.92); }

/* Date separators */
.date-sep {
    align-self: center;
    margin: 10px 0 4px;
}

.date-sep span {
    display: inline-block;
    font-size: 0.72rem;
    background: rgba(255, 255, 255, 0.92);
    padding: 4px 12px;
    border-radius: 999px;
    color: var(--text-muted);
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(255, 107, 157, 0.05);
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Presence */
.user-avatar { position: relative; }
.chat-avatar { position: relative; }

.presence-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #cfcfcf;
    border: 2px solid #fff;
    box-sizing: content-box;
    display: none;
}

.presence-dot[data-online="1"] {
    display: block;
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    animation: pulse-online 2.4s ease-out infinite;
}

@keyframes pulse-online {
    0%   { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55); }
    70%  { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

.online-text {
    color: #c8f7d5;
    font-weight: 600;
}

.last-seen {
    opacity: 0.85;
}
