:root {
  --bg: #e7efe9;
  --ink: #132019;
  --muted: #5d7266;
  --panel: rgba(255, 252, 247, 0.82);
  --panel-solid: #fffdf9;
  --line: rgba(19, 32, 25, 0.12);
  --accent: #0f7a55;
  --accent-2: #1c4d6e;
  --danger: #b42318;
  --code: #0b3d2c;
  --shadow: 0 28px 60px rgba(19, 32, 25, 0.12);
  --radius: 22px;
  --font-display: "Fraunces", "Times New Roman", serif;
  --font-body: "Sora", "Trebuchet MS", sans-serif;
  color-scheme: light;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--bg);
}

body {
  position: relative;
  overflow-x: hidden;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(160deg, #eef5f0 0%, #e7efe9 42%, #dce8e1 100%);
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.55;
  animation: drift 18s ease-in-out infinite alternate;
}

.orb-a {
  width: min(56vw, 520px);
  height: min(56vw, 520px);
  left: -12%;
  top: -18%;
  background: radial-gradient(circle, #9fd9bf 0%, transparent 70%);
}

.orb-b {
  width: min(48vw, 460px);
  height: min(48vw, 460px);
  right: -10%;
  bottom: 8%;
  background: radial-gradient(circle, #9bb8d4 0%, transparent 72%);
  animation-delay: -6s;
  animation-duration: 22s;
}

.grain {
  position: absolute;
  inset: 0;
  opacity: 0.18;
  background-image: radial-gradient(rgba(19, 32, 25, 0.35) 0.7px, transparent 0.8px);
  background-size: 3px 3px;
  mix-blend-mode: multiply;
}

@keyframes drift {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to { transform: translate3d(4%, 6%, 0) scale(1.08); }
}

#app {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 64px;
}

.brand {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
}

.brand.compact { margin-bottom: 4px; }

.display {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.display.small {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  word-break: break-word;
}

.lead {
  margin: 0 0 28px;
  max-width: 34rem;
  color: var(--muted);
  line-height: 1.55;
  font-size: 1.02rem;
}

.lead.tight { margin-bottom: 0; font-size: 0.95rem; }

.stage-gate {
  min-height: calc(100vh - 72px);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stage-gate.is-visible {
  animation: rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.stage-gate.is-leaving {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  width: 100%;
  z-index: 6;
  pointer-events: none;
  animation: gateOut 0.34s ease forwards !important;
}

@keyframes gateOut {
  from { opacity: 1; transform: translateY(0) scale(1); filter: blur(0); }
  to { opacity: 0; transform: translateY(-40px) scale(0.97); filter: blur(5px); }
}

.stage-gate.is-entering {
  animation: rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.gate-card {
  width: min(440px, 100%);
  padding: 22px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.field {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 500;
}

input {
  width: 100%;
  padding: 13px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus {
  outline: none;
  border-color: color-mix(in srgb, var(--accent) 55%, white);
  box-shadow: 0 0 0 4px rgba(15, 122, 85, 0.14);
  transform: translateY(-1px);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.btn:active { transform: scale(0.97); }

.btn.primary {
  width: 100%;
  margin-top: 4px;
  background: linear-gradient(135deg, var(--accent) 0%, #146b8a 100%);
  color: #f4fffa;
  box-shadow: 0 14px 30px rgba(15, 122, 85, 0.28);
}

.btn.primary:hover { box-shadow: 0 18px 34px rgba(15, 122, 85, 0.34); }

.btn.ghost {
  background: rgba(255, 253, 249, 0.7);
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.ghost:hover { background: #fff; }

.btn.loading .btn-label { opacity: 0.35; }
.btn.loading .btn-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.btn-spinner { width: 0; height: 0; }

@keyframes spin { to { transform: rotate(360deg); } }

.error {
  margin: 12px 0 0;
  color: var(--danger);
  font-size: 0.92rem;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.stage-desk {
  animation: none;
  opacity: 1;
  transform: none;
  transition: opacity 0.28s ease, transform 0.28s ease;
}

.stage-desk.is-entering {
  animation: riseDesk 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.stage-desk.is-leaving {
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
}

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

.skeleton-stack {
  display: grid;
  gap: 12px;
  padding: 4px 0;
}

.skeleton {
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(19,32,25,0.06), rgba(19,32,25,0.12), rgba(19,32,25,0.06));
  background-size: 200% 100%;
  animation: shimmer 1.1s ease-in-out infinite;
}

.skeleton.code { height: 118px; }
.skeleton.line { height: 42px; }
.skeleton.w70 { width: 70%; }
.skeleton.w50 { width: 50%; }

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

.inbox.is-refresh .code-card,
.inbox.is-refresh .msg {
  animation: none !important;
}

.inbox.is-fresh-load .code-card,
.inbox.is-fresh-load .msg {
  animation: pop 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
}

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.icon-refresh {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
}

#refresh.is-busy .icon-refresh {
  animation: spin 0.7s linear infinite;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.live span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(15, 122, 85, 0.45);
  animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(15, 122, 85, 0.45); }
  70% { box-shadow: 0 0 0 10px rgba(15, 122, 85, 0); }
  100% { box-shadow: 0 0 0 0 rgba(15, 122, 85, 0); }
}

.inbox {
  padding: 22px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  min-height: 280px;
}

.muted-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 1.05rem;
}

.code-card {
  margin: 0 0 16px;
  padding: 18px;
  border-radius: 18px;
  background: linear-gradient(145deg, #e8f7ef, #f7fffb);
  border: 1px solid rgba(15, 122, 85, 0.18);
  animation: pop 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.code-card.link {
  background: linear-gradient(145deg, #e8f1f7, #f7fbff);
  border-color: rgba(28, 77, 110, 0.18);
}

.code-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.code-value {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: clamp(2rem, 5vw, 2.6rem);
  letter-spacing: 0.12em;
  color: var(--code);
  word-break: break-all;
}

.code-value.link {
  font-family: var(--font-body);
  font-size: 1rem;
  letter-spacing: 0;
  line-height: 1.45;
}

.section-title {
  margin: 22px 0 10px;
  font-family: var(--font-display);
  font-size: 1.35rem;
}

.msg {
  padding: 14px 0;
  border-top: 1px solid var(--line);
  animation: rise 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.msg:nth-child(1) { animation-delay: 0.02s; }
.msg:nth-child(2) { animation-delay: 0.06s; }
.msg:nth-child(3) { animation-delay: 0.1s; }
.msg:nth-child(4) { animation-delay: 0.14s; }
.msg:nth-child(5) { animation-delay: 0.18s; }

.msg strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1.02rem;
}

.msg .meta {
  color: var(--muted);
  font-size: 0.86rem;
  margin-bottom: 8px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(19, 32, 25, 0.04);
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.chip .btn {
  padding: 6px 10px;
  font-size: 0.78rem;
  border-radius: 10px;
}

.copied {
  animation: flash 0.55s ease;
}

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

@keyframes pop {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes flash {
  0% { background: rgba(15, 122, 85, 0.18); }
  100% { background: transparent; }
}

@media (max-width: 720px) {
  #app { width: min(100% - 24px, 920px); padding-top: 24px; }
  .top { flex-direction: column; }
  .gate-card { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .atmosphere .orb,
  .skeleton,
  .live span,
  .btn.loading .btn-spinner,
  #refresh.is-busy .icon-refresh {
    animation: none !important;
  }
  .stage-gate.is-leaving,
  .stage-desk.is-entering,
  .stage-desk.is-leaving,
  .stage-gate.is-visible,
  .stage-gate.is-entering {
    animation-duration: 0.01ms !important;
  }
}
