:root {
    --primary-color: #ff4d6d;
    --primary-hover: #ff758f;
    --primary-soft: #ffe3e9;
    --bg-color: #fff0f3;
    --card-bg: #ffffff;
    --text-color: #590d22;
    --muted-color: #9d6b7a;
    --border-color: #ffccd5;
    --success: #2a9d8f;
    --shadow: 0 10px 25px rgba(255, 77, 109, 0.1);
    --radius: 14px;
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    background: radial-gradient(1200px 600px at 10% -10%, #ffe3e9 0%, var(--bg-color) 45%, #fff 100%);
    color: var(--text-color);
    margin: 0;
    display: flex;
    justify-content: center;
    padding: 20px;
    min-height: 100vh;
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 1020px;
}

.hidden { display: none !important; }

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 1.2rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 12px 16px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 12px;
    z-index: 20;
    flex-wrap: wrap;
}

h1 {
    color: var(--primary-color);
    margin: 0;
    font-size: 1.45rem;
    letter-spacing: -0.02em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--text-color);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    padding: 6px 12px 6px 6px;
    border-radius: 999px;
}

.profile-icon {
    width: 30px;
    height: 30px;
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
}

.nav-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.92rem;
}
.nav-link:hover { text-decoration: underline; }

/* Cards */
.card {
    background: var(--card-bg);
    padding: 1.6rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    text-align: center;
    margin-top: 4vh;
}

.card h2 { margin: 0 0 6px; }
.card p.muted, .muted { color: var(--muted-color); }

/* Composer */
.composer {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 1rem;
}

.composer-label {
    font-weight: 700;
    font-size: 0.95rem;
    margin: 0 0 8px;
}

.toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 0;
    background: #fff;
    padding: 8px;
    border-radius: 10px 10px 0 0;
    border: 2px solid var(--border-color);
    border-bottom: 1px dashed var(--border-color);
    width: 100%;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar button {
    padding: 6px 10px;
    background: transparent;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    font-size: 0.9rem;
    line-height: 1;
}
.toolbar button:hover, .toolbar button.active {
    background: var(--primary-soft);
    border-color: var(--primary-color);
}
.toolbar .sep { width: 1px; height: 22px; background: var(--border-color); }
.toolbar .hint { margin-left: auto; font-size: 0.8rem; color: var(--muted-color); }

.input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 0;
    align-items: stretch;
}

.rich-editor {
    flex-grow: 1;
    padding: 14px 15px;
    border: 2px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 10px 10px;
    font-size: 1.02rem;
    outline: none;
    transition: box-shadow 0.2s, border-color 0.2s;
    min-height: 64px;
    max-height: 220px;
    overflow-y: auto;
    background: white;
}
.rich-editor:empty:before {
    content: attr(placeholder);
    color: #b08a95;
}
.rich-editor:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(255, 77, 109, 0.18);
}

button#add-question-btn {
    padding: 0 28px;
    min-height: 48px;
    align-self: flex-end;
    white-space: nowrap;
}
button#add-question-btn:disabled { opacity: 0.6; cursor: wait; }

/* Status bar */
.statusbar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin: 0 2px 10px;
    font-size: 0.9rem;
    color: var(--muted-color);
}
.pill {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 4px 12px;
    font-weight: 600;
    color: var(--text-color);
}
.pill.live { background: var(--primary-soft); border-color: var(--primary-color); }
#poke-btn { padding: 6px 14px; font-size: 0.82rem; }
#poke-btn:disabled { opacity: 0.6; cursor: wait; }
#map-switcher {
    padding: 6px 10px;
    border: 2px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);
    background: #fff;
    outline: none;
}
#map-switcher:focus { border-color: var(--primary-color); }

