/* =======================================================
   Custom App Styles (uses CSS variables from theme.css)
   ======================================================= */

#app {
  max-width: var(--content-max);
  margin: 0 auto;
  min-height: 100%;
  position: relative;
  background: var(--bg);
}

/* ---------------- Splash ---------------- */
#splash {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 999;
  transition: opacity 0.5s ease;
}
#splash.hide {
  opacity: 0;
  pointer-events: none;
}

.marker-loader {
  position: relative;
  width: 96px;
  height: 96px;
}
.marker-loader .dot {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--accent);
  opacity: 0;
  animation: markerIn 1.6s ease-in-out infinite;
}
.marker-loader .dot.tl {
  top: 0;
  left: 0;
  animation-delay: 0s;
}
.marker-loader .dot.tr {
  top: 0;
  right: 0;
  animation-delay: 0.15s;
}
.marker-loader .dot.br {
  bottom: 0;
  right: 0;
  animation-delay: 0.3s;
}
.marker-loader .dot.bl {
  bottom: 0;
  left: 0;
  animation-delay: 0.45s;
}
.marker-loader .frame {
  position: absolute;
  inset: 14px;
  border: 2px solid var(--separator);
  border-radius: 12px;
  opacity: 0;
  animation: frameIn 1.6s ease-in-out infinite;
}
@keyframes markerIn {
  0% {
    opacity: 0;
    transform: scale(1.6);
  }
  25% {
    opacity: 1;
    transform: scale(1);
  }
  70% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}
@keyframes frameIn {
  0% {
    opacity: 0;
  }
  30% {
    opacity: 1;
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}
.splash-word {
  margin-top: 40px;
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}
.splash-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* ---------------- Screens & nav ---------------- */
.screen {
  display: none;
  min-height: 100%;
  padding-bottom: calc(90px + var(--safe-bottom));
  animation: screenIn 0.28s ease;
}
.screen.active {
  display: block;
}
@keyframes screenIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.navbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding: calc(14px + var(--safe-top)) var(--gutter) 12px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--separator);
}
.navbar .row {
  gap: 10px;
}
.navbar .app-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  margin-right: 10px;
}
.navbar h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}
.navbar .back-btn {
  display: flex;
  align-items: center;
  gap: 2px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 2px 4px 0;
}

.theme-toggle {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 2px;
}
.theme-toggle button {
  border: none;
  background: transparent;
  cursor: pointer;
  width: 32px;
  height: 30px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  color: var(--text-secondary);
  transition:
    background-color 0.2s,
    color 0.2s;
}
.theme-toggle button.active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

main.content {
  padding: 18px var(--gutter) 0;
}

/* ---------------- Install button [PWA] ---------------- */
.install-btn {
  background: var(--accent-soft);
  color: var(--accent-strong);
  margin-right: 5px;
}
html[data-theme="dark"] .install-btn {
  color: var(--accent);
}

/* ---------------- Home dashboard ---------------- */
.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 4px;
}
.action-card {
  grid-column: span 2;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  cursor: pointer;
  border: none;
  text-align: left;
  color: var(--text-primary);
}
.action-card.half {
  grid-column: span 1;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
}
.action-card:active {
  transform: scale(0.98);
}
.action-card .icon-wrap {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-strong);
  flex-shrink: 0;
}
html[data-theme="dark"] .action-card .icon-wrap {
  color: var(--accent);
}
.action-card .label {
  font-size: 16px;
  font-weight: 600;
}
.action-card .sub {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.action-card .chev {
  color: var(--text-tertiary);
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin: 26px 4px 10px;
}

/* ---------------- Placeholder / empty states ---------------- */
.empty-state {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-secondary);
}
.empty-state .glyph {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
}
.empty-state h3 {
  color: var(--text-primary);
  font-size: 16px;
  margin: 0 0 6px;
}
.empty-state p {
  font-size: 13.5px;
  margin: 0;
  max-width: 280px;
  margin-inline: auto;
}

/* ---------------- Bottom credit bar ---------------- */
.credit-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 10px var(--gutter) calc(10px + var(--safe-bottom));
  text-align: center;
  font-size: 11.5px;
  color: var(--text-tertiary);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--separator);
  cursor: pointer;
  z-index: 15;
}
.credit-bar b {
  color: var(--text-secondary);
}

