/* ============================================================
   Lulu Academy — Shared Styles
   Responsive: 768px breakpoint, mobile-first
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
  --c-primary: #d97706;
  --c-primary-light: #fbbf24;
  --c-primary-dark: #92400e;
  --c-bg: #fffbeb;
  --c-card-bg: #ffffff;
  --c-text: #92400e;
  --c-text-light: #a16207;
  --c-success: #10b981;
  --c-error: #ef4444;
  --c-accent: #f59e0b;
  --radius: 16px;
  --shadow: 0 4px 24px rgba(245,158,11,0.10);
  --shadow-hover: 0 8px 32px rgba(245,158,11,0.18);
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --bp-mobile: 768px;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font-body);
  background: var(--c-bg);
  color: var(--c-text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Typography ---- */
h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.5rem; font-weight: 600; }
h3 { font-size: 1.125rem; font-weight: 600; }

/* ---- Gate Page ---- */
.gate-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 50%, #f59e0b 100%);
  overflow: hidden;
}

#lulu-container {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 1;
}

.gate-card {
  position: relative; z-index: 10;
  background: var(--c-card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 48px 40px;
  max-width: 420px; width: calc(100% - 32px);
  text-align: center;
  animation: fadeInUp 0.6s ease;
}

.gate-card h1 {
  color: var(--c-primary);
  margin-bottom: 8px;
}

.gate-card .subtitle {
  color: var(--c-text-light);
  margin-bottom: 32px;
  font-size: 0.95rem;
}

#auth-form {
  display: flex; flex-direction: column; gap: 12px;
}

#auth-form input[type="password"] {
  padding: 14px 18px;
  border: 2px solid #e5e7eb;
  border-radius: 12px;
  font-size: 1rem;
  transition: border-color 0.2s;
  outline: none;
}

#auth-form input[type="password"]:focus {
  border-color: var(--c-primary);
}

#auth-form button {
  padding: 14px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#auth-form button:hover { background: var(--c-primary-dark); }
#auth-form button:active { transform: scale(0.97); }
#auth-form button:disabled { opacity: 0.6; cursor: not-allowed; }

.error-msg {
  color: var(--c-error);
  font-size: 0.85rem;
  min-height: 20px;
}

.student-entry {
  margin-top: 24px; padding-top: 24px;
  border-top: 1px solid #e5e7eb;
}

.student-entry a {
  color: var(--c-text-light);
  font-size: 0.9rem;
}

.student-entry a:hover {
  color: var(--c-primary);
}

/* ---- Top Bar ---- */
.top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px;
  background: var(--c-card-bg);
  border-bottom: 1px solid #ede9fe;
  position: sticky; top: 0; z-index: 100;
}

.top-bar .logo {
  font-size: 1.25rem; font-weight: 700;
  color: var(--c-primary);
}

.logout-btn {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  color: var(--c-text-light);
  font-size: 0.85rem;
  transition: all 0.2s;
}

.logout-btn:hover {
  border-color: var(--c-error);
  color: var(--c-error);
}

/* ---- Teacher Layout ---- */
.teacher-page {
  min-height: 100vh;
}

.teacher-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ---- Cards Grid ---- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  align-content: start;
}

