:root{
  --dusk-deep:   #150f24;
  --dusk-violet: #2a1c47;
  --plum-glass:  rgba(58, 41, 89, 0.55);
  --ember:       #e8825a;
  --ember-soft:  #f0a679;
  --mist:        #d9d3ec;
  --starlight:   #f5f2fb;
  --muted:       #9c8fbb;

  --font-display: 'Fraunces', serif;
  --font-body: 'Inter', sans-serif;
}

*{ box-sizing: border-box; }
html,body{
  margin:0; padding:0; height:100%;
  background: var(--dusk-deep);
  color: var(--starlight);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#stars{
  position: fixed; inset: 0; z-index: 0;
  background: radial-gradient(ellipse at 30% 0%, #2f2050 0%, #150f24 65%);
}

.screen{
  position: relative; z-index: 1;
  height: 100dvh; width: 100%;
  display: flex; flex-direction: column;
}
.hidden{ display:none !important; }

/* ---------- LOCK SCREEN ---------- */
#lockScreen{ align-items: center; justify-content: center; padding: 24px; }
.lock-card{
  width: 100%; max-width: 360px;
  background: var(--plum-glass);
  backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px;
  padding: 32px 26px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.lock-glyph{ font-size: 22px; color: var(--ember-soft); margin-bottom: 6px; }
.brand{
  font-family: var(--font-display);
  font-weight: 600; font-style: italic;
  font-size: 34px; margin: 0 0 4px;
  letter-spacing: 0.5px;
}
.tagline{ color: var(--muted); font-size: 13.5px; margin: 0 0 26px; }

.field{ text-align: left; margin-bottom: 18px; }
.field label{ display:block; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }

.who-toggle{ display:flex; gap: 8px; }
.who-btn{
  flex: 1; padding: 11px 8px;
  border-radius: 12px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04); color: var(--starlight);
  font-family: var(--font-body); font-weight: 600; font-size: 13.5px;
  cursor: pointer; transition: all .15s ease;
}
.who-btn.active{
  background: linear-gradient(135deg, var(--ember), #c9613c);
  border-color: transparent; color: #fff;
}

#pinInput{
  width: 100%; padding: 12px 14px;
  border-radius: 12px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.04); color: var(--starlight);
  font-size: 16px; letter-spacing: 3px; text-align: center;
  font-family: var(--font-body);
}
#pinInput:focus{ outline: none; border-color: var(--ember-soft); }

