:root {
  --primary: #1b3a6b;
  --primary-dark: #122a4d;
  --primary-light: #2d5b9e;
  --accent: #f5c518;
  --accent-dark: #d9a800;
  --green: #198754;
  --red: #b02a37;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 4px 16px rgba(27, 58, 107, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  line-height: 1.6;
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; }

/* Topbar */
.topbar { background: var(--primary); color: #fff; border-bottom: 4px solid var(--accent); }
.topbar-inner { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  background: var(--primary-dark); border-radius: 50%;
  width: 56px; height: 56px; display: grid; place-items: center;
  border: 2px solid var(--accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-family: 'Merriweather', serif; font-weight: 900; font-size: 17px; letter-spacing: 0.5px; }
.brand-sub { font-size: 12px; color: rgba(255,255,255,0.8); }
.nav { display: flex; gap: 22px; }
.nav a {
  color: #fff; text-decoration: none; font-size: 14px; font-weight: 500;
  opacity: 0.9; border-bottom: 2px solid transparent; padding-bottom: 2px;
  transition: opacity .15s, border-color .15s;
}
.nav a:hover { opacity: 1; border-bottom-color: var(--accent); }

/* Hero */
.hero {
  background:
    linear-gradient(135deg, rgba(27,58,107,0.92), rgba(45,91,158,0.92)),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'><path d='M0 30 L30 0 L60 30 L30 60 Z' fill='none' stroke='white' stroke-opacity='0.06' stroke-width='1'/></svg>");
  color: #fff; padding: 56px 0 64px; text-align: center;
}
.hero h1 { font-family: 'Merriweather', serif; font-size: clamp(28px, 4vw, 44px); margin: 0 0 10px; font-weight: 900; }
.hero .tagline { margin: 0 0 16px; font-size: 17px; }
.hero .desc { max-width: 640px; margin: 0 auto; color: rgba(255,255,255,0.9); }
.hero b { color: var(--accent); }

/* Status banner */
.status-banner {
  margin: -36px 0 24px;
  padding: 14px 18px;
  border-radius: 10px;
  font-size: 14px;
  position: relative;
  z-index: 3;
  box-shadow: var(--shadow);
  border: 1px solid;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.status-banner.hidden { display: none; }
.status-banner.locked { background: #fff8e1; border-color: #ffe082; color: #8a6d00; }
.status-banner.dev { background: #e7f3ff; border-color: #b6daff; color: #084298; }
.status-banner.open { background: #d1e7dd; border-color: #a3cfbb; color: var(--green); }
.status-banner b { font-weight: 700; }
.countdown {
  display: inline-flex; gap: 6px; margin-left: auto;
  font-family: 'Merriweather', serif; font-weight: 700;
}
.countdown span {
  background: rgba(0,0,0,0.06);
  padding: 4px 10px; border-radius: 6px;
  min-width: 42px; text-align: center;
}

/* Main */
.main { margin-top: -36px; padding-bottom: 60px; position: relative; z-index: 2; }
.status-banner + #cek { margin-top: 0; }

.card { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 32px; border: 1px solid var(--border); }
.card-title { font-family: 'Merriweather', serif; font-size: 22px; color: var(--primary); margin: 0 0 6px; }
.card-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.form-card { max-width: 640px; margin: 0 auto; }

.label { display: block; font-weight: 600; color: var(--primary); font-size: 14px; margin-bottom: 8px; }
.req { color: var(--red); }
#nisn {
  width: 100%; padding: 14px 16px; font-size: 18px;
  font-family: 'Poppins', sans-serif; letter-spacing: 2px;
  border: 1.5px solid var(--border); border-radius: 8px; outline: none;
  transition: border-color .15s, box-shadow .15s; background: #fff;
}
#nisn:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(27,58,107,0.12); }
#nisn:disabled { background: #f1f3f5; cursor: not-allowed; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 18px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 14px 20px; font-size: 15px; font-weight: 600;
  font-family: 'Poppins', sans-serif; color: #fff; background: var(--primary);
  border: none; border-radius: 8px; cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:hover:not(:disabled) { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
  background: #fff; color: var(--primary); border: 1.5px solid var(--primary);
}
.btn-secondary:hover:not(:disabled) { background: var(--primary); color: #fff; }

.alert { margin-top: 18px; padding: 12px 14px; border-radius: 8px; font-size: 14px; border: 1px solid; }
.alert.error { background: #fdecea; color: #b02a37; border-color: #f5c2c7; }
.alert.hidden { display: none; }

/* Info grid */
.info-grid { margin-top: 40px; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 20px; }
.info-card {
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; text-align: center; transition: transform .2s, box-shadow .2s;
}
.info-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.info-icon {
  width: 56px; height: 56px; border-radius: 50%;
  background: rgba(27,58,107,0.08); color: var(--primary);
  display: grid; place-items: center; margin: 0 auto 12px;
}
.info-card h3 { margin: 6px 0; font-family: 'Merriweather', serif; font-size: 16px; color: var(--primary); }
.info-card p { margin: 0; color: var(--muted); font-size: 14px; }

/* Footer */
.footer { background: var(--primary-dark); color: rgba(255,255,255,0.85); padding: 28px 0; border-top: 4px solid var(--accent); }
.footer-inner { text-align: center; }
.footer p { margin: 4px 0; font-size: 14px; }
.footer .copy { margin-top: 10px; color: rgba(255,255,255,0.6); font-size: 13px; }

/* ===== Loading Overlay + Envelope Animation ===== */
.overlay {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center;
}
.overlay.hidden { display: none; }
.overlay-backdrop {
  position: absolute; inset: 0;
  background: rgba(18,42,77,0.85);
  backdrop-filter: blur(4px);
}
.overlay-content {
  position: relative;
  display: flex; flex-direction: column; align-items: center;
  gap: 30px;
  padding: 20px;
}

.envelope-stage {
  perspective: 1000px;
  width: 320px; height: 220px;
  position: relative;
}

.envelope {
  position: absolute; inset: 0;
  transition: transform 1s cubic-bezier(.4,.2,.2,1);
}
.envelope.lift { transform: translateY(-40px); }

/* Envelope back (the body) */
.env-back {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #d9a800, #f5c518);
  border-radius: 6px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}

/* Letter inside */
.letter {
  position: absolute;
  left: 14px; right: 14px; top: 14px; bottom: 14px;
  background: #fffdf7;
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  padding: 14px;
  transition: transform 1.2s cubic-bezier(.4,.2,.2,1), opacity .4s;
  transform-origin: bottom center;
  z-index: 1;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.letter.rise { transform: translateY(-120px) scale(1.05); }

.letter-header { text-align: center; border-bottom: 2px solid var(--primary); padding-bottom: 6px; margin-bottom: 8px; }
.letter-logo { display: flex; justify-content: center; }
.letter-title { font-family: 'Merriweather', serif; font-weight: 900; font-size: 10px; color: var(--primary); letter-spacing: 1px; margin-top: 2px; }
.letter-sub { font-size: 8px; color: var(--muted); }
.letter-body { flex: 1; position: relative; padding-top: 6px; }
.letter-body .line {
  height: 4px; background: #d6dbe3; border-radius: 2px;
  margin-bottom: 6px; opacity: 0; transform: translateX(-10px);
  animation: lineIn .4s forwards;
}
.letter-body .line.short { width: 60%; }
.letter.rise .letter-body .line:nth-child(1) { animation-delay: .2s; }
.letter.rise .letter-body .line:nth-child(2) { animation-delay: .35s; }
.letter.rise .letter-body .line:nth-child(3) { animation-delay: .5s; }
.letter.rise .letter-body .line:nth-child(4) { animation-delay: .65s; }
.letter.rise .letter-body .line:nth-child(5) { animation-delay: .8s; }
@keyframes lineIn { to { opacity: 1; transform: none; } }

.seal {
  position: absolute; right: 4px; bottom: 0;
  opacity: 0; transform: scale(0) rotate(-30deg);
}
.letter.rise .seal { animation: sealIn .5s .9s forwards cubic-bezier(.3,1.5,.4,1); }
@keyframes sealIn { to { opacity: 1; transform: scale(1) rotate(-10deg); } }

/* Envelope front (cover the lower part of letter) */
.env-front {
  position: absolute; inset: 0;
  background: linear-gradient(135deg, #f5c518, #d9a800);
  border-radius: 6px;
  clip-path: polygon(0 45%, 50% 100%, 100% 45%, 100% 100%, 0 100%);
  z-index: 2;
  box-shadow: inset 0 4px 10px rgba(0,0,0,0.1);
}

/* Envelope flap (top triangle, opens up) */
.env-flap {
  position: absolute; left: 0; right: 0; top: 0;
  height: 60%;
  background: linear-gradient(135deg, #f5c518, #c89500);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transform: rotateX(0deg);
  transition: transform 0.9s cubic-bezier(.4,.2,.2,1);
  z-index: 3;
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.envelope.open .env-flap { transform: rotateX(180deg); z-index: 0; }

/* Overlay status text */
.overlay-status { text-align: center; color: #fff; min-width: 280px; }
.status-text {
  font-family: 'Merriweather', serif;
  font-size: 18px; margin: 0 0 14px;
  min-height: 24px;
}
.progress {
  width: 280px; height: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 4px; overflow: hidden;
  margin: 0 auto;
}
.progress-bar {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), #fff);
  transition: width .4s ease;
  border-radius: 4px;
}

/* ===== Modal ===== */
.modal { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 20px; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); animation: fade .2s ease; }
.modal-content {
  position: relative; background: #fff; border-radius: 12px;
  max-width: 560px; width: 100%; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: pop .35s ease; border-top: 6px solid var(--primary);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
.modal-close {
  position: absolute; top: 8px; right: 14px; background: transparent;
  border: none; font-size: 28px; cursor: pointer; color: var(--muted); line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* Result */
.result-box { padding: 32px 28px; text-align: center; }
.status-badge {
  display: inline-block; padding: 8px 22px; border-radius: 999px;
  font-weight: 700; font-size: 14px; letter-spacing: 1px;
  margin-bottom: 16px; text-transform: uppercase;
}
.status-badge.lulus { background: #d1e7dd; color: var(--green); border: 1.5px solid var(--green); }
.status-badge.tidak { background: #f8d7da; color: var(--red); border: 1.5px solid var(--red); }
.status-badge.error { background: #e9ecef; color: var(--muted); border: 1.5px solid #ced4da; }
.status-badge.info-badge { background: #fff3cd; color: #8a6d00; border: 1.5px solid #ffe082; }

.result-box h2 { font-family: 'Merriweather', serif; font-size: 22px; color: var(--text); margin: 4px 0; }
.result-box .siswa-name { color: var(--primary); font-size: 26px; }

.result-detail {
  margin: 22px 0 6px; border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden; text-align: left;
}
.result-detail .row { display: grid; grid-template-columns: 140px 1fr; padding: 12px 16px; font-size: 14px; }
.result-detail .row:nth-child(odd) { background: #f8fafc; }
.result-detail .k { color: var(--muted); font-weight: 500; }
.result-detail .v { color: var(--text); font-weight: 600; }

.result-message { margin-top: 16px; font-size: 14px; color: var(--muted); line-height: 1.7; }
.result-message b.lulus { color: var(--green); }
.result-message b.tidak { color: var(--red); }

.result-actions {
  margin-top: 22px;
  display: flex; gap: 10px; flex-wrap: wrap; justify-content: center;
}
.result-actions .btn { width: auto; padding: 12px 20px; }

@media (max-width: 640px) {
  .topbar-inner { flex-direction: column; gap: 12px; padding: 14px; }
  .brand-text { text-align: center; }
  .nav { gap: 16px; }
  .card { padding: 22px; }
  .result-detail .row { grid-template-columns: 110px 1fr; }
  .hero { padding: 40px 0 50px; }
  .envelope-stage { width: 280px; height: 190px; }
  .countdown { margin-left: 0; width: 100%; justify-content: center; }
}
