/* Reading Lesson Server — family-LAN three-screen app */

:root {
  --primary: #667eea;
  --secondary: #4ECDC4;
  --gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #2d3748;
  --muted: #718096;
  --border: #e2e8f0;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --radius: 12px;
  --error: #ef476f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--gradient);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(102,126,234,0.3);
}

.app-header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
}

.app-header .btn-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
}

.app-header .btn-header:hover {
  background: rgba(255,255,255,0.3);
  text-decoration: none;
}

/* Container */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px;
}

/* Cards grid */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.lesson-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  cursor: pointer;
  min-height: 120px;
}

.lesson-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

.lesson-card .card-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
}

.lesson-card .card-date {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
}

/* Status pills */
.status-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.status-pill.generating {
  background: rgba(102,126,234,0.2);
  color: var(--primary);
  animation: pulse 1.6s ease-in-out infinite;
}

.status-pill.completed {
  background: rgba(78,205,196,0.2);
  color: #2a9d8f;
}

.status-pill.error {
  background: rgba(239,71,111,0.2);
  color: var(--error);
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1.0; }
}

.error-reason {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--error);
}

.retry-btn {
  margin-top: 10px;
  display: inline-block;
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--error);
  color: var(--error);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  min-width: 64px;
}

.retry-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
}

.empty-state .emoji {
  font-size: 3rem;
  margin-bottom: 12px;
}

.empty-state p {
  margin: 0 0 20px;
  font-size: 1.1rem;
  color: var(--muted);
}

.empty-state .btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  min-width: 48px;
  box-shadow: 0 4px 12px rgba(102,126,234,0.3);
}

.empty-state .btn-primary:hover {
  opacity: 0.92;
  text-decoration: none;
}

/* Upload form */
.upload-form {
  max-width: 520px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}

.upload-form label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

.upload-form input[type="file"],
.upload-form input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg);
  margin-bottom: 18px;
}

.upload-form input[type="file"] {
  padding: 10px 14px;
}

.upload-form .preview {
  margin-bottom: 18px;
}

.upload-form .preview img {
  max-width: 100%;
  max-height: 240px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.upload-form .btn-submit {
  width: 100%;
  padding: 14px;
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  box-shadow: 0 4px 12px rgba(102,126,234,0.3);
}

.upload-form .btn-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.upload-form .form-error {
  color: var(--error);
  font-size: 0.9rem;
  margin-bottom: 12px;
  min-height: 1.2em;
}

/* Viewer */
.viewer-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: var(--gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.viewer-header .back-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  min-width: 44px;
}

.viewer-header .back-btn:hover {
  background: rgba(255,255,255,0.3);
  text-decoration: none;
}

.viewer-header .viewer-title {
  flex: 1;
  margin: 0 12px;
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.viewer-iframe {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: calc(100vh - 48px);
  border: none;
}