/* ---------------- Bottom sheet pane (About, etc.) ---------------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-scrim);
  z-index: 220;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.sheet-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.bottom-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: var(--content-max);
  margin: 0 auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-sheet);
  z-index: 221;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: calc(24px + var(--safe-bottom));
}
.bottom-sheet.open {
  transform: translateY(0);
}
.sheet-grabber {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background: var(--separator-strong);
  margin: 10px auto 4px;
}
.sheet-body {
  padding: 4px 20px 8px;
}

.about-header {
  text-align: center;
  padding: 18px 0 6px;
}
.about-header img {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  margin: 0 auto 10px;
}
.about-header h2 {
  margin: 0 0 4px;
  font-size: 18px;
}
.about-header p {
  margin: 0;
  font-size: 13px;
  color: var(--text-secondary);
  max-width: 300px;
  margin-inline: auto;
}

.pill-list {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pill-item {
  background: var(--surface-2);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.pill-item .pill-head {
  width: 100%;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 14px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-primary);
}
.pill-item .pill-head .ic {
  color: var(--accent-strong);
  flex-shrink: 0;
}
html[data-theme="dark"] .pill-item .pill-head .ic {
  color: var(--accent);
}
.pill-item .pill-head .chev {
  margin-left: auto;
  color: var(--text-tertiary);
  transition: transform 0.2s;
}
.pill-item.open .pill-head .chev {
  transform: rotate(90deg);
}
.pill-item .pill-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease;
  padding: 0 14px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}
.pill-item.open .pill-body {
  padding-bottom: 14px;
}
.pill-item .pill-body a {
  color: var(--accent);
  text-decoration: none;
}
.pill-item .pill-body ul {
  padding-left: inherit;
  margin: 6px 0 0;
}

/* ---------------- Wizard (New Exam) ---------------- */
.wizard-progress {
  display: flex;
  gap: 6px;
  margin: 2px 4px 20px;
}
.wizard-progress .seg {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: var(--separator);
  transition: background-color 0.2s;
}
.wizard-progress .seg.done,
.wizard-progress .seg.current {
  background: var(--accent);
}

.wizard-step {
  display: none;
}
.wizard-step.active {
  display: block;
}

.field-group {
  margin-bottom: 16px;
}
.field-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.4;
}

.answer-key-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 55vh;
  overflow-y: auto;
  padding: 2px 2px 4px;
  margin: 4px 0 6px;
}
.answer-key-grid .qkey {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 8px 8px;
}
.answer-key-grid .qkey span.qn {
  font-size: 12.5px;
  color: var(--text-secondary);
  width: 20px;
  flex-shrink: 0;
}
.answer-key-grid .qkey select {
  padding: 6px 4px;
  font-size: 13px;
  border-radius: 8px;
}

.summary-card {
  padding: 16px;
  margin-bottom: 16px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--separator);
  font-size: 14px;
}
.summary-row:last-child {
  border-bottom: none;
}
.summary-row .k {
  color: var(--text-secondary);
}
.summary-row .v {
  font-weight: 600;
}

.wizard-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}
.wizard-actions .btn {
  flex: 1;
}

/* ---------------- History list ---------------- */
.exam-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
}
.exam-row .exam-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
html[data-theme="dark"] .exam-row .exam-icon {
  color: var(--accent);
}
.exam-row .exam-info {
  min-width: 0;
  flex: 1;
}
.exam-row .exam-title {
  font-size: 15px;
  font-weight: 600;
  white-space: normal;
  overflow-wrap: break-word;
}
.exam-row .exam-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 3px;
}
.exam-row .exam-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.exam-row .exam-actions .icon-btn {
  width: 32px;
  height: 32px;
}
.exam-row .exam-actions .icon-btn svg {
  width: 15px;
  height: 15px;
}

/* ---------------- Settings ---------------- */
.settings-group {
  margin-bottom: 22px;
}
.settings-group .group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 4px 10px;
}
.settings-card {
  padding: 4px 0;
}
.settings-item {
  padding: 13px 16px;
  border-bottom: 1px solid var(--separator);
}
.settings-item:last-child {
  border-bottom: none;
}
.settings-item .row {
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}
.settings-item label.inline-label {
  font-size: 14.5px;
  font-weight: 500;
}
.settings-item input[type="number"] {
  width: 76px;
  text-align: center;
  padding: 8px;
}
.settings-item input[type="text"] {
  margin-top: 8px;
}

.danger-zone {
  padding: 4px 0;
}
.danger-row {
  padding: 14px 16px;
  cursor: pointer;
  color: var(--danger);
  font-weight: 600;
  font-size: 14.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------------- Toast Notification ---------------- */
#toastHost {
  position: fixed;
  left: 0;
  right: 0;
  top: calc(14px + var(--safe-top));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--gutter);
}
.toast {
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-card);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}
.toast.show {
  opacity: 1;
  transform: none;
}

/* ---------------- Scan: exam hub ---------------- */
.hub-header {
  padding: 16px 18px;
}
.hub-title {
  font-size: 17px;
  font-weight: 700;
}
.hub-meta {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.rank-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-secondary);
  padding: 10px 12px;
  border-bottom: 1px solid var(--separator);
}
.rank-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--separator);
}
.rank-table tr:last-child td {
  border-bottom: none;
}
.icon-btn.sm {
  width: 28px;
  height: 28px;
}

