:root {
  --bg: #04030a;
  --ink: #f5f3ff;
  --mute: #9a95b3;
  --mute-2: #6f6a88;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(103, 232, 249, 0.28);
  --panel: rgba(12, 10, 24, 0.82);
  --panel-solid: #0c0a18;
  --panel-2: rgba(18, 15, 34, 0.94);
  --cyan: #67e8f9;
  --cyan-deep: #22d3ee;
  --accent-ink: #041018;
  --ok: #34d399;
  --danger: #f87171;
  --display: "Manrope", system-ui, sans-serif;
  --body: "Manrope", system-ui, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --radius: 14px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.is-booting .auth-screen,
body.is-booting .app-chrome {
  opacity: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
  background: none;
}

/* Author display rules must not override the hidden attribute. */
[hidden] {
  display: none !important;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

/* ── Atmosphere ─────────────────────────────────────────── */
.stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background: #04030a;
}

.stage-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 30%, #000 20%, transparent 75%);
  opacity: 0.55;
}

.stage-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(36px);
}

.stage-glow-a {
  width: min(58vw, 640px);
  height: min(58vw, 640px);
  top: -12%;
  left: 8%;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.22), transparent 70%);
  animation: drift-a 18s var(--ease) infinite alternate;
}

.stage-glow-b {
  width: min(48vw, 520px);
  height: min(48vw, 520px);
  bottom: -8%;
  right: -4%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.18), transparent 70%);
  animation: drift-b 22s var(--ease) infinite alternate;
}

.stage-wash {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(4, 3, 10, 0.15), rgba(4, 3, 10, 0.88));
}

@keyframes drift-a {
  from { transform: translate(0, 0); }
  to { transform: translate(4%, 6%); }
}

@keyframes drift-b {
  from { transform: translate(0, 0); }
  to { transform: translate(-5%, -4%); }
}

@keyframes auth-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, -12px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 420px);
  padding: 0.75rem 1.1rem;
  border-radius: 12px;
  background: rgba(40, 16, 20, 0.95);
  border: 1px solid rgba(248, 113, 113, 0.4);
  color: #fecaca;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.35s var(--ease);
  overflow-wrap: anywhere;
}

.toast.ok {
  background: rgba(10, 36, 28, 0.95);
  border-color: rgba(52, 211, 153, 0.4);
  color: #a7f3d0;
}

/* ── Auth screens ───────────────────────────────────────── */
.auth-screen {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(100%, 420px);
  padding: 2.25rem 1.85rem 1.85rem;
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(18, 15, 34, 0.96), rgba(8, 7, 18, 0.94));
  border: 1px solid rgba(255, 255, 255, 0.09);
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-enter {
  animation: auth-in 0.55s var(--ease) both;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.35rem;
}

.auth-brand img {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 0.35rem;
}

.auth-product {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.auth-product span {
  color: var(--cyan);
}

.auth-card h1 {
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(1.55rem, 4vw, 1.85rem);
  letter-spacing: -0.035em;
  margin-bottom: 0.55rem;
}

.auth-lead {
  color: var(--mute);
  margin-bottom: 1.5rem;
  line-height: 1.55;
}

.auth-foot {
  margin-top: 1.15rem;
  font-size: 0.78rem;
  color: var(--mute-2);
}

/* ── Buttons ────────────────────────────────────────────── */
.btn,
.btn-ghost {
  appearance: none;
  border-radius: 12px;
  padding: 0.7rem 1.05rem;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  transition: transform 0.15s var(--ease), background 0.15s ease, border-color 0.15s ease;
}

.btn {
  background: linear-gradient(180deg, var(--cyan), var(--cyan-deep));
  color: var(--accent-ink);
  border: 0;
  box-shadow: 0 8px 24px rgba(34, 211, 238, 0.22);
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-discord {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.03);
}

.btn-ghost.danger {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.28);
}

.btn-sm {
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
  border-radius: 10px;
  font-weight: 600;
}

.btn:disabled,
.btn-ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── App chrome ─────────────────────────────────────────── */
.app-chrome {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: fade-up 0.45s var(--ease) both;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem clamp(0.85rem, 2vw, 1.35rem);
  border-bottom: 1px solid var(--line);
  background: rgba(6, 5, 14, 0.78);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: inherit;
  text-decoration: none;
  justify-self: start;
}

