@import url('https://fonts.googleapis.com/css2?family=Kiwi+Maru:wght@500&family=Yusei+Magic&display=swap');

:root {
  --pink: #ec4899;
  --purple: #8b5cf6;
  --yellow: #f59e0b;
  --green: #10b981;
  --slate: #0f172a;
}

* {
  box-sizing: border-box;
}

body {
  font-family: 'Kiwi Maru', serif;
  background:
    radial-gradient(circle at top left, rgba(236,72,153,.18), transparent 34%),
    radial-gradient(circle at top right, rgba(245,158,11,.20), transparent 32%),
    linear-gradient(135deg, #fff8e7, #ffe7f3);
  min-height: 100vh;
}

.font-title,
h1,
h2,
h3 {
  font-family: 'Yusei Magic', sans-serif;
}

/* Header */

.festival-header {
  background: linear-gradient(90deg, var(--pink), var(--purple), var(--yellow));
  color: white;
  padding: 1rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-icon {
  background: white;
  color: var(--pink);
  padding: .65rem;
  border-radius: 999px;
  box-shadow: 0 8px 18px rgba(0,0,0,.18);
  animation: floatIcon 2.2s ease-in-out infinite;
}

@keyframes floatIcon {
  0%, 100% {
    transform: translateY(0) rotate(-4deg);
  }
  50% {
    transform: translateY(-6px) rotate(4deg);
  }
}

.stats-box {
  display: flex;
  gap: .75rem;
  background: rgba(0,0,0,.22);
  padding: .6rem;
  border-radius: 1.25rem;
  backdrop-filter: blur(8px);
}

.stats-box div {
  min-width: 82px;
  background: rgba(255,255,255,.16);
  border-radius: 1rem;
  padding: .5rem .8rem;
  text-align: center;
}

.stats-box span {
  display: block;
  opacity: .9;
}

.stats-box strong {
  display: block;
  font-size: 1.25rem;
}

/* Tabs */

.tab-wrap {
  display: flex;
  gap: .5rem;
  background: #e2e8f0;
  border-radius: 1.25rem;
  padding: .35rem;
}

.tab-button {
  flex: 1;
  min-height: 52px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .5rem;
  border-radius: 1rem;
  font-weight: 700;
  color: #475569;
  transition: .18s;
}

.tab-button:hover {
  background: rgba(255,255,255,.65);
}

.tab-button.active {
  background: white;
  color: var(--pink);
  box-shadow: 0 8px 18px rgba(0,0,0,.10);
}

/* Layout */

.view-section {
  animation: fadeUp .22s ease both;
}

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

.card {
  background: white;
  border: 4px solid rgba(139,92,246,.22);
  border-radius: 1.75rem;
  box-shadow: 0 14px 34px rgba(15,23,42,.12);
}

.section-title {
  color: var(--purple);
  font-size: 1.35rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1rem;
}

.section-title.center {
  justify-content: center;
  font-size: 2rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 1rem 0 1.5rem;
}

/* Form */

.input-label {
  display: block;
  font-size: .82rem;
  font-weight: 800;
  color: #64748b;
  margin-bottom: .35rem;
}

.main-input,
.main-textarea {
  width: 100%;
  border: 3px solid #e2e8f0;
  border-radius: 1rem;
  padding: .8rem 1rem;
  outline: none;
  font-weight: 700;
  background: #fff;
  transition: .18s;
}

.main-input:focus,
.main-textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 4px rgba(236,72,153,.13);
}

.main-textarea {
  resize: vertical;
  min-height: 150px;
}

.template-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}

.template-btn {
  font-weight: 800;
  padding: .62rem .85rem;
  border-radius: .9rem;
  transition: .16s;
}

.template-btn:hover {
  transform: translateY(-2px);
}

.template-btn.cat {
  background: #fef3c7;
  color: #92400e;
}

.template-btn.click {
  background: #dbeafe;
  color: #1d4ed8;
}

.template-btn.typing {
  background: #ede9fe;
  color: #6d28d9;
}

.template-btn.star {
  background: #dcfce7;
  color: #047857;
}

/* Buttons */

.generate-btn,
.post-btn,
.reload-btn,
.close-qr-btn,
.modal-action,
.modal-close {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: .45rem;
  font-weight: 900;
  transition: .16s;
}

