:root {
  --sky-top: #eaf6ff;
  --sky-mid: #cfe9fb;
  --sky-deep: #9ec9e8;
  --ink: #0f2740;
  --ink-soft: #3d5a73;
  --muted: #5f7a90;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-strong: rgba(255, 255, 255, 0.9);
  --line: rgba(15, 39, 64, 0.1);
  --accent: #0b6bcb;
  --accent-2: #084a8f;
  --accent-soft: rgba(11, 107, 203, 0.12);
  --live: #128a4c;
  --danger: #c23b3b;
  --shadow: 0 18px 50px rgba(15, 60, 100, 0.14);
  --radius: 22px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font-ui: "Sora", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-ui);
  background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 48%, var(--sky-deep) 100%);
  -webkit-font-smoothing: antialiased;
}

.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.haze {
  position: absolute;
  inset: auto 0 0;
  height: 40%;
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.35));
}

.cloud {
  position: absolute;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  filter: blur(2px);
  animation: drift 48s var(--ease) infinite alternate;
}
.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  border-radius: 999px;
  background: inherit;
}
.c1 { width: 220px; height: 70px; top: 12%; left: -40px; opacity: 0.7; }
.c1::before { width: 90px; height: 90px; top: -48px; left: 36px; }
.c1::after { width: 120px; height: 120px; top: -60px; left: 90px; }
.c2 { width: 280px; height: 80px; top: 28%; right: -60px; opacity: 0.55; animation-duration: 64s; animation-delay: -10s; }
.c2::before { width: 110px; height: 110px; top: -55px; left: 50px; }
.c2::after { width: 140px; height: 140px; top: -72px; left: 120px; }
.c3 { width: 180px; height: 56px; top: 58%; left: 18%; opacity: 0.4; animation-duration: 56s; animation-delay: -22s; }
.c3::before { width: 70px; height: 70px; top: -36px; left: 28px; }
.c3::after { width: 95px; height: 95px; top: -48px; left: 70px; }

@keyframes drift {
  from { transform: translateX(0); }
  to { transform: translateX(36px); }
}

.shell {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 calc(36px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 2px 22px;
  animation: rise 0.7s var(--ease) both;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: inherit;
}
.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px rgba(11, 107, 203, 0.28);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  color: #1a4f8c;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(18, 138, 76, 0.1);
  color: var(--live);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(18, 138, 76, 0.45);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(18, 138, 76, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(18, 138, 76, 0); }
  100% { box-shadow: 0 0 0 0 rgba(18, 138, 76, 0); }
}

.admin-link {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 10px;
}
.admin-link:hover { background: rgba(255, 255, 255, 0.45); color: var(--ink); }

.hero {
  animation: rise 0.85s var(--ease) 0.08s both;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.headline {
  margin: 0;
  display: grid;
  gap: 6px;
  line-height: 1.05;
}
.brand-hero {
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #0d4f94;
}
.headline-rest {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 4.8vw, 2.55rem);
  font-weight: 560;
  letter-spacing: -0.025em;
  color: var(--ink);
}

.lede {
  margin: 14px 0 0;
  max-width: 38rem;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.55;
}

.fetch-panel {
  margin-top: 28px;
  padding: 18px;
  border-radius: calc(var(--radius) + 4px);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
}

.fetch-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 760px) {
  .fetch-row {
    grid-template-columns: minmax(0, 1fr) 160px auto;
    align-items: stretch;
  }
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 14px;
  border-radius: 14px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}
.field:focus-within {
  border-color: rgba(11, 107, 203, 0.45);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.field-ico {
  color: var(--muted);
  font-weight: 700;
  flex: none;
}
.field-ico.lock {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
}
.field-ico.lock svg { width: 18px; height: 18px; }
.field input,
.field select {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 0.98rem;
  padding: 14px 0;
}
.field select { cursor: pointer; }
.code-field { margin-top: 10px; }

.btn-fetch {
  appearance: none;
  border: 0;
  border-radius: 14px;
  min-height: 52px;
  padding: 0 22px;
  background: linear-gradient(180deg, #1780e6, var(--accent-2));
  color: #fff;
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 12px 24px rgba(8, 74, 143, 0.28);
  transition: transform 0.2s var(--ease), filter 0.2s var(--ease);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.btn-fetch:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn-fetch:active { transform: translateY(0); }
.btn-fetch:disabled { opacity: 0.7; cursor: wait; transform: none; }
.btn-spin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  display: none;
  animation: spin 0.7s linear infinite;
}
.btn-fetch.is-loading .btn-spin { display: block; }
.btn-fetch.is-loading .btn-label { opacity: 0.85; }
@keyframes spin { to { transform: rotate(360deg); } }

.form-error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}

.results {
  margin-top: 28px;
  animation: rise 0.9s var(--ease) 0.16s both;
}
.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.results-head h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}
.count-chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 700;
}

