:root {
  --bg: #f0f4f8;
  --bg-elevated: #ffffff;
  --bg-muted: #f8fafc;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #0d9488;
  --accent-hover: #0f766e;
  --accent-soft: #ccfbf1;
  --accent-ring: rgba(13, 148, 136, 0.25);
  --warn: #ea580c;
  --warn-soft: #fff7ed;
  --warn-border: #fdba74;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.1);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-full: 999px;
  --font: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  --transition: 0.18s ease;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
}

button,
input,
select {
  font: inherit;
}

/* ——— Topbar ——— */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

.topbar-end {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-menu-toggle {
  padding: 8px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  border-color: var(--border);
  color: var(--text-secondary);
  white-space: nowrap;
}

.btn-menu-toggle:hover {
  background: var(--accent-soft);
  border-color: #99f6e4;
  color: var(--accent-hover);
}

.menu-toggle-icon {
  width: 18px;
  height: 18px;
}

body.menu-collapsed .menu-toggle-icon-hide {
  display: none;
}

body.menu-collapsed .menu-toggle-icon-show {
  display: block !important;
}

body:not(.menu-collapsed) .menu-toggle-icon-show {
  display: none;
}

.role-teacher .topbar {
  position: sticky;
  top: 0;
  z-index: 40;
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.status-pill.is-live {
  background: #ecfdf5;
  color: var(--accent-hover);
  border-color: #99f6e4;
}

.role-badge {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--text);
  color: white;
  letter-spacing: 0.02em;
}

/* ——— Toolbar layout ——— */
.toolbar {
  padding: 16px 20px;
}

.role-teacher .teacher-only {
  display: block;
}

.role-teacher .student-only {
  display: none;
}

.role-student .teacher-only {
  display: none;
}

.role-student .student-only {
  display: block;
}

.role-teacher #teacher-toolbar {
  position: sticky;
  top: var(--topbar-height, 69px);
  z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  max-height: min(44vh, 360px);
  overflow: auto;
  transition:
    max-height 0.32s ease,
    opacity 0.24s ease,
    padding 0.32s ease,
    border-color 0.24s ease,
    box-shadow 0.24s ease;
}

.role-teacher.menu-collapsed #teacher-toolbar {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  pointer-events: none;
  border-bottom-color: transparent;
  box-shadow: none;
}

.role-teacher.menu-collapsed .stage {
  padding-top: 8px;
}

.toolbar-grid {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(280px, 1.4fr) minmax(220px, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.panel-label {
  margin: 0 0 12px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* ——— Segmented controls ——— */
.seg {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  width: 100%;
}

.seg-tabs {
  margin-bottom: 12px;
}

.seg-btn {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-radius: calc(var(--radius-md) - 4px);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.seg-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.7);
}

.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}

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

/* ——— Search combobox ——— */
.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-input-wrap-compact {
  margin-bottom: 10px;
}

.search-icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  min-height: 46px;
  padding: 0 14px 0 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-muted);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}

.search-input:hover {
  border-color: var(--border-strong);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 50;
  margin: 0;
  padding: 6px;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.search-dropdown li {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.search-dropdown li:hover,
.search-dropdown li.active {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.search-dropdown .surah-num {
  font-weight: 700;
  color: var(--accent);
  min-width: 28px;
}

.search-dropdown .surah-page {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.search-combo {
  position: relative;
}

.nav-hint {
  margin: 8px 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.nav-panel {
  margin-bottom: 12px;
}

/* ——— Juz grid ——— */
.juz-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding: 2px;
}

.juz-chip {
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  line-height: 1.2;
}

.juz-chip small {
  display: block;
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 2px;
}

.juz-chip:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: var(--accent-soft);
}

.juz-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgba(13, 148, 136, 0.3);
}

.juz-chip.active small {
  color: rgba(255, 255, 255, 0.85);
}

.juz-chip[hidden] {
  display: none;
}

/* ——— Page stepper ——— */
.page-stepper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-input {
  width: 88px;
  min-height: 46px;
  text-align: center;
  font-weight: 700;
  font-size: 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-muted);
}

.page-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}

.page-stepper-meta {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
}

/* ——— Buttons ——— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.875rem;
  transition: all var(--transition);
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--bg-muted);
}

.btn:active {
  transform: scale(0.98);
}

.btn svg {
  width: 18px;
  height: 18px;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.25rem;
  line-height: 1;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  border-color: transparent;
  color: white;
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0f766e, #0d9488);
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(13, 148, 136, 0.4);
}

.btn-go {
  width: 100%;
  min-height: 46px;
  margin-top: 4px;
}

.btn-warning {
  background: var(--warn-soft);
  border-color: var(--warn-border);
  color: #9a3412;
}

.btn-warning:hover {
  background: #ffedd5;
}

.btn-soft {
  background: var(--accent-soft);
  border-color: #99f6e4;
  color: var(--accent-hover);
}

.btn-soft:hover {
  background: #99f6e4;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-muted);
  border-color: var(--border);
}

.btn-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.value-chip {
  min-width: 56px;
  text-align: center;
  font-weight: 700;
  font-size: 0.875rem;
  color: var(--text);
  padding: 0 4px;
}

.value-chip-wide {
  min-width: 88px;
}

/* ——— Controls panel ——— */
.control-cluster {
  margin-bottom: 14px;
}

.cluster-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.action-stack {
  display: grid;
  gap: 8px;
}