/* Tiles (replaces table view) - vertical layout */
.tiles {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.tiles-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 32px;
    color: var(--muted-color);
    background: var(--card-bg);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius);
}
.tile {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.tile:hover { border-color: var(--primary-color); }
.tile-head { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; user-select: none; }
.tile-head:focus { outline: 2px solid var(--primary-color); outline-offset: 2px; border-radius: 8px; }
.tile-head .question-text { flex: 1; }
.toggle-icon {
    flex-shrink: 0;
    color: var(--primary-color);
    font-weight: 800;
    margin-top: 1px;
    transition: transform 0.2s;
}
.tile.collapsed .toggle-icon { transform: rotate(-90deg); }
.tile.collapsed .answers-grid { display: none; }
.tile-num {
    flex-shrink: 0;
    background: var(--primary-color);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 800;
    border-radius: 8px;
    padding: 3px 9px;
    margin-top: 2px;
}
.tile-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--muted-color);
}
.answer-state {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 2px 10px;
    font-weight: 700;
}
.answers-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.answer-tile {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
}
.answer-tile.is-mine { border-color: var(--primary-color); background: #fff7f9; }
.answer-head { display: flex; align-items: center; gap: 8px; }
.answer-avatar {
    width: 26px; height: 26px;
    border-radius: 50%;
    background: var(--primary-soft);
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.8rem;
    flex-shrink: 0;
}
.answer-name { font-weight: 700; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.you-badge {
    margin-left: auto;
    font-size: 0.7rem;
    font-weight: 800;
    background: var(--primary-color);
    color: #fff;
    border-radius: 999px;
    padding: 2px 8px;
}
.answer-tile .rich-text-cell {
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    padding: 10px;
    min-height: 90px;
}
.answer-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 2px;
}
.saved-line { font-size: 0.78rem; color: var(--muted-color); }
.history-btn {
    margin-left: auto;
    padding: 5px 12px;
    font-size: 0.78rem;
    background: #fff;
    color: var(--primary-color);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-weight: 700;
}
.history-btn:hover { background: var(--primary-soft); }
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 4px;
    max-height: 260px;
    overflow-y: auto;
}
.history-item {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff7f9;
}
.history-meta { font-size: 0.75rem; font-weight: 700; color: var(--muted-color); margin-bottom: 4px; }
.history-text { font-size: 0.88rem; word-break: break-word; }
.history-text img { max-width: 100%; border-radius: 6px; }
.history-empty { font-size: 0.82rem; color: var(--muted-color); font-style: italic; }

/* Table (legacy, kept for compat) */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    min-width: 680px;
}

