:root {
  --bg-color: #f5f5f7; --surface-color: #ffffff; --text-primary: #1d1d1f; --text-secondary: #86868b;
  --accent-color: #000000; --accent-text: #ffffff; --border-color: #d2d2d7; --danger-color: #ff3b30;
  --msg-bubble-self: #000000; --msg-text-self: #ffffff; --radius: 16px;
}
[data-theme="dark"] {
  --bg-color: #000000; --surface-color: #1c1c1e; --text-primary: #f5f5f7; --text-secondary: #8e8e93;
  --accent-color: #ffffff; --accent-text: #000000; --border-color: #38383a; --msg-bubble-self: #ffffff; --msg-text-self: #000000;
}

html, body { height: 100%; width: 100%; overflow: hidden; position: fixed; margin: 0; padding: 0; touch-action: none; }
body { background-color: var(--bg-color); color: var(--text-primary); font-family: -apple-system, sans-serif; display: flex; justify-content: center; transition: 0.3s; }

.top-controls { position: absolute; top: 20px; right: 20px; display: flex; gap: 12px; z-index: 99999; pointer-events: auto; }
.text-icon { font-size: 14px; font-weight: 600; width: auto !important; padding: 0 10px; background: transparent; border: none; color: var(--text-primary); cursor: pointer; }
.icon-btn { background: transparent; border: none; color: var(--text-primary); cursor: pointer; display: flex; align-items: center; justify-content: center;}

.app-container { width: 100%; max-width: 600px; height: 100dvh; display: flex; flex-direction: column; position: relative; z-index: 1;}

.view { display: none; flex-direction: column; height: 100%; width: 100%; box-sizing: border-box; }
.view.active { display: flex; }
.view-content { padding: 100px 20px 40px; display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 400px; margin: 0 auto; overflow-y: auto; touch-action: auto;}

h1 { font-size: 34px; font-weight: 700; margin-bottom: 8px; text-align: center; }
.sub-text { color: var(--text-secondary); font-size: 15px; margin-bottom: 40px; text-align: center; }
.glitch-404 { font-size: 90px; font-weight: 900; line-height: 1; margin-bottom: 5px; color: var(--danger-color); letter-spacing: -3px; }

.input-group { width: 100%; display: flex; flex-direction: column; gap: 15px; }
input { width: 100%; background: var(--surface-color); border: 1px solid var(--border-color); color: var(--text-primary); padding: 16px; border-radius: var(--radius); font-size: 16px; outline: none; box-sizing: border-box;}
input:focus { border-color: var(--accent-color); }

.primary-btn { width: 100%; background: var(--accent-color); color: var(--accent-text); padding: 16px; border-radius: var(--radius); font-size: 16px; font-weight: 600; border: none; cursor: pointer; }
.primary-btn.outline { background: transparent; border: 2px solid var(--accent-color); color: var(--accent-color); }
#create-result { margin-top: 20px; font-size: 14px; text-align: center; color: var(--text-secondary); line-height: 1.5; word-break: break-all; }
#create-result a { color: var(--text-primary); font-weight: 600; }

.chat-mode { padding-top: 50px; }
.chat-header { display: flex; justify-content: space-between; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--border-color); background: var(--bg-color); z-index: 10;}
.status-indicator { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-secondary); font-weight: 500;}
.dot { width: 8px; height: 8px; background-color: #34c759; border-radius: 50%; box-shadow: 0 0 8px rgba(52, 199, 89, 0.5); }
.danger-btn { background: transparent; color: var(--danger-color); font-size: 15px; font-weight: 600; cursor: pointer; border: none; padding: 8px 12px; border-radius: 8px;}
.danger-btn:hover { background: rgba(255, 59, 48, 0.1); }

#messages { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 16px; padding: 10px 15px; touch-action: pan-y; }

.msg { display: flex; flex-direction: column; max-width: 80%; align-self: flex-start; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.msg.self { align-self: flex-end; }
.msg-info { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.msg.self .msg-info { justify-content: flex-end; }
.msg-bubble { background: var(--surface-color); padding: 12px 16px; border-radius: 20px; border-top-left-radius: 4px; border: 1px solid var(--border-color); font-size: 16px; line-height: 1.4; word-break: break-word; }
.msg.self .msg-bubble { background: var(--msg-bubble-self); color: var(--msg-text-self); border-top-left-radius: 20px; border-top-right-radius: 4px; border: none; }

.revoke-btn-float { 
  display: none; align-self: flex-start; margin-bottom: 6px;
  background: var(--surface-color); color: var(--danger-color); border: 1px solid var(--border-color); 
  padding: 8px 18px; border-radius: 12px; font-size: 13px; font-weight: bold; box-shadow: 0 4px 10px rgba(0,0,0,0.1);
  white-space: nowrap; width: max-content; 
}
.msg.self .revoke-btn-float { align-self: flex-end; }
.msg.show-action .revoke-btn-float { display: block; animation: popUp 0.2s ease; }

.attach-menu { position: absolute; bottom: 85px; left: 15px; right: 15px; background: #1c1c1e; border-radius: 24px; padding: 25px 10px; display: none; justify-content: space-around; box-shadow: 0 10px 40px rgba(0,0,0,0.3); z-index: 100;}
.attach-menu.show { display: flex; animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
.menu-item { display: flex; flex-direction: column; align-items: center; gap: 10px; cursor: pointer; -webkit-tap-highlight-color: transparent;}
.menu-icon { width: 60px; height: 60px; background: #2c2c2e; border-radius: 18px; display: flex; align-items: center; justify-content: center; }
.menu-icon svg { width: 28px; height: 28px; stroke: #ffffff; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;}
.menu-item span { font-size: 13px; color: #8e8e93; font-weight: 500; }

.input-area { display: flex; gap: 10px; padding: 10px 15px; background: var(--surface-color); border-top: 1px solid var(--border-color); align-items: center; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
.input-area input { flex: 1; background: var(--bg-color); border: none; padding: 12px 16px; border-radius: 20px; outline: none; font-size: 15px;}
.input-area .icon-btn { width: 36px; height: 36px; }
.send-btn { background: var(--accent-color); color: var(--accent-text); width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; border: none; cursor: pointer;}
.mic-btn.recording { color: var(--danger-color); animation: pulse 1s infinite; }

#toast { position: fixed; top: -60px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.85); color: #fff; padding: 12px 24px; border-radius: 30px; font-size: 15px; font-weight: 500; z-index: 999999; transition: top 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55); backdrop-filter: blur(10px); text-align: center; white-space: nowrap; }
#toast.show { top: 40px; }
.sys-msg { align-self: center; font-size: 13px; color: var(--text-secondary); padding: 6px 14px; background: var(--surface-color); border: 1px solid var(--border-color); border-radius: 14px; margin: 10px 0; }

@keyframes popUp { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }
img, video { max-width: 100%; border-radius: 12px; margin-top: 5px; }
audio { max-width: 220px; }
.file-card { padding: 10px; background: rgba(128,128,128,0.1); border-radius: 8px; display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; font-size: 14px;}