.card {
  background: var(--c-card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.3s;
  border: 2px solid transparent;
  display: flex; flex-direction: column; gap: 12px;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.card-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.card h3 {
  margin: 0;
}

.card p {
  color: var(--c-text-light);
  font-size: 0.9rem;
}

.card-actions {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: auto;
}

.card-actions textarea,
.card-actions input {
  padding: 12px;
  border: 2px solid #e5e7eb;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: var(--font-body);
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color 0.2s;
}

.card-actions textarea:focus,
.card-actions input:focus {
  border-color: var(--c-primary);
}

.card-actions .dual-inputs {
  display: flex; gap: 8px;
}

.card-actions .dual-inputs input {
  flex: 1;
  min-height: auto;
}

.btn-generate {
  padding: 12px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-generate:hover { background: var(--c-primary-dark); }
.btn-generate:active { transform: scale(0.97); }
.btn-generate:disabled { opacity: 0.6; cursor: not-allowed; }

.game-link-btn {
  display: inline-block;
  padding: 12px 24px;
  background: var(--c-accent);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  transition: background 0.2s;
}

.game-link-btn:hover {
  background: #d97706;
  text-decoration: none;
}

/* ---- 4-State UI ---- */
.result-area {
  padding: 16px;
  background: #f0fdf4;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
}

.result-area.hidden { display: none; }

/* Skeleton loading */
.skeleton {
  padding: 16px;
  border-radius: 10px;
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  min-height: 80px;
}

.skeleton.hidden { display: none; }

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

/* Error state */
.card.state-error {
  border-color: var(--c-error);
  animation: shake 0.3s ease;
}

.card.state-success {
  border-color: var(--c-success);
}

.retry-btn {
  padding: 8px 16px;
  background: transparent;
  border: 1px solid var(--c-error);
  color: var(--c-error);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  display: none;
}

.state-error .retry-btn { display: inline-block; }

/* ---- Lulu Panel ---- */
.lulu-panel {
  position: sticky; top: 80px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
}

.lulu-panel #lulu-container {
  position: relative;
  width: 240px; height: 320px;
  pointer-events: auto;
}

.lulu-speech-bubble {
  position: relative;
  background: var(--c-card-bg);
  border-radius: 14px;
  padding: 12px 18px;
  box-shadow: var(--shadow);
  max-width: 240px;
  text-align: center;
  animation: bounceIn 0.4s ease;
}

.lulu-speech-bubble::after {
  content: '';
  position: absolute; top: -8px; left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid var(--c-card-bg);
}

.lulu-speech-bubble p {
  font-size: 0.85rem;
  color: var(--c-text);
}

/* ---- Chat Toggle Button ---- */
.chat-toggle-btn {
  padding: 8px 16px;
  background: var(--c-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  margin-right: 8px;
  transition: background 0.2s;
}
.chat-toggle-btn:hover { background: var(--c-primary-dark); }

/* ---- Chat Panel ---- */
.chat-panel {
  position: fixed; top: 0; right: 0;
  width: 380px; height: 100vh;
  background: var(--c-card-bg);
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 500;
  display: flex; flex-direction: column;
  transition: transform 0.3s ease;
}
.chat-panel.hidden { transform: translateX(100%); }
.chat-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #ede9fe;
  font-weight: 600;
  font-size: 1rem;
}
.chat-panel-header button {
  background: none; border: none; font-size: 1.2rem;
  cursor: pointer; color: var(--c-text-light);
}
.chat-panel iframe { flex: 1; min-height: 0; }

@media (max-width: 768px) {
  .chat-panel { width: 100vw; }
  .chat-toggle-btn { font-size: 0.8rem; padding: 6px 12px; }
}

/* ---- Student Page ---- */
.student-page {
  min-height: 100vh;
}

.student-layout {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 20px;
  max-width: 900px;
  margin: 0 auto;
  padding: 24px;
  height: calc(100vh - 70px);
}

#coze-chat-container {
  background: var(--c-card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 400px;
}

.lulu-small #lulu-container {
  width: 100px; height: 140px;
}

/* ---- 2D Fallback Character ---- */
.lulu-2d {
  width: 100px; height: 100px;
  border-radius: 50%;
  background: var(--c-primary);
  position: relative;
  margin: 0 auto;
  transition: transform 0.3s;
}

.lulu-2d::before,
.lulu-2d::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 35px;
}

.lulu-2d::before { left: 22px; }
.lulu-2d::after { right: 22px; }

.lulu-2d .pupil {
  position: absolute;
  width: 6px; height: 6px;
  background: #000;
  border-radius: 50%;
  top: 40px;
}

.lulu-2d .pupil.left { left: 27px; }
.lulu-2d .pupil.right { right: 27px; }

.lulu-2d .mouth {
  position: absolute;
  width: 20px; height: 10px;
  border-bottom: 3px solid #fff;
  border-radius: 0 0 10px 10px;
  bottom: 28px; left: 50%;
  transform: translateX(-50%);
}

/* ---- Animations ---- */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes bounceIn {
  0% { opacity: 0; transform: scale(0.8); }
  60% { transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* ---- Accessibility ---- */
:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

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

/* ---- Spinner ---- */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ============================================================
   Responsive: Mobile (< 768px)
   ============================================================ */
@media (max-width: 768px) {
  .gate-card {
    padding: 32px 24px;
  }

  .teacher-layout {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .cards-grid {
    grid-template-columns: 1fr;
  }

  .lulu-panel {
    position: fixed; bottom: 16px; right: 16px;
    flex-direction: row-reverse;
    z-index: 200;
  }

  .lulu-panel #lulu-container {
    width: 48px; height: 48px;
  }

  .lulu-speech-bubble {
    display: none;
  }

  .student-layout {
    grid-template-columns: 1fr;
    height: auto;
    padding: 16px;
  }

  .lulu-small #lulu-container {
    position: fixed; bottom: 16px; right: 16px;
    width: 48px; height: 48px;
    z-index: 200;
  }

  #coze-chat-container {
    min-height: 70vh;
  }
}
