:root {
  --bg-base: #f0f4f8; 
  --bg-card: #ffffff;
  --text-main: #1e293b; 
  --text-sub: #64748b;
  --border: #e2e8f0; 
  --primary: #3b82f6; 
  --primary-hover: #2563eb;
  --msg-host: #ffffff;      
  --msg-guest: #3b82f6;     
  --msg-text-guest: #ffffff;
  --ghost-bg: rgba(59, 130, 246, 0.1); 
  --ghost-text: #64748b;
  --tick-seen: #10b981; 
  --tick-deliv: #94a3b8;
  --radius: 14px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body.dark-mode {
  --bg-base: #000000; 
  --bg-card: #0a0a0a;
  --text-main: #e2e8f0; 
  --text-sub: #8b949e;
  --border: #1f2937; 
  --primary: #2563eb; 
  --primary-hover: #3b82f6;
  --msg-host: #111111; 
  --msg-guest: #1e3a8a; 
  --msg-text-guest: #ffffff;
  --ghost-bg: rgba(37, 99, 235, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(134, 150, 160, 0.3); border-radius: 10px; }
.dark-mode ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); }

html { background-color: var(--bg-base); }
body { 
  font-family: var(--font-sans); background-color: var(--bg-base); color: var(--text-main); 
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  width: 100%; height: 100%; overflow: hidden; display: flex; flex-direction: column;
}

#custom-alert-overlay, #custom-confirm-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); z-index: 9999; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); padding: 20px;}
.custom-alert-box { background: var(--bg-card); padding: 24px 20px; border-radius: var(--radius); width: 100%; max-width: 340px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.15); border: 1px solid var(--border); animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.custom-alert-box h3 { margin-bottom: 12px; font-size: 1.2rem; color: var(--text-main); font-weight: 700; }
.custom-alert-box p { color: var(--text-sub); margin-bottom: 24px; font-size: 0.95rem; line-height: 1.5; }
.btn-success { background-color: var(--primary); color: white; border: none; padding: 12px; border-radius: 10px; cursor: pointer; width: 100%; font-weight: 600; font-size: 1rem; margin-bottom: 0; }
@keyframes popIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#peer-warn-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #ef4444; color: white; padding: 6px 16px; border-radius: 20px; font-size: 0.85rem; font-weight: bold; z-index: 50; box-shadow: 0 4px 10px rgba(239,68,68,0.3); animation: slideDown 0.3s ease; }
@keyframes slideDown { from { transform: translate(-50%, -20px); opacity: 0;} to { transform: translate(-50%, 0); opacity: 1;} }

.app-header { background: var(--bg-card); padding: calc(12px + var(--safe-top)) 20px 12px; border-bottom: 1px solid var(--border); z-index: 10; flex-shrink: 0; }
.header-content { display: flex; justify-content: space-between; align-items: center; max-width: 650px; margin: 0 auto; width: 100%; }
.brand-group { display: flex; flex-direction: column; }
.brand { color: var(--text-main); font-weight: 800; font-size: 1.3rem; letter-spacing: -0.02em;}
.brand-sub { font-size: 0.75rem; font-weight: 600; color: var(--primary); margin-top: -2px;}

#app-container { flex: 1; width: 100%; max-width: 650px; margin: 0 auto; display: flex; flex-direction: column; position: relative; overflow: hidden; }

.view { display: flex; flex-direction: column; width: 100%; height: 100%; overflow: hidden; }
.idle-view { padding: 20px; align-items: center; overflow-y: auto; }