.generate-btn {
  width: 100%;
  min-height: 58px;
  border-radius: 1.1rem;
  color: white;
  font-family: 'Yusei Magic', sans-serif;
  font-size: 1.2rem;
  background: linear-gradient(90deg, var(--pink), var(--yellow));
  box-shadow: 0 12px 24px rgba(236,72,153,.25);
}

.post-btn {
  width: 100%;
  min-height: 52px;
  border-radius: 1.1rem;
  color: white;
  font-family: 'Yusei Magic', sans-serif;
  background: linear-gradient(90deg, #14b8a6, #22c55e);
  box-shadow: 0 12px 24px rgba(16,185,129,.22);
}

.post-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: grayscale(.35);
}

.generate-btn:not(:disabled):hover,
.post-btn:not(:disabled):hover,
.reload-btn:hover,
.close-qr-btn:hover,
.modal-action:hover,
.modal-close:hover {
  opacity: .9;
  transform: translateY(-1px);
}

.generate-btn:active,
.post-btn:active,
.reload-btn:active {
  transform: scale(.98);
}

.reload-btn {
  background: white;
  color: var(--purple);
  border: 2px solid #ddd6fe;
  padding: .65rem 1rem;
  border-radius: 1rem;
  box-shadow: 0 8px 16px rgba(15,23,42,.08);
}

/* Preview */

.preview-shell {
  background: #0f172a;
  border: 4px solid #334155;
  border-radius: 1.75rem;
  padding: 1rem;
  box-shadow: 0 22px 42px rgba(15,23,42,.22);
  min-height: 640px;
  display: flex;
  flex-direction: column;
}

.preview-topbar {
  color: #cbd5e1;
  font-size: .8rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid #1e293b;
  margin-bottom: .75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dot {
  width: .72rem;
  height: .72rem;
  border-radius: 999px;
  display: inline-block;
}

.dot.red {
  background: #ef4444;
}

.dot.yellow {
  background: #eab308;
}

.dot.green {
  background: #22c55e;
}

.preview-badge {
  background: #1e293b;
  padding: .3rem .55rem;
  border-radius: .6rem;
  font-size: .68rem;
}

.preview-body {
  position: relative;
  background: white;
  border-radius: 1rem;
  overflow: hidden;
  flex: 1;
  height: 520px;
  min-height: 520px;
}

#preview-iframe {
  width: 100%;
  height: 100%;
  min-height: 520px;
  border: 0;
  background: white;
  display: block;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(15,23,42,.88);
  color: white;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: .9rem;
}

.spinner {
  width: 72px;
  height: 72px;
  border-radius: 999px;
  border: 6px solid rgba(255,255,255,.18);
  border-top-color: var(--pink);
  animation: spin .85s linear infinite;
}

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

.error-box {
  margin-top: 1rem;
  background: #fff1f2;
  color: #be123c;
  border: 2px solid #fecdd3;
  padding: .8rem;
  border-radius: 1rem;
  font-weight: 800;
  font-size: .9rem;
}

/* Board */

.board-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0,1fr));
  gap: 1rem;
}

@media (min-width: 768px) {
  .board-grid {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
}

@media (min-width: 1024px) {
  .board-grid {
    grid-template-columns: repeat(3, minmax(0,1fr));
  }
}

.work-card {
  background: white;
  border: 3px solid #f1f5f9;
  border-radius: 1.4rem;
  padding: 1rem;
  box-shadow: 0 10px 24px rgba(15,23,42,.08);
  display: flex;
  flex-direction: column;
  gap: .75rem;
  transition: .18s;
}

.work-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 34px rgba(15,23,42,.14);
}

.work-title {
  font-size: 1.1rem;
  font-weight: 900;
  color: #1e293b;
}

.work-meta {
  color: #7c3aed;
  font-size: .85rem;
  font-weight: 800;
}

.work-prompt {
  color: #64748b;
  font-size: .86rem;
  line-height: 1.6;
  background: #f8fafc;
  border-radius: .9rem;
  padding: .7rem;
  min-height: 70px;
}

.work-actions {
  display: flex;
  gap: .5rem;
  margin-top: auto;
}

