/* ── Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --purple: #6B4FA0;
  --purple-light: #8B6FC0;
  --green: #4CAF50;
  --green-dark: #388E3C;
  --yellow: #FFB74D;
  --yellow-light: #FFE0B2;
  --pink: #E91E63;
  --cream: #FFF8E7;
  --white: #FFFFFF;
  --text: #333333;
  --text-light: #666666;
  --shadow: 0 4px 20px rgba(0,0,0,0.1);
  --radius: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--cream);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 16px;
  background-image:
    radial-gradient(circle at 20% 80%, rgba(107,79,160,0.06) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(76,175,80,0.06) 0%, transparent 50%);
}

.screen { display: none; width: 100%; max-width: 500px; }
.screen.active { display: block; }
.hidden { display: none !important; }

/* ── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.hero { text-align: center; padding: 40px 24px; }

.egg-icon {
  font-size: 64px;
  margin-bottom: 12px;
  animation: wobble 2s ease-in-out infinite;
}

@keyframes wobble {
  0%, 100% { transform: rotate(-5deg); }
  50% { transform: rotate(5deg); }
}

h1 {
  font-size: 28px;
  color: var(--purple);
  margin-bottom: 4px;
}
h1 small {
  font-size: 18px;
  color: var(--text-light);
  font-weight: 400;
}

h2 { font-size: 22px; color: var(--purple); margin-bottom: 12px; }
h3 { font-size: 16px; color: var(--purple); margin-bottom: 8px; }
h4 { font-size: 14px; color: var(--text-light); margin-bottom: 4px; }

.subtitle {
  color: var(--text-light);
  margin-bottom: 24px;
  font-size: 15px;
}

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 12px 24px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  margin-bottom: 8px;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--purple); color: white; }
.btn-primary:hover { background: var(--purple-light); }

.btn-secondary { background: var(--yellow-light); color: var(--text); }
.btn-secondary:hover { background: var(--yellow); }

.btn-success { background: var(--green); color: white; }
.btn-success:hover { background: var(--green-dark); }

.btn-warning { background: #FF9800; color: white; }

.btn-ghost {
  background: transparent;
  color: var(--purple);
  border: 2px solid var(--purple);
}

.btn-large { padding: 16px 32px; font-size: 18px; margin-top: 16px; }

.btn-group { margin-top: 16px; }

.btn-small {
  padding: 6px 14px;
  font-size: 13px;
  width: auto;
  margin: 2px;
}

/* ── Forms ──────────────────────────────────────────────────────────── */
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #E0E0E0;
  border-radius: 12px;
  font-size: 16px;
  margin-bottom: 8px;
  background: var(--white);
  transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--purple);
}
textarea { resize: vertical; min-height: 60px; font-family: inherit; }

/* ── Room Code ─────────────────────────────────────────────────────── */
.room-code-display { text-align: center; margin-bottom: 16px; font-size: 15px; }
.room-code {
  font-size: 32px;
  font-weight: 800;
  color: var(--purple);
  letter-spacing: 4px;
  font-family: 'Courier New', monospace;
}

/* ── Player List ───────────────────────────────────────────────────── */
.player-list {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.player-tag {
  background: var(--yellow-light);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
}
.player-tag.solved { background: var(--green); color: white; }
.player-tag.disconnected { opacity: 0.5; }

/* ── Sections ──────────────────────────────────────────────────────── */
.section { margin-bottom: 20px; }

.invite-links { margin-top: 12px; }
.invite-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #F5F5F5;
  border-radius: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  word-break: break-all;
}
.invite-link button {
  flex-shrink: 0;
  padding: 4px 10px;
  border: 1px solid var(--purple);
  background: white;
  color: var(--purple);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

/* ── Clue Editor ───────────────────────────────────────────────────── */
.clue-edit-row {
  margin-bottom: 10px;
  padding: 8px;
  background: #FAFAFA;
  border-radius: 8px;
}
.clue-edit-row label {
  font-size: 13px;
  font-weight: 600;
  color: var(--purple);
  display: block;
  margin-bottom: 4px;
}

/* ── Round Header ──────────────────────────────────────────────────── */
.round-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }

.round-badge {
  background: var(--purple);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.intro-text {
  color: var(--text-light);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 20px;
  padding: 12px;
  background: var(--yellow-light);
  border-radius: 12px;
}

/* ── Puzzle Areas ──────────────────────────────────────────────────── */
#puzzle-area { margin-bottom: 16px; }

.puzzle-question {
  font-size: 16px;
  line-height: 1.6;
  margin-bottom: 16px;
  padding: 16px;
  background: #F9F5FF;
  border-radius: 12px;
  border-left: 4px solid var(--purple);
}

.puzzle-answer-row {
  display: flex;
  gap: 8px;
}
.puzzle-answer-row input { flex: 1; margin-bottom: 0; }
.puzzle-answer-row .btn { width: auto; margin-bottom: 0; }

.answer-feedback {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}
.answer-feedback.correct { background: #E8F5E9; color: var(--green-dark); }
.answer-feedback.wrong { background: #FFEBEE; color: #C62828; }
.answer-feedback.hint-msg { background: var(--yellow-light); color: #795548; }

/* ── Scramble ──────────────────────────────────────────────────────── */
.scramble-letters {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 20px 0;
  flex-wrap: wrap;
}
.scramble-letter {
  width: 44px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--purple);
  color: white;
  font-size: 22px;
  font-weight: 800;
  border-radius: 10px;
  box-shadow: 0 3px 8px rgba(107,79,160,0.3);
}

/* ── Cipher ────────────────────────────────────────────────────────── */
.cipher-table {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 4px;
  margin-bottom: 16px;
}
.cipher-cell {
  text-align: center;
  padding: 8px 4px;
  background: #F9F5FF;
  border-radius: 8px;
  font-size: 14px;
}
.cipher-cell .letter { font-weight: 800; font-size: 18px; color: var(--purple); }
.cipher-cell .number { font-size: 12px; color: var(--text-light); }

.encrypted-numbers {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
}
.enc-num {
  width: 44px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--yellow);
  font-size: 20px;
  font-weight: 800;
  border-radius: 10px;
}
.enc-positions { text-align: center; color: var(--text-light); font-size: 13px; margin-bottom: 12px; }

/* ── Word Search ───────────────────────────────────────────────────── */
.ws-grid {
  display: grid;
  gap: 2px;
  margin: 12px auto;
  max-width: 360px;
}
.ws-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F5F5F5;
  font-size: 15px;
  font-weight: 700;
  border-radius: 4px;
  user-select: none;
  transition: background 0.3s;
}
.ws-cell.found { background: var(--green); color: white; }
.ws-cell.found-other { background: #81C784; color: white; }

.ws-word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
  justify-content: center;
}
.ws-word {
  padding: 6px 12px;
  background: #F5F5F5;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}
.ws-word.found { background: var(--green); color: white; text-decoration: line-through; }
.ws-word.mine { border: 2px solid var(--purple); }

.ws-input-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.ws-input-row input { flex: 1; margin-bottom: 0; }
.ws-input-row .btn { width: auto; margin-bottom: 0; }

/* ── Status Bar ────────────────────────────────────────────────────── */
.status-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px;
  background: #F5F5F5;
  border-radius: 10px;
  margin-bottom: 12px;
}

/* ── GM Game ───────────────────────────────────────────────────────── */
.gm-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }

.progress-panel {
  padding: 12px;
  background: #F9F5FF;
  border-radius: 12px;
  margin-bottom: 16px;
}

.progress-player {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid #E0E0E0;
}
.progress-player:last-child { border: none; }
.progress-status { font-size: 13px; }
.progress-status.solved { color: var(--green); font-weight: 700; }
.progress-status.pending { color: var(--text-light); }

.gm-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.gm-controls .btn { flex: 1; min-width: 140px; }

.hint-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.hint-row input { flex: 1; margin: 0; }
.hint-row .btn { width: auto; margin: 0; }

/* ── Clue Reveal ───────────────────────────────────────────────────── */
.clue-card { text-align: center; padding: 32px 24px; }
.clue-icon { font-size: 64px; margin-bottom: 12px; animation: pulse 1s ease-in-out; }
.clue-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--purple);
  padding: 20px;
  background: var(--yellow-light);
  border-radius: 12px;
  margin: 16px 0;
  line-height: 1.4;
}
.clue-waiting { color: var(--text-light); font-size: 14px; margin-top: 12px; }

@keyframes pulse {
  0% { transform: scale(0.5); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

/* ── Finale ────────────────────────────────────────────────────────── */
.finale-card {
  text-align: center;
  padding: 40px 24px;
  background: linear-gradient(135deg, var(--yellow-light), #E8F5E9, #F3E5F5);
  position: relative;
  overflow: hidden;
}
.finale-card h1 { font-size: 28px; margin-bottom: 16px; }
.finale-text {
  font-size: 22px;
  font-weight: 700;
  color: var(--purple);
  padding: 24px;
  background: rgba(255,255,255,0.8);
  border-radius: 16px;
  margin: 16px 0;
  line-height: 1.5;
}

.egg-rain {
  font-size: 32px;
  letter-spacing: 8px;
  margin-top: 16px;
  animation: rainBounce 2s ease-in-out infinite;
}
@keyframes rainBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

/* ── Loader ────────────────────────────────────────────────────────── */
.loader {
  width: 40px;
  height: 40px;
  border: 4px solid var(--yellow-light);
  border-top-color: var(--purple);
  border-radius: 50%;
  margin: 20px auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 400px) {
  body { padding: 8px; }
  .card { padding: 16px; }
  .scramble-letter { width: 36px; height: 42px; font-size: 18px; }
  .enc-num { width: 36px; height: 42px; font-size: 16px; }
  .ws-cell { font-size: 13px; }
  h1 { font-size: 24px; }
}

/* ── Confetti animation ────────────────────────────────────────────── */
.confetti {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  overflow: hidden;
}
.confetti::before, .confetti::after {
  content: '🎉✨🌟🎊';
  position: absolute;
  font-size: 24px;
  animation: confettiFall 3s ease-in-out infinite;
}
.confetti::before { left: 20%; animation-delay: 0s; }
.confetti::after { right: 20%; animation-delay: 1.5s; }
@keyframes confettiFall {
  0% { top: -20%; opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

/* Solved overlay */
.puzzle-solved-overlay {
  text-align: center;
  padding: 24px;
}
.puzzle-solved-overlay .checkmark { font-size: 48px; margin-bottom: 8px; }
.puzzle-solved-overlay p { color: var(--green-dark); font-weight: 600; }