.card { background: var(--bg-card); padding: 24px; border-radius: var(--radius); width: 100%; max-width: 400px; border: 1px solid var(--border); text-align: center; margin: auto; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.card h1 { font-size: 1.5rem; margin-bottom: 8px; color: var(--text-main); }
.card p { color: var(--text-sub); margin-bottom: 24px; font-size: 0.95rem; }

input:not([type="file"]):not([type="checkbox"]):not([type="range"]):not([type="color"]), select { width: 100%; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg-base); color: var(--text-main); font-size: 16px; margin-bottom: 16px; font-family: inherit; }
input.otp-input { text-align: center; font-size: 1.6rem; font-weight: 800; letter-spacing: 2px; color: var(--text-main); }
button { background-color: var(--primary); color: #ffffff; border: none; border-radius: 10px; padding: 14px; font-size: 1rem; font-weight: 600; cursor: pointer; width: 100%; margin-bottom: 12px; display: flex; align-items: center; justify-content: center; gap: 8px; font-family: inherit;}
button.secondary { background-color: var(--bg-base); color: var(--text-main); border: 1px solid var(--border); }
.btn-danger { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid #ef4444; }

.pill-btn { background: var(--bg-base); border: 1px solid var(--primary); color: var(--primary); padding: 8px 16px; border-radius: 20px; font-weight: 600; display: flex; align-items: center; gap: 6px; cursor: pointer; width: auto; margin: 0; font-size: 0.9rem; }
.pill-btn:hover { background: rgba(59, 130, 246, 0.1); }

#settings-overlay { position: fixed; top:0; left:0; right:0; bottom:0; background: rgba(0,0,0,0.7); display: flex; justify-content: center; align-items: center; z-index: 100; padding: 20px;}
.settings-card { background: var(--bg-card); padding: 24px; border-radius: var(--radius); width: 100%; max-width: 400px; border: 1px solid var(--border); }
.setting-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; font-weight: 500; gap: 15px;}
.setting-text { display: flex; flex-direction: column; text-align: left; }
.setting-text span { font-weight: 600; font-size: 0.95rem; color: var(--text-main);}
.setting-text small { color: var(--text-sub); font-size: 0.8rem; margin-top: 4px; font-weight: normal;}
.setting-data-usage { background: var(--bg-base); padding: 12px; border-radius: 10px; margin-bottom: 20px; border: 1px solid var(--border); font-size: 0.9rem;}
.metric-row { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--text-sub); }
.metric-row strong { color: var(--text-main); }
#data-counter { font-weight: bold; color: var(--primary); font-size: 1rem; margin-top: 4px; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border); transition: .3s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 1px 3px rgba(0,0,0,0.2);}
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

.qr-wrapper { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; margin: 15px 0; }
.qr-box { background: white; padding: 15px; border-radius: 10px; display: flex; justify-content: center; align-items: center; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.1); }
#qrcode { display: flex; justify-content: center; align-items: center; width: 100%; }

.chat-wrapper { position: relative; flex: 1; overflow: hidden; width: 100%; display: flex; flex-direction: column; background: var(--bg-base); }
#media-container { position: relative; width: 100%; max-height: 40%; background: #000; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: center; z-index: 10; flex-shrink: 0; }
#media-container:not(.hidden) { display: flex; }
#media-container:fullscreen { max-height: 100vh; background: #000; }
#media-container:-webkit-full-screen { max-height: 100vh; background: #000; }
#remote-screen { width: 100%; max-height: 100%; object-fit: contain; }
.overlay-btn { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,0.5); color: white; border: none; border-radius: 8px; width: 36px; height: 36px; font-size: 1.2rem; display: flex; align-items: center; justify-content: center; cursor: pointer; z-index: 20; padding: 0; margin: 0; backdrop-filter: blur(2px);}

#chat-log { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; scroll-behavior: smooth; z-index: 1; transition: opacity 0.3s ease; }
#chat-log.fade-out { opacity: 0.15; pointer-events: none; }
/* Pushes early messages to bottom to prevent hiding under keyboard */
#chat-log::before { content: ""; flex: 1; min-height: 0; }

#chat-canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 5; transition: background-color 0.3s ease; }
#chat-canvas.active { pointer-events: auto; cursor: crosshair; }
#chat-canvas.solid { background-color: var(--bg-base); }

#draw-toolbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--bg-card); border-bottom: 1px solid var(--border); position: absolute; top: 0; left: 0; width: 100%; z-index: 20; box-shadow: 0 4px 15px rgba(0,0,0,0.05); transition: transform 0.3s ease; }
#draw-toolbar-content { display: flex; flex: 1; align-items: center; justify-content: space-between; gap: 10px; overflow-x: auto; }
#draw-toolbar.collapsed { transform: translateY(calc(-100% + 50px)); background: transparent; border: none; box-shadow: none; justify-content: flex-end;}
#draw-toolbar.collapsed #draw-toolbar-content { display: none; }

.color-picker { display: flex; align-items: center; gap: 10px; }
.color-picker-input { -webkit-appearance: none; border: none; width: 34px; height: 34px; border-radius: 50%; overflow: hidden; cursor: pointer; padding: 0; background: none; }
.color-picker-input::-webkit-color-swatch-wrapper { padding: 0; }
.color-picker-input::-webkit-color-swatch { border: 2px solid var(--border); border-radius: 50%; }