.play-btn,
.like-btn,
.qr-btn {
  flex: 1;
  border-radius: .9rem;
  padding: .65rem .7rem;
  color: white;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  transition: .16s;
}

.play-btn {
  background: var(--purple);
}

.like-btn {
  background: var(--pink);
}

.qr-btn {
  background: #0f766e;
}

.play-btn:hover,
.like-btn:hover,
.qr-btn:hover {
  opacity: .9;
  transform: translateY(-1px);
}

/* Ranking */

.ranking-list {
  display: flex;
  flex-direction: column;
  gap: .9rem;
}

.ranking-card {
  background: white;
  border-radius: 1.3rem;
  padding: 1rem;
  box-shadow: 0 10px 24px rgba(15,23,42,.08);
  display: grid;
  grid-template-columns: 64px 1fr auto;
  align-items: center;
  gap: 1rem;
}

.rank-num {
  width: 54px;
  height: 54px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 900;
  color: white;
  background: #94a3b8;
}

.ranking-card.rank-1 {
  border-left: 10px solid #facc15;
}

.ranking-card.rank-1 .rank-num {
  background: #f59e0b;
}

.ranking-card.rank-2 {
  border-left: 10px solid #cbd5e1;
}

.ranking-card.rank-2 .rank-num {
  background: #94a3b8;
}

.ranking-card.rank-3 {
  border-left: 10px solid #b45309;
}

.ranking-card.rank-3 .rank-num {
  background: #b45309;
}

.rank-likes {
  font-size: 1.2rem;
  font-weight: 900;
  color: var(--pink);
}

/* Empty */

.empty-box {
  text-align: center;
  background: white;
  border: 4px dashed #cbd5e1;
  border-radius: 1.5rem;
  padding: 4rem 1rem;
  color: #94a3b8;
  font-weight: 900;
}

.empty-box svg {
  width: 64px;
  height: 64px;
  margin: 0 auto .75rem;
}

/* Modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0,0,0,.68);
  backdrop-filter: blur(8px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}

.modal-card {
  background: white;
  border-radius: 1.5rem;
  box-shadow: 0 24px 64px rgba(0,0,0,.30);
  overflow: hidden;
}

.modal-card.large {
  width: min(1100px, 96vw);
  height: 88vh;
  display: flex;
  flex-direction: column;
  border: 4px solid var(--pink);
}

.modal-card.small {
  width: min(380px, 94vw);
  padding: 1.5rem;
}

.modal-header {
  flex-shrink: 0;
}

#modal-iframe {
  flex: 1;
  width: 100%;
  min-height: 0;
  height: auto;
  border: 0;
  background: white;
}

.modal-header h3 {
  color: #fde047;
  font-size: 1.2rem;
}

.modal-header p {
  color: #cbd5e1;
  font-size: .8rem;
}

.modal-action,
.modal-close {
  width: 42px;
  height: 42px;
  border-radius: .8rem;
  color: white;
}

.modal-action {
  background: #2563eb;
}

.modal-close {
  background: #e11d48;
}

.close-qr-btn {
  margin-top: 1rem;
  width: 100%;
  background: var(--purple);
  color: white;
  border-radius: .9rem;
  padding: .7rem;
}

/* Effects */

.confetti {
  position: fixed;
  top: -20px;
  width: 10px;
  height: 14px;
  z-index: 999;
  pointer-events: none;
  animation: confettiFall 3.4s linear forwards;
}

@keyframes confettiFall {
  to {
    transform: translateY(110vh) rotate(720deg);
    opacity: .8;
  }
}

/* Footer */

.footer {
  margin-top: 3rem;
  background: #0f172a;
  color: #94a3b8;
  text-align: center;
  padding: 1rem;
  font-size: .8rem;
}

/* Utilities */

.hidden {
  display: none !important;
}

button:disabled {
  pointer-events: none;
}

/* Responsive */

@media (max-width: 768px) {
  .tab-wrap {
    flex-direction: column;
  }

  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  .preview-shell {
    min-height: 520px;
  }

  .preview-body {
    min-height: 420px;
  }

  .ranking-card {
    grid-template-columns: 52px 1fr;
  }

  .rank-likes {
    grid-column: 2;
  }

  .work-actions {
    flex-direction: column;
  }
}