/* ————————————————————————————————
   moon mail — the envelope & the panel
   ———————————————————————————————— */

/* — the envelope, glowing when a letter waits — */

.scene-controls .mail-btn.mail-unread {
  color: var(--gold-soft);
  border-color: var(--gold);
  background: rgba(231, 201, 130, 0.14);
  animation: mailPulse 1.9s ease-in-out infinite;
}

@keyframes mailPulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(231, 201, 130, 0.0), 0 0 14px rgba(231, 201, 130, 0.45);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 10px rgba(231, 201, 130, 0.16), 0 0 34px rgba(242, 227, 184, 0.85);
    transform: scale(1.12);
  }
}

.scene-controls .mail-btn.mail-instant.mail-unread {
  animation: none;
  transform: none;
  box-shadow: 0 0 0 6px rgba(231, 201, 130, 0.16), 0 0 28px rgba(242, 227, 184, 0.7);
}

/* a gentler glow — someone reacted to a letter */

.scene-controls .mail-btn.mail-unread-gentle {
  color: var(--gold-dim);
  border-color: rgba(231, 201, 130, 0.5);
  background: rgba(231, 201, 130, 0.09);
  animation: mailPulseGentle 3.4s ease-in-out infinite;
}

@keyframes mailPulseGentle {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(231, 201, 130, 0.0), 0 0 8px rgba(231, 201, 130, 0.22);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(231, 201, 130, 0.08), 0 0 16px rgba(231, 201, 130, 0.4);
    transform: scale(1.04);
  }
}

.scene-controls .mail-btn.mail-instant.mail-unread-gentle {
  animation: none;
  transform: none;
  box-shadow: 0 0 0 3px rgba(231, 201, 130, 0.1), 0 0 14px rgba(231, 201, 130, 0.35);
}

/* read receipt under my last-seen note */
.mail-note .mail-seen {
  margin-top: 0.25rem;
  font-family: var(--font-utility);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(231, 201, 130, 0.65);
  text-align: right;
}

/* — the panel: a glassy night card, cousin of the gate — */

.mail-panel {
  position: fixed;
  top: 4.5rem;
  right: 1.1rem;
  z-index: 8;
  width: min(92vw, 22rem);
  max-height: 74vh;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(231, 201, 130, 0.22);
  border-radius: 1rem;
  background: linear-gradient(168deg, rgba(32, 43, 88, 0.55), rgba(14, 22, 49, 0.72));
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow:
    0 30px 80px rgba(3, 5, 16, 0.55),
    inset 0 1px 0 rgba(246, 241, 228, 0.08);
  animation: mailIn 0.35s ease both;
}

.mail-panel[hidden] { display: none; }

.mail-panel.mail-instant { animation: none; }

@keyframes mailIn {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* — header — */

.mail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.95rem 1.05rem 0.55rem;
}

.mail-eyebrow {
  font-family: var(--font-utility);
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--gold);
}

.mail-close {
  width: 1.9rem;
  height: 1.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  line-height: 1;
  color: var(--gold-dim);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.25s ease;
}

.mail-close:hover { color: var(--gold); }
.mail-close:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; }

.mail-head-btns {
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

/* — the bell: opt-in letter alerts — */

.mail-bell {
  width: 1.9rem;
  height: 1.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gold-dim);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.25s ease, background-color 0.25s ease;
}

.mail-bell:hover { color: var(--gold); }
.mail-bell:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 2px; }

.mail-bell.on {
  color: var(--gold);
  background: rgba(231, 201, 130, 0.14);
}

/* — the thread — */

.mail-thread {
  flex: 1 1 auto;
  min-height: 5.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.3rem 1.05rem 0.85rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(231, 201, 130, 0.25) transparent;
}

.mail-note {
  position: relative;
  max-width: 88%;
  align-self: flex-start;
  padding: 0.5rem 0.8rem 0.6rem;
  background: rgba(246, 241, 228, 0.045);
  border: 1px solid rgba(231, 201, 130, 0.10);
  border-radius: 0.75rem;
  border-bottom-left-radius: 0.25rem;
}

.mail-note.mine {
  align-self: flex-end;
  background: rgba(231, 201, 130, 0.075);
  border-color: rgba(231, 201, 130, 0.16);
  border-radius: 0.75rem;
  border-bottom-right-radius: 0.25rem;
}

.mail-meta {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
}

.mail-note.mine .mail-meta { justify-content: flex-end; }

