* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0e17;
  --panel: #1a1830;
  --panel-2: #221f3d;
  --accent: #6c5ce7;
  --accent-2: #8f7bff;
  --text: #e8e6f5;
  --muted: #8b87a8;
  --own: #4a3f8f;
  --other: #241f3d;
  --danger: #ff4d6d;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.panel {
  background: var(--panel);
  border-radius: 14px;
  padding: 28px 22px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

.panel h1 {
  font-size: 22px;
  text-align: center;
  letter-spacing: 0.5px;
  color: var(--accent-2);
  margin-bottom: 6px;
}

.panel h2 {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 6px;
}

.hint {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 8px;
}

input {
  background: var(--panel-2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  width: 100%;
  font-family: inherit;
}

input:focus { border-color: var(--accent); }

button {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 12px 16px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

button:active { background: var(--accent-2); }

button:disabled { opacity: 0.5; cursor: default; }

.msg {
  font-size: 13px;
  color: var(--danger);
  text-align: center;
  min-height: 16px;
}

#app-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#app-screen header {
  background: var(--panel);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  gap: 10px;
  flex-shrink: 0;
  min-height: 64px;
}

#header-user {
  font-weight: 700;
  color: var(--accent-2);
  font-size: 18px;
  letter-spacing: 0.3px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

#jump {
  width: 70px;
  padding: 8px 10px;
  font-size: 13px;
  text-align: center;
}

.header-actions button {
  padding: 8px 12px;
  font-size: 14px;
  min-width: 38px;
}

#refresh-btn,
#panic-btn {
  background: transparent;
  color: var(--text);
  width: 34px;
  height: 34px;
  padding: 0;
  font-size: 18px;
  font-weight: 700;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

#refresh-btn:active,
#panic-btn:active { background: rgba(255, 255, 255, 0.1); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg);
  position: relative;
}

.day-sep {
  align-self: center;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 5px 12px;
  border-radius: 10px;
  margin: 6px 0;
  text-transform: uppercase;
}

.bubble {
  max-width: 78%;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.15s;
  position: relative;
}

.bubble.own {
  align-self: flex-end;
  background: var(--own);
  border-bottom-right-radius: 4px;
}

.bubble.other {
  align-self: flex-start;
  background: var(--other);
  border-bottom-left-radius: 4px;
}

.bubble .num {
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
}

.bubble .num .ticks {
  color: var(--muted);
  font-size: 11px;
  margin-left: 3px;
  letter-spacing: -1px;
}

.bubble .num .ticks.both {
  color: var(--accent-2);
}

.bubble .txt {
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.5px;
  word-break: break-all;
}

.bubble .txt.revealed {
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  letter-spacing: normal;
  word-break: break-word;
}

.bubble .time {
  font-size: 10px;
  color: var(--muted);
  align-self: flex-end;
  margin-top: -2px;
}

.media-locked {
  background: rgba(0, 0, 0, 0.25);
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 14px 16px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  min-width: 140px;
}

.media-el {
  max-width: 240px;
  max-height: 240px;
  border-radius: 8px;
  display: block;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  pointer-events: none;
}

audio.media-el {
  width: 240px;
  height: 40px;
  pointer-events: auto;
}

#scroll-bottom {
  position: absolute;
  bottom: 84px;
  right: 18px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  z-index: 20;
}

#scroll-bottom:active { background: var(--accent); }

#composer {
  background: var(--panel);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

#attach-btn, #camera-btn, #mic-btn, #send-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  border-radius: 50%;
  padding: 0;
  font-size: 18px;
  background: var(--panel-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

#send-btn {
  background: var(--accent);
  color: #fff;
}

#send-btn:active { background: var(--accent-2); }

#compose {
  flex: 1;
  border-radius: 22px;
  padding: 12px 16px;
  background: var(--panel-2);
}

#attach-menu {
  position: fixed;
  bottom: 70px;
  left: 12px;
  background: var(--panel);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  z-index: 50;
}

#attach-menu button {
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 500;
  font-size: 14px;
}

#attach-menu button:active { background: var(--panel-2); }

#record-bar {
  position: fixed;
  bottom: 70px;
  left: 12px;
  right: 12px;
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  z-index: 60;
}

#record-time {
  flex: 1;
  font-size: 15px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

#record-cancel, #record-stop {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  padding: 0;
  background: var(--panel-2);
  color: var(--text);
}

#record-stop { background: var(--danger); color: #fff; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-box {
  background: var(--panel);
  border-radius: 14px;
  padding: 22px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-box h3 {
  font-size: 16px;
  color: var(--accent-2);
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.modal-actions button { flex: 1; }

#unlock-cancel { background: var(--panel-2); color: var(--muted); }

.camera-box {
  background: var(--panel);
  border-radius: 14px;
  padding: 14px;
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#camera-video {
  width: 100%;
  border-radius: 10px;
  background: #000;
  max-height: 60vh;
  object-fit: cover;
}

.camera-actions {
  display: flex;
  gap: 8px;
}

.camera-actions button { flex: 1; }

#camera-cancel { background: var(--panel-2); color: var(--muted); }

#camera-flip {
  background: var(--panel-2);
  color: var(--text);
  flex: 0 0 60px;
}

@media (max-width: 480px) {
  .bubble { max-width: 85%; }
  .panel { padding: 22px 18px; }
  .media-el { max-width: 200px; max-height: 200px; }
  audio.media-el { width: 200px; }
  .header-actions button { padding: 6px 10px; }
}