.draw-actions { display: flex; gap: 6px; align-items: center; }
.draw-actions button { padding: 6px 10px; margin: 0; font-size: 0.85rem; width: auto; border-radius: 8px; }
.draw-icon-btn { background: var(--bg-base); border: 1px solid var(--border); border-radius: 8px; width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-main); padding: 0; margin: 0; }
.draw-icon-btn:hover { background: var(--border); }
.draw-send-btn { background: var(--primary); color: white; padding: 6px 12px; border-radius: 8px; border: none; font-weight: 600; cursor: pointer;}
.draw-cancel-btn { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid #ef4444; padding: 6px 12px; border-radius: 8px; font-weight: 600; cursor: pointer; }

#btn-draw-collapse { background: var(--bg-card); border: 1px solid var(--border); border-radius: 50%; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.1); color: var(--text-main); padding: 0; flex-shrink: 0;}

.msg-wrap { display: flex; flex-direction: column; max-width: 85%; margin-bottom: 8px; z-index: 2; overflow: hidden; flex-shrink: 0; }
.msg-wrap.self { align-self: flex-end; align-items: flex-end; }
.msg-wrap.peer { align-self: flex-start; align-items: flex-start; }

.msg-bubble { 
  padding: 10px 14px; border-radius: 16px; font-size: 0.98rem; line-height: 1.45; 
  word-wrap: break-word; overflow-wrap: break-word; word-break: break-word; 
  white-space: pre-wrap; box-shadow: 0 1px 3px rgba(0,0,0,0.05); max-width: 100%; 
  box-sizing: border-box; cursor: pointer; position: relative;
  transition: transform 0.2s ease-out;
}
.msg-bubble.swiping { transition: none; }
.msg-bubble.single-emoji { background: transparent !important; box-shadow: none !important; font-size: 3.5rem; padding: 0 !important; border: none !important; line-height: 1.1; }

.msg-quote {
  background: rgba(0, 0, 0, 0.08); border-left: 4px solid var(--primary);
  padding: 6px 10px; border-radius: 6px; font-size: 0.85rem; margin-bottom: 6px;
  color: inherit; opacity: 0.9; max-height: 60px; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.dark-mode .msg-quote { background: rgba(255, 255, 255, 0.1); }

.msg-wrap.self .msg-bubble { background: var(--msg-guest); color: var(--msg-text-guest); border-bottom-right-radius: 4px; }
.msg-wrap.peer .msg-bubble { background: var(--msg-host); color: var(--text-main); border-bottom-left-radius: 4px; border: 1px solid var(--border); }
.msg-meta { display: flex; align-items: center; gap: 4px; margin-top: 3px; font-size: 0.75rem; color: var(--text-sub); font-weight: 500;}

.msg-ticks svg { width: 16px; height: 16px; stroke: var(--tick-deliv); stroke-width: 2.5px; opacity: 0.9;}
.msg-ticks.seen svg { stroke: var(--tick-seen); filter: drop-shadow(0 0 2px rgba(16, 185, 129, 0.4));}

.file-bubble { width: 250px; max-width: 100%; overflow: hidden; display: flex; flex-direction: column; gap: 8px; }
.media-preview { width: 100%; max-width: 100%; max-height: 200px; object-fit: contain; border-radius: 10px; background: #000; cursor: pointer; border: 1px solid rgba(0,0,0,0.1); }
.canvas-snapshot { max-width: 100%; max-height: 300px; object-fit: contain; background: var(--bg-base); box-shadow: inset 0 0 0 1px var(--border); } 

.file-row { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem;}
.file-progress-bg { height: 6px; background: rgba(0,0,0,0.1); border-radius: 3px; overflow: hidden; width: 100%;}
.dark-mode .file-progress-bg { background: rgba(255,255,255,0.1); }
.file-progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.1s; }
.btn-cancel { background: transparent; color: #ef4444; opacity: 0.8; border: none; padding: 4px; cursor: pointer; display: flex; margin: 0; width: auto;}

.batch-folder { background: var(--bg-card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; margin-top: 5px;}
.batch-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; font-weight: 600; font-size: 0.9rem;}
.batch-list { display: none; margin-top: 10px; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.batch-list.open { display: flex; }

#chat-input-container { display: flex; flex-direction: column; background: var(--bg-card); z-index: 10; flex-shrink: 0; border-top: 1px solid var(--border);}
.input-row { display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px calc(10px + var(--safe-bottom)); width: 100%; }

#reply-preview { display: flex; justify-content: space-between; align-items: center; padding: 10px 15px; background: var(--bg-base); border-left: 4px solid var(--primary); margin: 0; font-size: 0.85rem; color: var(--text-sub); }
#reply-preview p { margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 90%; color: var(--text-main); font-weight: 500;}
#close-reply { background: transparent; border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-sub); padding: 0; margin: 0; width: auto;}

#chat-input { 
  flex: 1; min-height: 44px; max-height: 100px; padding: 12px 16px; margin: 0; 
  border: 1px solid var(--border); border-radius: 22px; background: var(--bg-base); 
  color: var(--text-main); font-size: 16px; 
  resize: none; outline: none; line-height: 1.4;
  overflow-y: auto; font-family: inherit;
}

.icon-btn { background: transparent; border: none; padding: 10px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text-sub); width: auto; margin:0;}
.primary-icon { background: var(--primary); color: white; width: 44px; height: 44px; flex-shrink: 0; padding: 0; border-radius: 50%;}
.primary-icon:hover { background: var(--primary-hover); }
.primary-icon:active { transform: scale(0.95); }

.dice-menu-container { position: relative; }
.action-menu { position: absolute; bottom: calc(100% + 10px); left: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 8px; display: flex; flex-direction: column; gap: 4px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275); box-shadow: 0 10px 30px rgba(0,0,0,0.15); z-index: 20; min-width: 190px;}
.action-menu.active { opacity: 1; pointer-events: all; transform: translateY(0); }
.action-btn { background: transparent; border: none; padding: 12px 14px; display: flex; align-items: center; gap: 12px; color: var(--text-main); cursor: pointer; border-radius: 10px; font-size: 0.95rem; width: 100%; margin: 0; justify-content: flex-start;}
.action-btn:hover { background: var(--bg-base); }
.action-btn.active-green { color: #10b981; font-weight: 600; }
.menu-divider { height: 1px; background: var(--border); margin: 4px 0; }

#ghost-typing-container { padding: 4px 15px; font-size: 0.85rem; color: var(--ghost-text); display: flex; align-items: center; gap: 8px; background: var(--bg-base); }
.typing-indicator { display: flex; gap: 4px; }
.typing-indicator span { width: 6px; height: 6px; background: var(--text-sub); border-radius: 50%; animation: typing 1.4s infinite ease-in-out both; }
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

.link-animation { display: flex; align-items: center; justify-content: center; gap: 15px; margin: 30px 0; }
.orb { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 15px var(--primary); animation: pulseOrb 1.5s infinite alternate; }
.beam-container { width: 100px; height: 3px; background: var(--border); border-radius: 2px; overflow: hidden; position: relative;}
.beam { position: absolute; top: 0; left: -50px; width: 50px; height: 100%; background: var(--primary); box-shadow: 0 0 10px var(--primary); animation: shootBeam 1.5s infinite linear; }
@keyframes pulseOrb { 0% { transform: scale(0.8); opacity: 0.6; } 100% { transform: scale(1.2); opacity: 1; } }
@keyframes shootBeam { 0% { left: -50px; } 100% { left: 100px; } }
.hidden { display: none !important; }
.mt-10 { margin-top: 10px; }

#context-menu { position: fixed; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); padding: 5px; z-index: 1000; min-width: 120px; display: flex; flex-direction: column; gap: 2px; }
.context-item { background: transparent; border: none; padding: 10px 15px; text-align: left; width: 100%; cursor: pointer; color: var(--text-main); font-size: 0.95rem; border-radius: 8px; margin: 0; }
.context-item:hover { background: var(--bg-base); }

#scroll-down-btn { position: absolute; bottom: 80px; right: 20px; width: 44px; height: 44px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 10px rgba(0,0,0,0.1); z-index: 5; color: var(--text-sub); transition: transform 0.2s; }
#scroll-down-btn:active { transform: scale(0.9); }
.unread-badge { position: absolute; top: -5px; right: -5px; background: var(--primary); color: white; font-size: 0.7rem; font-weight: bold; height: 20px; min-width: 20px; padding: 0 6px; border-radius: 10px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg-card); }

.msg-wrap.self .file-bubble { background: var(--bg-card) !important; color: var(--text-main) !important; border: 1px solid var(--primary); border-bottom-right-radius: 4px; }
.msg-wrap.self .file-row strong, .msg-wrap.self .file-row small { color: var(--text-main) !important; }
.file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; min-width: 0; }
.media-preview-audio { width: 100%; height: 40px; margin-bottom: 8px; outline: none; border-radius: 20px; }