th, td {
    padding: 14px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

th {
    background: var(--primary-color);
    color: white;
    position: sticky;
    top: 0;
    font-size: 0.95rem;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fff7f9; }

.question-cell { position: relative; max-width: 360px; }
.question-text { padding-right: 4px; word-break: break-word; }
.question-text img, .rich-text-cell img { max-width: 100%; border-radius: 8px; }
.creator-badge {
    display: inline-block;
    margin-top: 8px;
    font-size: 0.75rem;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    padding: 2px 10px;
    color: var(--muted-color);
    font-weight: 600;
}

.question-actions {
    display: none;
    gap: 6px;
    margin-top: 10px;
}
.tile .question-actions { margin-top: 0; margin-left: auto; }
.question-cell:hover .question-actions { display: flex; }

.action-btn {
    padding: 5px 10px;
    font-size: 0.78rem;
    border-radius: 7px;
}
.action-btn.delete { background: #ff4444; }
.action-btn.delete:hover { background: #e03232; }

.rich-text-cell {
    min-width: 200px;
    border-left: 1px solid var(--border-color);
    transition: background 0.15s, box-shadow 0.15s;
    word-break: break-word;
}
.rich-text-cell[contenteditable="true"] {
    background: #fffdfd;
    cursor: text;
}
.rich-text-cell[contenteditable="true"]:hover { background: #fff5f7; }
.rich-text-cell[contenteditable="true"]:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
    background: #fff;
}
.rich-text-cell[contenteditable="false"] {
    background: #faf7f8;
    color: #6d4a55;
}
.rich-text-cell.is-mine { box-shadow: inset 3px 0 0 var(--primary-color); }
.rich-text-cell:empty:before {
    content: 'Click to answer…';
    color: #c39aa4;
    font-style: italic;
}

.edit-mode {
    border: 2px solid var(--primary-color) !important;
    border-radius: 8px;
    background: white !important;
    outline: none;
    padding: 8px;
}

/* Forms */
input[type="text"], input[type="email"], input[type="number"], input[type="password"] {
    width: 100%;
    max-width: 420px;
    padding: 12px 14px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 1rem;
    outline: none;
    background: #fff;
    color: var(--text-color);
}
input:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(255,77,109,.15); }

button {
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.05s, background 0.2s;
}
button:hover { background: var(--primary-hover); }
button:active { transform: translateY(1px); }

#logout-btn { background: #e9e1e4; color: #5b3a44; padding: 9px 16px; }
#logout-btn:hover { background: #dccfd4; }

.flex-col { display: flex; flex-direction: column; gap: 10px; align-items: center; }

.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 14px;
    margin-top: 18px;
}
.user-card {
    background: var(--bg-color);
    padding: 16px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    text-align: center;
}
.user-card button { margin-top: 12px; width: 100%; }

.footer-text { margin-top: 15px; font-size: 0.9rem; }
.footer-text a { color: var(--primary-color); text-decoration: none; font-weight: 700; }

.error { color: #c9184a; font-size: 0.9rem; margin-top: 10px; min-height: 1.2em; }

/* Toast */
#toast {
    position: fixed;
    bottom: 22px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #3a1522;
    color: #fff;
    padding: 11px 18px;
    border-radius: 999px;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
    z-index: 100;
    max-width: 90vw;
    text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.success { background: #1d7a6e; }
#toast.error { background: #c9184a; }

.save-dot {
    display: inline-block;
    font-size: 0.8rem;
    color: var(--muted-color);
    margin-left: 8px;
}

/* Brand */
.brand { display: flex; align-items: center; gap: 10px; }
.brand-center { justify-content: center; margin-bottom: 6px; }
.brand-name { font-weight: 800; font-size: 1rem; color: var(--primary-color); letter-spacing: -0.01em; }
.heart-logo { width: 26px; height: 26px; fill: var(--primary-color); flex-shrink: 0; }
h1 .heart-logo { width: 24px; height: 24px; vertical-align: -3px; margin-right: 2px; }

/* Auth */
.auth-card { max-width: 460px; margin: 5vh auto 0; text-align: left; }
.auth-card h1, .auth-card .auth-sub, .auth-card .footer-text { text-align: center; }
.auth-sub { color: var(--muted-color); margin: 4px 0 20px; font-size: 0.95rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; font-size: 0.88rem; }
.field input { max-width: none; }
.field select {
    padding: 12px 14px; border: 2px solid var(--border-color); border-radius: 10px;
    font-size: 1rem; color: var(--text-color); background: #fff; outline: none;
}
.field select:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(255,77,109,.15); }
.field-hint { font-size: 0.78rem; color: var(--muted-color); }
.full-btn { width: 100%; margin-top: 4px; }
.full-btn:disabled { opacity: 0.6; cursor: wait; }
.password-wrap { position: relative; display: flex; }
.password-wrap input { flex: 1; padding-right: 72px; }
.password-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    background: transparent; color: var(--primary-color);
    padding: 6px 10px; font-size: 0.8rem; border-radius: 8px;
}
.password-toggle:hover { background: var(--primary-soft); }
.privacy-note {
    margin-top: 16px; padding-top: 14px;
    border-top: 1px solid var(--border-color);
    font-size: 0.82rem; color: var(--muted-color); text-align: center;
}
.privacy-note a { color: var(--primary-color); font-weight: 700; text-decoration: none; }

/* Dashboard sections */
.section-card { text-align: left; margin-top: 16px; }
.section-card:first-of-type { margin-top: 0; }
.toolbar-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.toolbar-row input { max-width: 280px; }
.btn-secondary { background: #fff; color: var(--primary-color); border: 2px solid var(--border-color); }
.btn-secondary:hover { background: var(--primary-soft); }
.visibility-note {
    margin-top: 12px; padding: 10px 14px;
    background: var(--bg-color); border: 1px solid var(--border-color);
    border-radius: 10px; font-size: 0.85rem; color: var(--muted-color);
}
.maps-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.map-row {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    background: var(--bg-color); border: 1px solid var(--border-color);
    border-radius: 10px; padding: 10px 14px;
}
.map-row .map-name { font-weight: 700; }
.map-row .map-meta { font-size: 0.82rem; color: var(--muted-color); }
.map-row button { margin-left: auto; padding: 8px 18px; }
.invite-actions { margin-left: auto; display: flex; gap: 8px; }
.invite-actions button { margin-left: 0; }
.pending-notice {
    background: #fff; border: 2px dashed var(--border-color);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 26px; text-align: center; margin-bottom: 1rem;
}
.pending-notice h2 { margin: 0 0 8px; }
.pending-notice p { color: var(--muted-color); margin: 0 0 14px; }

/* Composer popover + counter */
.composer { position: relative; }
.inline-toolbar { margin-bottom: 10px; }
.inline-toolbar[hidden] { display: none; }
.inline-toolbar .toolbar { border-radius: 10px; border-bottom: 2px solid var(--border-color); }
.color-btn-wrap {
    position: relative; width: 32px; height: 26px;
    border: 1px solid var(--border-color); border-radius: 6px;
    background: #fff; cursor: pointer; overflow: hidden;
    display: inline-flex; align-items: center; justify-content: center;
}
.color-btn-wrap .color-a { font-weight: 800; font-size: 0.95rem; border-bottom: 3px solid var(--primary-color); line-height: 1; }
.color-btn-wrap input[type="color"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
/* Modal popup */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(58, 21, 34, 0.45);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
    background: #fff; border-radius: var(--radius);
    border: 1px solid var(--border-color); box-shadow: var(--shadow);
    padding: 20px; width: 100%; max-width: 440px;
}
.modal h3 { margin: 0 0 12px; color: var(--primary-color); }
.modal .field { margin-bottom: 12px; }
.modal select {
    padding: 10px 12px; border: 2px solid var(--border-color); border-radius: 10px;
    font-size: 0.95rem; color: var(--text-color); background: #fff; outline: none;
}
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.link-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.link-tabs button[aria-pressed="true"] { outline: 2px solid var(--primary-color); }
.composer-foot { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.char-count { margin-left: auto; font-size: 0.78rem; color: var(--muted-color); }
.char-count.over { color: #c9184a; font-weight: 700; }

/* Site footer */
.site-footer {
    margin: 26px 2px 8px; padding-top: 14px;
    border-top: 1px solid var(--border-color);
    font-size: 0.82rem; color: var(--muted-color);
    display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: center;
}
.site-footer a { color: var(--primary-color); font-weight: 700; text-decoration: none; }
.site-footer a:hover { text-decoration: underline; }

/* Prose page (privacy) */
.prose h2 { margin: 22px 0 8px; font-size: 1.1rem; color: var(--text-color); }
.prose p, .prose li { font-size: 0.94rem; color: #6d3a48; }
.prose ul { padding-left: 20px; }

/* Danger zone */
.danger-zone { border-color: #f0a8b8; }
.danger-btn { background: #c9184a; }
.danger-btn:hover { background: #a41340; }
.danger-btn:disabled { opacity: 0.6; cursor: wait; }

/* Avatars */
.profile-icon img, img.avatar-img {
    width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
}
.profile-icon { overflow: hidden; flex-shrink: 0; }
.answer-avatar { overflow: hidden; }
.answer-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Profile editor */
.profile-edit { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.avatar-preview {
    width: 96px; height: 96px; border-radius: 50%;
    background: var(--primary-soft); border: 2px solid var(--border-color);
    display: flex; align-items: center; justify-content: center;
    font-size: 2rem; font-weight: 800; color: var(--primary-color);
    overflow: hidden; flex-shrink: 0;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-controls { display: flex; flex-direction: column; gap: 8px; }
.avatar-controls input[type="file"] { font-size: 0.85rem; max-width: 240px; }
.avatar-row { display: flex; gap: 8px; flex-wrap: wrap; }
.avatar-row button { padding: 8px 16px; font-size: 0.85rem; }
.profile-fields { flex: 1; min-width: 240px; }
textarea#profile-bio {
    width: 100%; max-width: 460px; min-height: 76px; resize: vertical;
    padding: 12px 14px; border: 2px solid var(--border-color); border-radius: 10px;
    font-size: 1rem; font-family: inherit; color: var(--text-color); outline: none;
}
textarea#profile-bio:focus { border-color: var(--primary-color); box-shadow: 0 0 0 3px rgba(255,77,109,.15); }

/* Responsive */
@media (max-width: 760px) {
    body { padding: 12px; }
    header { top: 8px; padding: 10px 12px; }
    h1 { font-size: 1.2rem; }
    .input-group { flex-direction: column; }
    button#add-question-btn { width: 100%; }
    .table-wrap { border-radius: 12px; }
}