.mail-who {
  font-family: var(--font-utility);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.mail-who[data-who="ushi"]   { color: var(--rose); }
.mail-who[data-who="piyush"] { color: var(--gold); }

.mail-time {
  font-family: var(--font-utility);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
  color: rgba(246, 241, 228, 0.38);
}

.mail-text {
  margin-top: 0.2rem;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1rem;
  line-height: 1.4;
  color: var(--moon);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

/* — quoted note above a reply — */

.mail-quote {
  margin-top: 0.3rem;
  padding: 0.12rem 0 0.12rem 0.55rem;
  border-left: 2px solid rgba(231, 201, 130, 0.55);
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
}

.mail-quote-who {
  font-family: var(--font-utility);
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: rgba(246, 241, 228, 0.5);
}

.mail-quote-who[data-who="ushi"]   { color: rgba(233, 173, 188, 0.75); }
.mail-quote-who[data-who="piyush"] { color: rgba(231, 201, 130, 0.75); }

.mail-quote-text {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 0.85rem;
  line-height: 1.35;
  color: rgba(246, 241, 228, 0.55);
  overflow-wrap: break-word;
}

/* — reaction badges on the note's corner — */

.mail-reacts {
  position: absolute;
  right: 0.55rem;
  bottom: -0.6rem;
  display: flex;
  gap: 0.25rem;
}

.mail-reacts[hidden] { display: none; }

.mail-note.mine .mail-reacts {
  right: auto;
  left: 0.55rem;
}

.mail-note:has(> .mail-reacts:not([hidden])) { margin-bottom: 0.45rem; }

.mail-react {
  padding: 0.06rem 0.34rem;
  font-size: 0.72rem;
  line-height: 1.3;
  border-radius: 999px;
  background: rgba(7, 11, 29, 0.92);
  border: 1px solid rgba(246, 241, 228, 0.2);
}

.mail-react[data-who="ushi"] {
  border-color: rgba(233, 173, 188, 0.6);
  box-shadow: 0 0 8px rgba(233, 173, 188, 0.18);
}

.mail-react[data-who="piyush"] {
  border-color: rgba(231, 201, 130, 0.6);
  box-shadow: 0 0 8px rgba(231, 201, 130, 0.18);
}

/* — the quiet action row: reply + the three little feelings — */

.mail-actions {
  position: absolute;
  top: -0.95rem;
  right: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.08rem 0.3rem;
  background: rgba(7, 11, 29, 0.95);
  border: 1px solid rgba(231, 201, 130, 0.28);
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(3, 5, 16, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 2;
}

.mail-note.mine .mail-actions {
  right: auto;
  left: 0.4rem;
}

.mail-note:hover .mail-actions,
.mail-note:focus-within .mail-actions,
.mail-note.mail-show-actions .mail-actions {
  opacity: 1;
  pointer-events: auto;
}

.mail-act {
  padding: 0.12rem 0.4rem;
  background: transparent;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.4;
  color: rgba(246, 241, 228, 0.6);
  transition: background-color 0.2s ease, color 0.2s ease;
}

.mail-act:hover { background: rgba(246, 241, 228, 0.07); color: var(--moon); }
.mail-act:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 1px; }

.mail-act-reply {
  font-family: var(--font-utility);
  font-size: 0.62rem;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-dim);
}

.mail-act-reply:hover { color: var(--gold); background: transparent; }

.mail-act-react.active {
  background: rgba(231, 201, 130, 0.16);
  box-shadow: inset 0 0 0 1px rgba(231, 201, 130, 0.4);
}

.mail-empty {
  margin: auto;
  padding: 1.1rem 0.5rem;
  text-align: center;
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1rem;
  color: var(--ink-dim);
}

/* — the composer — */

.mail-compose {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem 1.05rem 0.95rem;
  border-top: 1px solid rgba(231, 201, 130, 0.14);
}

/* — reply-in-progress chip above the composer — */

.mail-replychip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.28rem 0.3rem 0.28rem 0.6rem;
  border-left: 2px solid var(--gold);
  border-radius: 0.35rem;
  background: rgba(231, 201, 130, 0.07);
}

.mail-replychip[hidden] { display: none; }

.mail-replychip-text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font-utility);
  font-size: 0.74rem;
  letter-spacing: 0.03em;
  color: rgba(246, 241, 228, 0.72);
}

.mail-replychip-x {
  flex: 0 0 auto;
  width: 1.5rem;
  height: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  line-height: 1;
  color: var(--gold-dim);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.2s ease;
}

.mail-replychip-x:hover { color: var(--gold); }
.mail-replychip-x:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 1px; }

.mail-input {
  width: 100%;
  min-height: 2.7rem;
  max-height: 7.6rem; /* ~5 lines */
  padding: 0.7rem 0.95rem;
  font-family: var(--font-utility);
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--moon);
  background: rgba(7, 11, 29, 0.55);
  border: 1px solid rgba(231, 201, 130, 0.3);
  border-radius: 0.7rem;
  outline: none;
  resize: none;
  overflow-y: auto;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.mail-input::placeholder { color: rgba(246, 241, 228, 0.35); }

.mail-input:focus-visible {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(231, 201, 130, 0.18);
}

.mail-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.mail-hint {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-utility);
  font-size: 0.76rem;
  line-height: 1.3;
  color: rgba(233, 173, 188, 0.85);
}

.mail-count {
  font-family: var(--font-utility);
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  color: rgba(246, 241, 228, 0.38);
}

.mail-count.warn { color: var(--gold); }

.mail-send {
  padding: 0.55rem 1.15rem;
  font-family: var(--font-utility);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--night-900);
  background: linear-gradient(160deg, var(--gold-soft), var(--gold));
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.25s ease;
  box-shadow: 0 8px 22px rgba(231, 201, 130, 0.22);
}

.mail-send:hover { transform: translateY(-1px); box-shadow: 0 10px 26px rgba(231, 201, 130, 0.3); }
.mail-send:focus-visible { outline: 2px solid var(--gold-soft); outline-offset: 3px; }
.mail-send:active { transform: translateY(0); }

/* — reduced motion: everything instant — */

.mail-panel.mail-instant .mail-close,
.mail-panel.mail-instant .mail-input,
.mail-panel.mail-instant .mail-send,
.mail-panel.mail-instant .mail-bell,
.mail-panel.mail-instant .mail-act,
.mail-panel.mail-instant .mail-actions,
.mail-panel.mail-instant .mail-replychip-x {
  transition: none;
}

.mail-panel.mail-instant .mail-send:hover { transform: none; }

/* — bottom sheet under 560px — */

@media (max-width: 560px) {
  .mail-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 72vh;
    border-radius: 1rem 1rem 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .mail-panel { animation-name: mailInSheet; }
  .mail-panel.mail-instant { animation: none; }

  @keyframes mailInSheet {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
  }
}
