:root {
    --ink: #151515;
    --muted: #858585;
    --blue: #2864e8;
    --amber: #e9a12b;
    --line: #e8e8e8;
    font-family: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: #fff; }
body { color: var(--ink); font-family: 'Cairo', system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
button, textarea, select { font: inherit; }
button { cursor: pointer; }
.app-shell { width: min(1100px, calc(100% - 24px)); margin: 0 auto; padding: max(8px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom)); }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 0 0 10px; }
.stat-card { min-width: 0; min-height: 64px; display: flex; align-items: center; gap: 11px; padding: 9px 15px; border: 1px solid #ededed; border-radius: 14px; background: #fff; box-shadow: 0 3px 13px rgba(0,0,0,.035); }
.stat-icon { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border-radius: 10px; }
.stat-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.visitors-icon { color: var(--blue); background: #eef3ff; }
.messages-icon { color: #b9780d; background: #fff5e4; }
.stat-copy { min-width: 0; display: flex; flex-direction: column; }
.stat-label { color: #858585; font-size: 10px; font-weight: 600; line-height: 1.5; }
.stat-card strong { color: var(--ink); font-size: clamp(18px, 3.5vw, 24px); line-height: 1.2; font-weight: 800; direction: ltr; text-align: right; font-variant-numeric: tabular-nums; }
.grid-stage { position: relative; width: 100%; height: calc(100svh - 98px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); min-height: 280px; display: grid; place-items: center; overflow: hidden; }
.grid-viewport { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: auto; background: #fff; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #cbd0d6 #f7f7f7; }
.grid-viewport.is-zoomed { align-items: flex-start; justify-content: flex-start; }
#message-grid { display: block; flex: 0 0 auto; width: 100%; height: auto; max-width: 1000px; aspect-ratio: 1 / 1; image-rendering: pixelated; image-rendering: crisp-edges; cursor: crosshair; touch-action: pan-x pan-y; user-select: none; -webkit-user-select: none; }
.zoom-controls { position: absolute; z-index: 5; top: 9px; right: 9px; display: flex; gap: 6px; direction: ltr; }
.zoom-controls button { width: 33px; height: 33px; display: grid; place-items: center; padding: 0; border: 1px solid #e6e6e6; border-radius: 9px; background: rgba(255,255,255,.96); color: #444; box-shadow: 0 2px 9px rgba(0,0,0,.07); font-size: 20px; line-height: 1; }
.zoom-controls button:hover { border-color: #bdbdbd; color: #111; }

/* First-visit welcome popup */
.welcome-backdrop { position: fixed; inset: 0; z-index: 130; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(15,17,20,.48); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); }
.welcome-backdrop.is-open { display: flex; animation: fade-in .18s ease; }
.welcome-modal { position: relative; width: min(100%, 460px); padding: 33px 30px 27px; border: 1px solid rgba(255,255,255,.85); border-radius: 23px; background: #fff; box-shadow: 0 24px 80px rgba(0,0,0,.22); text-align: right; animation: modal-in .2s ease; }
.welcome-close { position: absolute; left: 15px; top: 14px; width: 33px; height: 33px; display: grid; place-items: center; border: 1px solid #ededed; border-radius: 10px; background: #fff; color: #777; font-size: 22px; line-height: 1; }
.welcome-brand { display: flex; align-items: center; gap: 9px; margin-bottom: 17px; color: #888; font-size: 9px; font-weight: 900; letter-spacing: 1.4px; direction: ltr; justify-content: flex-end; }
.welcome-mark { width: 9px; height: 9px; display: inline-block; border: 1px solid #171717; background: var(--amber); box-shadow: 5px 5px 0 #171717; margin-left: 4px; }
.welcome-modal h1 { margin: 0 0 11px; color: #171717; font-size: clamp(21px, 5vw, 27px); line-height: 1.55; font-weight: 900; }
.welcome-modal p { margin: 0 0 10px; color: #707070; font-size: 13px; line-height: 2.05; }
.welcome-modal .welcome-last-line { margin-top: 5px; color: #242424; font-weight: 700; }
.welcome-start { width: 100%; min-height: 49px; display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 21px; padding: 10px 16px; border: 0; border-radius: 12px; background: #171717; color: #fff; font-size: 12px; font-weight: 800; transition: transform .15s, background .15s; }
.welcome-start:hover { background: #303030; transform: translateY(-1px); }
.welcome-start span { font-size: 17px; }

/* Message compose/read popup */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(13,22,39,.48); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px); }
.modal-backdrop.is-open { display: flex; animation: fade-in .14s ease; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.message-modal { position: relative; width: min(100%, 485px); max-height: min(90vh, 780px); overflow-y: auto; padding: 30px; border: 1px solid rgba(255,255,255,.7); border-radius: 22px; background: #fff; box-shadow: 0 25px 80px rgba(5,15,35,.24); animation: modal-in .18s ease; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-close { position: absolute; left: 16px; top: 14px; width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid #ebedf1; border-radius: 10px; background: #fff; color: #737d8d; font-size: 22px; line-height: 1; }
.modal-close:hover { background: #f5f7fb; color: #111827; }
.modal-topline { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; color: #a0a8b5; font-size: 9px; font-weight: 800; letter-spacing: 1.5px; direction: ltr; }
.modal-mark { width: 8px; height: 8px; border-radius: 2px; background: var(--amber); box-shadow: 8px 0 #171717; margin-right: 8px; }
.message-modal h2 { margin: 0 0 5px; font-size: 24px; font-weight: 800; }
.modal-description { margin: 0 0 16px; color: #8b94a2; font-size: 12px; line-height: 1.9; }
.selected-cell { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; margin-bottom: 13px; border: 1px solid #edf0f5; border-radius: 8px; color: #9099a7; background: #fafbfd; font-size: 10px; }
.selected-cell b { color: var(--amber); direction: ltr; }
#message-input { display: block; width: 100%; min-height: 145px; resize: vertical; padding: 14px 15px; border: 1px solid #e3e7ee; border-radius: 13px; outline: none; background: #fcfdff; color: var(--ink); font-size: 13px; line-height: 1.9; transition: border .15s, box-shadow .15s; }
#message-input:focus { border-color: #e4b65e; box-shadow: 0 0 0 3px rgba(233,161,43,.12); background: #fff; }
#message-input::placeholder { color: #b0b7c2; }
.form-meta { display: flex; justify-content: space-between; gap: 9px; margin: 8px 2px 13px; color: #a0a8b4; font-size: 9px; }
#char-count { direction: ltr; font-variant-numeric: tabular-nums; }
.primary-button { width: 100%; min-height: 47px; display: flex; justify-content: center; align-items: center; gap: 13px; padding: 10px 17px; border: 0; border-radius: 11px; background: #171717; color: #fff; font-size: 12px; font-weight: 800; box-shadow: 0 7px 16px rgba(0,0,0,.12); transition: background .15s, transform .15s; }
.primary-button:hover { background: #303030; transform: translateY(-1px); }
.primary-button:disabled { opacity: .65; cursor: wait; transform: none; }
.privacy-note { margin: 12px 0 0; color: #a0a7b2; font-size: 9px; line-height: 1.8; text-align: center; }
.form-error { min-height: 0; margin: 0 0 8px; color: #c2413a; font-size: 11px; line-height: 1.6; }
.form-error:empty { display: none; }
.published-message { margin: 3px 0 15px; padding: 19px; border: 1px solid #edf0f4; border-right: 3px solid var(--amber); border-radius: 12px; background: #fcfdff; color: #333d4d; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 2; }
.read-meta { display: flex; justify-content: space-between; color: #a0a8b4; font-size: 10px; }
.report-area { margin-top: 22px; padding-top: 15px; border-top: 1px solid #eff1f5; }
.report-area > label { display: block; margin-bottom: 8px; color: #929baa; font-size: 10px; }
.report-row { display: flex; gap: 8px; }
.report-row select { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid #e7eaf0; border-radius: 8px; background: #fff; color: #6d7787; font-size: 10px; }
.report-button { padding: 7px 15px; border: 1px solid #f1d7d5; border-radius: 8px; background: #fff8f7; color: #bb5a53; font-size: 10px; font-weight: 700; }
.report-button:hover { background: #fff0ee; }
.success-check { width: 52px; height: 52px; display: grid; place-items: center; margin: 2px 0 17px; border-radius: 16px; background: #eaf8f2; color: #1b9b68; font-size: 25px; font-weight: 700; }
.hp-field, .sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }
[hidden] { display: none !important; }
button:focus-visible, select:focus-visible, canvas:focus-visible { outline: 3px solid rgba(233,161,43,.35); outline-offset: 3px; }
@media (max-width: 520px) {
    .app-shell { width: calc(100% - 14px); }
    .stats { gap: 7px; margin-bottom: 7px; }
    .stat-card { min-height: 57px; padding: 7px 9px; gap: 7px; border-radius: 11px; }
    .stat-icon { width: 30px; height: 30px; flex-basis: 30px; border-radius: 8px; }
    .stat-icon svg { width: 16px; height: 16px; }
    .stat-label { font-size: 9px; }
    .grid-stage { height: calc(100svh - 79px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
    .zoom-controls { top: 6px; right: 6px; }
    .zoom-controls button { width: 30px; height: 30px; border-radius: 8px; }
    .welcome-modal { padding: 30px 21px 21px; border-radius: 19px; }
    .welcome-modal p { font-size: 12px; }
    .message-modal { padding: 26px 19px 21px; border-radius: 18px; }
    .message-modal h2 { font-size: 22px; }
    #message-input { min-height: 132px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* Shareable message link */
.share-message-button { width: 100%; min-height: 42px; display: flex; justify-content: center; align-items: center; gap: 9px; margin-top: 15px; padding: 9px 14px; border: 1px solid #ead7b4; border-radius: 10px; background: #fffaf1; color: #8b5c12; font-size: 11px; font-weight: 800; }
.share-message-button:hover { background: #fff3dc; border-color: #e4bf7e; }
.share-message-button:disabled { opacity: .65; cursor: wait; }