.message-list { display: grid; gap: 10px; }

.empty-state {
  text-align: center;
  padding: 42px 20px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.42);
  border: 1px dashed rgba(15, 39, 64, 0.16);
}
.empty-ico {
  width: 48px;
  height: 48px;
  margin: 0 auto 10px;
  color: var(--accent);
  opacity: 0.85;
}
.empty-ico svg { width: 48px; height: 48px; }
.empty-state h3 { margin: 0 0 6px; font-family: var(--font-display); }
.empty-state p { margin: 0; color: var(--muted); }

.msg {
  display: grid;
  gap: 6px;
  padding: 16px 16px 14px;
  border-radius: 18px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(15, 60, 100, 0.08);
  cursor: pointer;
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease);
  animation: rise 0.55s var(--ease) both;
}
.msg:hover {
  transform: translateY(-2px);
  border-color: rgba(11, 107, 203, 0.28);
}
.msg-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}
.msg-from { font-weight: 700; color: var(--ink); }
.msg-time { color: var(--muted); font-size: 0.78rem; white-space: nowrap; }
.msg-subject { font-weight: 600; }
.msg-preview {
  color: var(--ink-soft);
  font-size: 0.92rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.msg-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.tag.unread { background: rgba(18, 138, 76, 0.12); color: var(--live); }
.tag.code { background: var(--accent-soft); color: var(--accent-2); font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }

.foot {
  margin-top: 36px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.82rem;
}
.foot a { color: var(--accent-2); font-weight: 600; text-decoration: none; }

.reader {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(10, 24, 40, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.reader.hidden { display: none; }
.reader-panel {
  width: min(720px, 100%);
  max-height: min(92dvh, 980px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #ffffff;
  border-radius: 22px;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.35);
  animation: rise 0.35s var(--ease) both;
  border: 1px solid rgba(255, 255, 255, 0.4);
}
.reader-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid #e8eef4;
  background: #fff;
  flex: none;
}
.reader-meta { min-width: 0; flex: 1; }
.reader-head h2 {
  margin: 4px 0 6px;
  font-family: var(--font-ui);
  font-size: clamp(1.15rem, 2.6vw, 1.45rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: #0f2740;
}
.reader-from {
  margin: 0;
  font-weight: 600;
  font-size: 0.88rem;
  color: #3d5a73;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-time {
  margin: 0;
  color: #7a92a8;
  font-size: 0.8rem;
}
.reader-close {
  appearance: none;
  border: 0;
  background: #f3f6fa;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  cursor: pointer;
  color: #5f7a90;
  flex: none;
  display: grid;
  place-items: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.reader-close svg { width: 18px; height: 18px; }
.reader-close:hover { background: #e8eef5; color: #0f2740; }
.reader-codes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 18px 0;
  flex: none;
}
.code-chip {
  appearance: none;
  border: 1px solid rgba(11, 107, 203, 0.22);
  padding: 10px 14px;
  border-radius: 12px;
  background: #edf6ff;
  color: var(--accent-2);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
  cursor: pointer;
}
.code-chip:hover { filter: brightness(0.98); }
.code-chip.copied {
  background: #e8f8ef;
  border-color: rgba(18, 138, 76, 0.28);
  color: #128a4c;
}
.reader-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #f5f7fa;
  padding: 14px 12px 18px;
}
.reader-body {
  margin: 0 auto;
  width: min(640px, 100%);
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 1px 0 rgba(15, 39, 64, 0.04), 0 10px 30px rgba(15, 39, 64, 0.06);
  overflow: hidden;
  color: #111;
  line-height: 1.55;
}
.reader-body.is-plain {
  padding: 28px 24px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.98rem;
}
.reader-body img { max-width: 100%; height: auto; }
.email-frame {
  display: block;
  width: 100%;
  min-height: 280px;
  border: 0;
  background: #fff;
}

@media (max-width: 640px) {
  .reader { place-items: end center; padding: 0; }
  .reader-panel {
    width: 100%;
    max-height: 94dvh;
    border-radius: 18px 18px 0 0;
  }
  .reader-stage { padding: 10px 8px 14px; }
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