.brand img {
  border-radius: 10px;
}

.brand-text {
  font-family: var(--display);
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand strong {
  color: var(--cyan);
  font-weight: 800;
}

.top-center {
  justify-self: center;
  font-size: 0.85rem;
  color: var(--mute);
  max-width: min(42vw, 320px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-end {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.user-chip {
  font-size: 0.82rem;
  color: var(--mute);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Mail layout ────────────────────────────────────────── */
.mail-app {
  flex: 1;
  display: grid;
  grid-template-columns: 15rem minmax(16rem, 22rem) minmax(0, 1fr);
  min-height: 0;
  height: calc(100vh - 57px);
  border-top: 0;
}

.mail-side,
.mail-list-pane,
.mail-reader {
  min-width: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.mail-reader {
  border-right: 0;
  background: rgba(8, 7, 16, 0.55);
}

.mail-side {
  padding: 0.9rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: auto;
}

.btn-compose {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.compose-plus {
  font-size: 1.15rem;
  line-height: 1;
  font-weight: 700;
}

.mail-side-head {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mute-2);
  margin-bottom: 0.4rem;
  font-weight: 700;
}

.mail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.mail-nav button {
  text-align: left;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  color: var(--ink);
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.mail-nav button .nav-sub {
  display: block;
  font-size: 0.72rem;
  color: var(--mute-2);
  margin-top: 0.1rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mail-nav button:hover {
  background: rgba(255, 255, 255, 0.04);
}

.mail-nav button.active {
  background: rgba(103, 232, 249, 0.12);
  box-shadow: inset 2px 0 0 var(--cyan);
}

/* List pane */
.mail-list-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mail-list-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.85rem 0.95rem;
  border-bottom: 1px solid var(--line);
}

.mail-list-head h2 {
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.list-count {
  margin-top: 0.15rem;
  font-size: 0.75rem;
  color: var(--mute-2);
}

.mail-list-actions {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.mail-list {
  overflow: auto;
  flex: 1;
}

.mail-row {
  width: 100%;
  text-align: left;
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: 0.55rem 0.65rem;
  align-items: start;
  padding: 0.8rem 0.95rem;
  border-bottom: 1px solid var(--line);
  transition: background 0.12s ease;
}

.mail-row:hover {
  background: rgba(255, 255, 255, 0.035);
}

.mail-row.active {
  background: rgba(103, 232, 249, 0.08);
}

.mail-row-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 0.35rem;
  background: transparent;
}

.mail-row.unread .mail-row-dot {
  background: var(--cyan);
  box-shadow: 0 0 0 3px rgba(103, 232, 249, 0.15);
}

.mail-row-main {
  min-width: 0;
}

.mail-row-from {
  font-size: 0.82rem;
  color: var(--mute);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-row.unread .mail-row-from {
  color: var(--ink);
  font-weight: 700;
}

.mail-row-sub {
  margin-top: 0.15rem;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-row.unread .mail-row-sub {
  font-weight: 700;
}

.mail-row-preview {
  margin-top: 0.2rem;
  font-size: 0.78rem;
  color: var(--mute-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-row-date {
  font-size: 0.72rem;
  color: var(--mute-2);
  white-space: nowrap;
  padding-top: 0.15rem;
}

.list-empty,
.list-loading,
.reader-empty {
  color: var(--mute);
  padding: 2.5rem 1.25rem;
  text-align: center;
}

.list-loading {
  font-size: 0.9rem;
}

.reader-empty {
  display: grid;
  place-content: center;
  gap: 0.35rem;
  min-height: 100%;
  animation: fade-up 0.5s var(--ease) both;
}

.reader-empty-mark {
  font-size: 2rem;
  opacity: 0.45;
  margin-bottom: 0.35rem;
}

.reader-empty p {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
}

.reader-empty span {
  font-size: 0.88rem;
  color: var(--mute-2);
  max-width: 22rem;
  margin: 0 auto;
}

/* Reader */
.mail-reader {
  padding: 1rem 1.15rem 1.5rem;
  overflow: auto;
  position: relative;
}

.reader-back {
  margin-bottom: 0.65rem;
}

.reader-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}

#msg-subject {
  font-family: var(--display);
  font-size: clamp(1.15rem, 2vw, 1.4rem);
  font-weight: 750;
  letter-spacing: -0.02em;
  margin-bottom: 0.55rem;
  overflow-wrap: anywhere;
  animation: fade-up 0.35s var(--ease) both;
}

.msg-meta {
  color: var(--mute);
  font-size: 0.85rem;
  margin-bottom: 1.15rem;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.msg-html {
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  color: #e8e4f5;
}

.msg-html img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.msg-html a {
  color: var(--cyan);
}

.msg-html pre {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
}

.msg-atts {
  margin-top: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

.msg-atts a {
  color: var(--cyan);
  text-decoration: none;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.msg-atts a:hover {
  text-decoration: underline;
}

/* Confirm modal */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}

.confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 2, 8, 0.72);
  backdrop-filter: blur(10px);
}

.confirm-card {
  position: relative;
  width: min(100%, 400px);
  padding: 1.55rem 1.45rem 1.35rem;
  border-radius: 18px;
  background: linear-gradient(165deg, rgba(22, 18, 40, 0.98), rgba(8, 7, 18, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow), 0 0 0 1px rgba(103, 232, 249, 0.06);
  animation: confirm-in 0.32s var(--ease) both;
}

@keyframes confirm-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.confirm-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cyan);
  font-weight: 700;
  margin-bottom: 0.55rem;
}

.confirm-card h2 {
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
  margin-bottom: 0.45rem;
}

.confirm-body {
  color: var(--mute);
  font-size: 0.95rem;
  line-height: 1.5;
  margin-bottom: 1.35rem;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.55rem;
}

.btn-danger {
  background: linear-gradient(180deg, #fb7185, #e11d48) !important;
  color: #fff !important;
  box-shadow: 0 8px 24px rgba(225, 29, 72, 0.28) !important;
}

.btn-danger:hover {
  transform: translateY(-1px);
}

/* Compose overlay */
.compose-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: end center;
  padding: 0;
}

.compose-overlay[hidden] {
  display: none !important;
}

.compose-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 3, 10, 0.62);
  backdrop-filter: blur(4px);
  animation: fade-up 0.25s ease both;
}

.compose-sheet {
  position: relative;
  width: min(100%, 640px);
  max-height: min(92vh, 760px);
  margin: 0 auto;
  padding: 1.15rem 1.25rem 1.25rem;
  border-radius: 18px 18px 0 0;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom: 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  animation: auth-in 0.4s var(--ease) both;
  overflow: auto;
}

.compose-sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.compose-sheet-head h2 {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 750;
}

.field {
  display: block;
}

.field span {
  display: block;
  margin-bottom: 0.28rem;
  color: var(--mute);
  font-size: 0.78rem;
  font-weight: 600;
}

.field input,
.field textarea {
  width: 100%;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.32);
  color: var(--ink);
  padding: 0.65rem 0.8rem;
  font: inherit;
}

.field textarea {
  resize: vertical;
  min-height: 180px;
}

.field-grow {
  flex: 1;
}

.compose-actions {
  display: flex;
  gap: 0.55rem;
  margin-top: 0.35rem;
}

/* Mobile */
@media (max-width: 960px) {
  .top {
    grid-template-columns: 1fr auto;
  }

  .top-center {
    display: none;
  }

  .brand-text {
    font-size: 0.95rem;
  }

  .mail-app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: calc(100vh - 57px);
  }

  .mail-side {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .mail-list-pane {
    max-height: none;
    border-right: 0;
  }

  .mail-app.show-reader .mail-side,
  .mail-app.show-reader .mail-list-pane {
    display: none;
  }

  .mail-app:not(.show-reader) .mail-reader {
    display: none;
  }

  .reader-back {
    display: inline-flex !important;
  }

  .compose-sheet {
    width: 100%;
    max-height: 94vh;
  }
}

@media (min-width: 961px) {
  .reader-back {
    display: none !important;
  }
}
