:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-alt: #eef2ff;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #e0e7ff;
  --accent: #10b981;
  --accent-hover: #059669;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --text: #0f172a;
  --text-muted: #475569;
  --border: #dbe2ef;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --radius-md: 14px;
  --radius-lg: 22px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: none;
}

.hidden {
  display: none !important;
}

/* Header & Navigation */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 800;
  font-size: 1.3rem;
  color: var(--primary);
  text-decoration: none;
}

.brand img {
  width: 38px;
  height: 38px;
  border-radius: 10px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-size: 0.98rem;
  font-weight: 600;
  padding: 0.65rem 1.1rem;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  user-select: none;
  background: var(--surface-alt);
  color: var(--text);
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
  color: #ffffff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #ffffff;
}

.btn-outline {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-sm {
  padding: 0.42rem 0.75rem;
  font-size: 0.86rem;
  border-radius: 9px;
}

.btn-lg {
  padding: 0.9rem 1.5rem;
  font-size: 1.15rem;
  border-radius: 16px;
}

/* Main Containers */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* Auth / Passcode Gate Card */
.auth-card {
  max-width: 460px;
  margin: 3.5rem auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  text-align: center;
}

.auth-card img.logo {
  width: 72px;
  height: 72px;
  margin-bottom: 0.75rem;
}

.auth-card h1 {
  margin: 0 0 0.5rem;
  font-size: 1.6rem;
}

.auth-card p {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.98rem;
  line-height: 1.45;
}

.form-group {
  text-align: left;
  margin-bottom: 1.1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.input,
textarea,
select {
  width: 100%;
  padding: 0.75rem 0.95rem;
  font-size: 1rem;
  border-radius: 11px;
  border: 1.5px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s ease;
}

.input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Badges & Status */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-info {
  background: var(--primary-light);
  color: var(--primary);
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

/* Story Grid (Reader & Admin) */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.section-header h2 {
  margin: 0;
  font-size: 1.45rem;
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(275px, 1fr));
  gap: 1.25rem;
}

.story-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  cursor: pointer;
}

.story-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
}

.story-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.story-cover img,
.story-cover video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.story-cover-placeholder {
  font-size: 2.5rem;
  color: var(--text-muted);
}

.story-card-body {
  padding: 1.1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex: 1;
}

.story-card-title {
  margin: 0;
  font-size: 1.22rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
}

.story-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 500;
}

.story-card-actions {
  margin-top: auto;
  padding-top: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-top: 1px solid var(--border);
}

/* Pictello-Style Story Reader Player */
.player-view {
  min-height: calc(100vh - 70px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 0.85rem 1.25rem 1.25rem;
  max-width: 1160px;
  margin: 0 auto;
}

.player-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.player-title-wrap {
  text-align: center;
  flex: 1;
}

.player-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
}

.player-subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 600;
}

.player-stage {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 2px solid var(--border);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 420px;
}

.player-media-box {
  background: #0f172a;
  flex: 1;
  min-height: 300px;
  max-height: 58vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.player-media-box img,
.player-media-box video {
  max-width: 100%;
  max-height: 58vh;
  width: auto;
  height: auto;
  object-fit: contain;
}

.player-caption-box {
  padding: 1.35rem 1.5rem;
  background: var(--surface);
  border-top: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  transition: background-color 0.25s ease;
}

.player-caption-box.speaking {
  background: #ecfdf5;
  border-top-color: var(--accent);
}

.player-caption-text {
  margin: 0;
  font-size: clamp(1.3rem, 2.5vw, 1.85rem);
  font-weight: 700;
  line-height: 1.4;
  color: var(--text);
  flex: 1;
}

.player-speak-btn {
  flex-shrink: 0;
  min-width: 140px;
  min-height: 60px;
  font-size: 1.15rem;
  border-radius: 16px;
}

.player-nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1rem;
}

.player-nav-btn {
  min-width: 155px;
  min-height: 62px;
  font-size: 1.2rem;
  font-weight: 800;
  border-radius: 18px;
}

.player-dots {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.player-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #cbd5e1;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: all 0.15s ease;
}

.player-dot.active {
  width: 32px;
  border-radius: 999px;
  background: var(--primary);
}

/* Admin Panels & Editor */
.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1.5px solid var(--border);
  padding: 1.4rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.panel-header h3 {
  margin: 0;
  font-size: 1.2rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.slide-editor-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin: 1.25rem 0;
}

.slide-editor-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.slide-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--border);
}

.slide-number {
  font-weight: 800;
  font-size: 1.08rem;
  color: var(--primary);
}

.slide-editor-body {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1.25rem;
}

@media (max-width: 760px) {
  .slide-editor-body {
    grid-template-columns: 1fr;
  }
  .player-caption-box {
    flex-direction: column;
    align-items: stretch;
  }
  .player-nav-btn {
    min-width: 115px;
    font-size: 1.05rem;
  }
}

.media-dropzone {
  background: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius-md);
  min-height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
  text-align: center;
  overflow: hidden;
  position: relative;
}

.media-dropzone img,
.media-dropzone video {
  max-width: 100%;
  max-height: 190px;
  border-radius: 10px;
  object-fit: contain;
}

.media-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.65rem;
  flex-wrap: wrap;
}

.dictate-active {
  background: var(--danger) !important;
  color: #ffffff !important;
  animation: pulse 1.2s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  }
  70% {
    box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
  }
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow-md);
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: #0f172a;
  color: #ffffff;
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 200;
}