/* ---------------- Full-screen camera | Review overlays ---------------- */
.camera-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: none;
  flex-direction: column;
}
.camera-overlay.open {
  display: flex;
}
.camera-overlay video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-top-bar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(14px + var(--safe-top)) 16px 10px;
  background: linear-gradient(rgba(0, 0, 0, 0.55), transparent);
}
.icon-btn.on-dark {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  backdrop-filter: blur(6px);
}
.camera-exam-name {
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.camera-toast {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  background: rgba(20, 20, 20, 0.72);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  max-width: 82%;
  z-index: 2;
}
.camera-bottom-bar {
  position: relative;
  z-index: 2;
  margin-top: auto;
  display: flex;
  gap: 10px;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
}
.camera-bottom-bar .btn {
  flex: 1;
}
.camera-bottom-bar .btn-secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.review-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--separator);
}
.review-stats {
  font-size: 14px;
  font-weight: 600;
}
.review-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow: auto;
  background: var(--surface-2);
  cursor: zoom-in;
}
.review-canvas-wrap canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: var(--shadow-card);
}
.review-bottom-bar {
  display: flex;
  gap: 10px;
  padding: 14px 16px calc(18px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--separator);
}
.review-bottom-bar .btn {
  flex: 1;
}
#reviewOverlay,
#cameraOverlay {
  color: var(--text-primary);
}
#reviewOverlay,
#printOverlay {
  background: var(--bg);
}

/* ---------------- Zoom ---------------- */
.zoom-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  z-index: 300;
  display: none;
  flex-direction: column;
}
.zoom-overlay.open {
  display: flex;
}
.zoom-close {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 14px;
  z-index: 2;
  background: rgba(92, 92, 92, 0.35) !important;
}
.zoom-viewport {
  flex: 1;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
.zoom-viewport img {
  max-width: 92%;
  max-height: 92%;
  transition: transform 0.05s linear;
  will-change: transform;
  border-radius: 6px;
}
.zoom-hint {
  text-align: center;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12px;
  padding: 10px 0 calc(14px + var(--safe-bottom));
}

/* ---------------- Color Legend ---------------- */
.legend-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 4px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--separator);
}
.legend-row:last-child {
  border-bottom: none;
}
.legend-swatch {
  width: 20px;
  height: 20px;
  border-radius: 7px;
  border: 2.5px solid;
  flex-shrink: 0;
}

/* ---------------- In-app print preview ---------------- */
.print-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--separator);
}
.print-preview-wrap {
  flex: 1;
  overflow: auto;
  background: var(--surface-2);
  display: flex;
  justify-content: center;
  padding: 18px 10px;
}
.print-page-scaler {
  flex-shrink: 0;
}
.print-page {
  width: 210mm;
  height: 297mm;
  background: #fff;
  color: #111;
  position: relative;
  transform-origin: top left;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
  font-family: Arial, Helvetica, sans-serif;
}
.print-page .p-marker {
  position: absolute;
  background: #000;
}
.print-page .p-header {
  position: absolute;
  left: 15mm;
  right: 15mm;
  text-align: center;
}
.print-page .p-header .p-institute {
  font-size: 16pt;
  font-weight: bold;
  margin: 0;
}
.print-page .p-header .p-exam {
  font-size: 12pt;
  margin: 2mm 0 0;
  color: #555;
}
.print-page .p-header .p-rule {
  border: none;
  border-top: 0.6mm solid #111;
  margin-top: 3mm;
}
.print-page .p-student-box {
  position: absolute;
  left: 15mm;
  right: 15mm;
  border: 0.5mm solid #111;
  display: flex;
}
.print-page .p-student-box .p-field {
  flex: 1;
  display: flex;
  align-items: flex-end;
  padding: 2mm 3mm;
  font-size: 10pt;
  border-right: 0.4mm solid #111;
}
.print-page .p-student-box .p-field:last-child {
  border-right: none;
}
.print-page .p-student-box .p-label {
  color: #555;
  margin-right: 2mm;
  white-space: nowrap;
}
.print-page .p-student-box .p-fill-line {
  flex: 1;
  border-bottom: 0.35mm solid #999;
  height: 5mm;
}
.print-page .p-instr-box {
  position: absolute;
  left: 15mm;
  right: 15mm;
  border: 0.4mm solid #ccc;
  border-radius: 1mm;
  padding: 2mm 3mm;
  font-size: 8pt;
  color: #555;
  background: #fafafa;
}
.print-page .p-instr-box b {
  color: #111;
}
.print-page .p-qlabel {
  position: absolute;
  font-size: 8.5pt;
  transform: translate(0, -50%);
  color: #111;
}
.print-page .p-bubble {
  position: absolute;
  border: 0.35mm solid #000;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 6.5pt;
  color: #333;
}

@media print {
  body * {
    visibility: hidden;
  }
  #printOverlay,
  #printOverlay * {
    visibility: visible !important;
  }
  #printOverlay {
    position: absolute;
    inset: 0;
    background: #fff;
    display: block !important;
  }
  .print-topbar,
  #printOverlay .camera-bottom-bar {
    display: none !important;
  }
  .print-preview-wrap {
    padding: 0;
    overflow: visible;
    background: #fff;
    display: block;
  }
  .print-page {
    transform: none !important;
    box-shadow: none;
    position: absolute;
    top: 0;
    left: 0;
  }
  @page {
    size: A4;
    margin: 0;
  }
}