.action-stack .btn {
  width: 100%;
}

.control-cluster-video {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

.phase-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  vertical-align: middle;
}

.seg-compact .seg-btn {
  padding: 8px 10px;
  font-size: 0.8rem;
}

.cluster-hint {
  margin: 10px 0 0;
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text-muted);
}

/* ——— Toggle ——— */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  width: 42px;
  height: 24px;
  border-radius: var(--radius-full);
  background: var(--border-strong);
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}

.toggle input:checked + .toggle-track {
  background: var(--accent);
}

.toggle input:checked + .toggle-track::after {
  transform: translateX(18px);
}

.toggle-text {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ——— Field ——— */
.field {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.field input {
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  background: var(--bg-muted);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
  background: white;
}

/* ——— Student bar ——— */
.student-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.student-hint {
  width: 100%;
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  color: var(--accent-hover);
  font-size: 0.8rem;
  font-weight: 700;
}

/* ——— Stage & mushaf ——— */
.stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 16px 20px 24px;
  min-height: 0;
}

.mushaf-frame {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, calc(var(--mushaf-width, 900px) + 120px));
  max-width: 100%;
}

.viewer-shell {
  position: relative;
  flex: 1;
  min-width: 0;
  width: auto;
  overflow: hidden;
  background: #d4ecd4;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 0;
  border: 1px solid var(--border);
}

.mushaf-context-bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #0d9488, #14b8a6);
  color: white;
  border-radius: calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px) 0 0;
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.06);
}

.mushaf-ctx-item {
  min-width: 0;
}

.mushaf-ctx-juz {
  justify-self: start;
}

.mushaf-ctx-page {
  justify-self: center;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.16);
}

.mushaf-ctx-surah {
  justify-self: end;
  text-align: right;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mushaf-nav-btn {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--bg-elevated);
  color: var(--accent-hover);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
  transition: background var(--transition), border-color var(--transition), color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.mushaf-nav-btn svg {
  width: 28px;
  height: 28px;
}

.mushaf-nav-btn:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 6px 20px rgba(13, 148, 136, 0.35);
  transform: scale(1.06);
}

.mushaf-nav-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.mushaf-nav-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
  color: var(--text-muted);
}

.role-student .mushaf-nav-btn {
  display: none;
}

.role-student .mushaf-frame {
  width: 100%;
}

.viewer-scale {
  transform-origin: top center;
  margin: 0 auto;
  padding: 14px;
  overflow: auto;
  max-height: calc(100vh - 220px);
  background: #d4ecd4;
}

.mushaf-host {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 200px;
}

.mushaf-host.is-loading:not(:empty) {
  opacity: 0.72;
}

.mushaf-host.is-loading:not(:empty) .mushaf-svg {
  filter: blur(0.3px);
}

.mushaf-host .mushaf-svg {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  border-radius: 8px;
}

.mushaf-host [data-ayah] {
  cursor: default;
}

.role-teacher .mushaf-host [data-ayah],
.role-teacher .mushaf-host text {
  cursor: pointer;
}

.mushaf-host [data-ayah].ayah-highlight {
  fill: #1c1208;
}

.mushaf-host .ayah-highlight-bg {
  pointer-events: none;
}

.mushaf-loading,
.mushaf-error {
  color: var(--text-muted);
  text-align: center;
  padding: 48px 16px;
}

.mushaf-host.is-loading .mushaf-svg {
  opacity: 0.5;
}

.role-student .viewer-shell {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.role-student .stage {
  padding: 8px 12px;
}

.role-student .toolbar {
  padding: 10px 12px;
}

/* ——— Hidden hafazan ——— */
.hidden-screen {
  width: min(100%, 480px);
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: 24px;
}

.hidden-card {
  text-align: center;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 48px 32px;
  width: 100%;
  border: 1px solid var(--border);
}

.hidden-icon {
  font-size: 2.5rem;
  margin-bottom: 16px;
}

.hidden-card h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.hidden-card p {
  margin: 0;
  color: var(--text-secondary);
}

.hidden-card .hint {
  margin-top: 16px;
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* ——— Footer ——— */
.footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.hidden-screen[hidden],
#mushaf-frame[hidden],
#viewer-shell[hidden],
.search-dropdown[hidden] {
  display: none !important;
}

/* ——— Responsive ——— */
@media (max-width: 1024px) {
  .toolbar-grid {
    grid-template-columns: 1fr 1fr;
  }

  .panel-controls {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .mushaf-context-bar {
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    padding: 10px 12px;
    font-size: 0.68rem;
  }

  .mushaf-ctx-page {
    font-size: 1rem;
    padding: 2px 8px;
  }

  .mushaf-ctx-surah {
    max-width: 42vw;
  }

  .viewer-scale {
    max-height: calc(100vh - 180px);
    padding: 8px;
  }

  .btn-menu-toggle #toggle-menu-label {
    display: none;
  }

  .btn-menu-toggle {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
  }

  .mushaf-frame {
    gap: 8px;
    width: 100%;
  }

  .mushaf-nav-btn {
    width: 44px;
    height: 44px;
  }

  .mushaf-nav-btn svg {
    width: 24px;
    height: 24px;
  }

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

  .juz-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .topbar {
    padding: 12px 14px;
  }

  .role-student .student-bar::after {
    content: "Telefon: putar landscape atau guna laptop.";
    display: block;
    width: 100%;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
  }
}