.primary-btn{
  width: 100%; padding: 13px;
  border-radius: 12px; border: none;
  background: linear-gradient(135deg, var(--ember), #c9613c);
  color: #fff; font-weight: 700; font-size: 15px;
  cursor: pointer; transition: opacity .15s ease;
}
.primary-btn:disabled{ opacity: 0.4; cursor: not-allowed; }
.lock-error{ color: #ff8484; font-size: 12.5px; min-height: 18px; margin-top: 12px; }

/* ---------- CHAT HEADER ---------- */
.chat-header{
  display:flex; align-items:center; justify-content: space-between;
  padding: 14px 16px;
  background: rgba(21,15,36,0.75);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.partner-block{ display:flex; align-items:center; gap: 11px; }
.avatar{
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--ember), #8a5cb8);
  display:flex; align-items:center; justify-content:center;
  font-weight: 700; font-size: 16px; color: #fff;
  background-size: cover; background-position: center;
  flex-shrink: 0;
}
.partner-name{ font-weight: 700; font-size: 15.5px; }
.partner-status{ font-size: 12px; color: var(--muted); margin-top: 1px; }
.partner-status.online{ color: #7be0a5; }
.icon-btn{
  background: none; border: none; color: var(--mist);
  font-size: 19px; cursor: pointer; padding: 6px; line-height: 1;
}

/* ---------- MESSAGES ---------- */
.messages{
  flex: 1; overflow-y: auto;
  padding: 16px 12px 6px;
  display:flex; flex-direction: column; gap: 3px;
}
.msg-row{ display:flex; max-width: 100%; }
.msg-row.mine{ justify-content: flex-end; }
.msg-row.theirs{ justify-content: flex-start; }

.bubble{
  max-width: 74%;
  padding: 9px 13px;
  border-radius: 19px;
  font-size: 14.5px; line-height: 1.42;
  position: relative;
  word-wrap: break-word; white-space: pre-wrap;
  margin: 2px 0;
}
.mine .bubble{
  background: linear-gradient(135deg, var(--ember), #c9613c);
  color: #fff; border-bottom-right-radius: 5px;
}
.theirs .bubble{
  background: rgba(255,255,255,0.08);
  color: var(--starlight);
  border-bottom-left-radius: 5px;
}
.bubble.media{ padding: 4px; }
.bubble img, .bubble video{
  max-width: 100%; border-radius: 15px; display:block; max-height: 320px; cursor: pointer;
}
.meta-row{
  display:flex; align-items:center; gap: 5px;
  font-size: 10.5px; color: var(--muted); margin: 2px 4px 6px;
}
.mine .meta-row{ justify-content: flex-end; }
.edited-tag{ font-style: italic; opacity: 0.8; }

.msg-actions{
  display:flex; gap: 10px; margin: 0 4px 4px;
  font-size: 11px; opacity: 0; transition: opacity .12s ease;
}
.mine .msg-actions{ justify-content: flex-end; }
.msg-row:hover .msg-actions, .msg-row.show-actions .msg-actions{ opacity: 1; }
.msg-actions button{
  background:none; border:none; color: var(--muted);
  font-size: 11.5px; cursor: pointer; font-family: var(--font-body);
}
.msg-actions button:hover{ color: var(--ember-soft); }

.day-divider{
  text-align:center; font-size: 11.5px; color: var(--muted);
  margin: 14px 0 8px;
}

/* ---------- TYPING ---------- */
.typing-row{ padding: 0 18px 6px; font-size: 12.5px; color: var(--muted); font-style: italic; flex-shrink:0; }

/* ---------- EDIT BANNER ---------- */
.edit-banner{
  display:flex; align-items:center; justify-content: space-between;
  padding: 8px 16px; font-size: 12.5px;
  background: rgba(232,130,90,0.15); color: var(--ember-soft);
  flex-shrink: 0;
}
.edit-banner button{
  background:none; border:none; color: var(--ember-soft); font-weight:700; cursor:pointer; font-family: var(--font-body);
}

/* ---------- COMPOSER ---------- */
.composer{
  display:flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(21,15,36,0.85);
  backdrop-filter: blur(14px);
  border-top: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}
.input-wrap{ flex: 1; }
#textInput{
  width: 100%; resize: none; max-height: 110px;
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px; padding: 10px 15px;
  color: var(--starlight); font-family: var(--font-body); font-size: 14.5px;
}
#textInput:focus{ outline:none; border-color: var(--ember-soft); }
.send-btn{
  width: 40px; height: 40px; border-radius: 50%; border:none; flex-shrink:0;
  background: linear-gradient(135deg, var(--ember), #c9613c);
  color:#fff; font-size: 16px; cursor:pointer;
}
.send-btn:disabled{ opacity: 0.4; }

/* ---------- UPLOAD PROGRESS ---------- */
.upload-progress{
  padding: 8px 16px; flex-shrink: 0;
  display:flex; align-items:center; gap: 10px;
  font-size: 11.5px; color: var(--muted);
}
.upload-bar{ flex:1; height:4px; background: rgba(255,255,255,0.1); border-radius: 4px; overflow:hidden; }
.upload-fill{ height:100%; width:0%; background: var(--ember); transition: width .2s ease; }

/* ---------- LIGHTBOX ---------- */
.lightbox{
  position: fixed; inset:0; z-index: 50;
  background: rgba(10,7,18,0.95);
  display:flex; align-items:center; justify-content:center;
}
.lightbox-close{ position:absolute; top:16px; right:16px; font-size:22px; }
.lightbox-content img, .lightbox-content video{ max-width: 92vw; max-height: 88vh; border-radius: 10px; }

/* Scrollbar */
.messages::-webkit-scrollbar{ width: 4px; }
.messages::-webkit-scrollbar-thumb{ background: rgba(255,255,255,0.15); border-radius: 4px; }
