*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow-x: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0f0f0f;
  color: #ffffff;
  -webkit-tap-highlight-color: transparent;
}

/* Block landscape — show rotate notice instead of the app */
.rotate-notice {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: #0f0f0f;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.rotate-notice__text {
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.5;
  max-width: 280px;
}

@media (orientation: landscape) and (max-height: 500px) {
  .rotate-notice {
    display: flex;
  }

  .app {
    visibility: hidden;
    pointer-events: none;
  }
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Screens */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 100dvh;
}

.screen--active {
  display: flex;
}

/* Top panel with logo — compact bar, large logo */
.top-panel {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.75rem;
  padding-top: calc(0.2rem + env(safe-area-inset-top));
  background: #111111;
  border-bottom: 1px solid #2a2a2a;
  flex-shrink: 0;
  z-index: 20;
}

.top-panel--initial {
  grid-template-columns: 1fr auto 1fr;
}

.top-panel__side {
  width: 72px;
}

.top-logo {
  display: block;
  height: 72px;
  max-height: 72px;
  max-width: min(420px, 85vw);
  width: auto;
  object-fit: contain;
  justify-self: center;
  grid-column: 2;
}

.top-panel--initial .top-logo {
  grid-column: 2;
}

.btn-back {
  background: transparent;
  border: none;
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 600;
  padding: 0.25rem 0.35rem;
  cursor: pointer;
  min-height: 40px;
  min-width: 80px;
  text-align: left;
  align-self: center;
}

.btn-back:active {
  opacity: 0.7;
}

/* Initial screen */
#screen-initial {
  align-items: stretch;
}

.initial-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  text-align: center;
  gap: 2rem;
}

.title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 1rem;
  color: #a0a0a0;
  line-height: 1.5;
  max-width: 320px;
}

.initial-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  padding: 1rem 2rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  min-width: 160px;
  min-height: 52px;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: #3b82f6;
  color: #ffffff;
}

.btn--secondary {
  background: #2a2a2a;
  color: #ffffff;
  border: 1px solid #444;
}

/* Camera screen */
.screen--camera {
  background: #000;
  position: relative;
}

.camera-container {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
  background: #1a1a1a;
}

/* Only the crop viewport shows live camera; rest is solid mask color */
.crop-viewport {
  position: absolute;
  overflow: hidden;
  border: 2px solid #ffffff;
  border-radius: 4px;
  z-index: 2;
}

.camera-video {
  position: absolute;
  top: 0;
  left: 0;
  object-fit: cover;
  display: block;
}

.camera-canvas {
  display: none;
}

.captured-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.captured-photo[hidden], .review-controls[hidden], .capture-btn[hidden] {
  display: none;
}

.crop-viewport--review .camera-video {
  visibility: hidden;
}

.review-controls {
  position: absolute;
  z-index: 15;
  display: flex;
  gap: 0.75rem;
}

.review-controls .btn {
  flex: 1;
  min-width: 0;
  min-height: 68px;
  padding: 1.1rem 0.5rem;
  font-size: clamp(1.1rem, 4.6vw, 1.35rem);
  font-weight: 700;
}

.capture-loading {
  position: absolute;
  inset: 0;
  z-index: 18;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(4px);
  pointer-events: none;
}

.capture-loading[hidden] {
  display: none;
}

.capture-loading__spinner {
  width: 68px;
  height: 68px;
  border-radius: 999px;
  border: 5px solid rgba(255, 255, 255, 0.22);
  border-top-color: #ffffff;
  animation: spin 0.9s linear infinite;
}

.capture-loading__text {
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  text-align: center;
  letter-spacing: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.camera-controls {
  position: absolute;
  bottom: 3.25rem;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.5rem calc(0.5rem + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  z-index: 15;
}

.capture-btn {
  width: 88px;
  height: 88px;
  border-radius: 999px;
  border: 5px solid rgba(255, 255, 255, 0.9);
  background: #d62828;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease;
}

.capture-btn:hover {
  background: #e03131;
}

.capture-btn:active:not(:disabled) {
  transform: scale(0.95);
}

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

/* Dedicated landscape live model output */
.screen--live {
  min-height: 100dvh;
  background: #000;
}

.live-header {
  display: grid;
  grid-template-columns: 90px 1fr 90px;
  align-items: center;
  flex-shrink: 0;
  min-height: 52px;
  padding: env(safe-area-inset-top) 0.75rem 0;
  border-bottom: 1px solid #272727;
  background: #111;
  z-index: 3;
}

.live-header__title {
  font-size: 1rem;
  text-align: center;
}

.live-header__side {
  width: 90px;
}

.live-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 0.75rem;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0.75rem;
  background: #000;
}

.live-preview {
  position: relative;
  width: min(100%, 640px);
  height: auto;
  aspect-ratio: 1.85;
  max-height: calc(100dvh - 150px);
  flex: 0 1 auto;
  overflow: hidden;
  background: rgb(114, 114, 114);
}

.live-source,
.live-output {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.live-source {
  object-fit: fill;
  background: #000;
}

.live-output {
  z-index: 1;
  pointer-events: none;
}

.live-controls {
  display: flex;
  justify-content: center;
  width: min(100%, 640px);
  flex: 0 0 auto;
}

.btn--live-take {
  min-width: 0;
  min-height: 46px;
  padding: 0.7rem 1.4rem;
  font-size: 0.95rem;
}

.btn--live-take {
  border: 1px solid #60a5fa;
  background: #2563eb;
  color: #ffffff;
}

.threshold-control {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.45rem 0.75rem;
  width: min(100%, 640px);
  flex: 0 0 auto;
  padding: 0.65rem 0.8rem;
  border: 1px solid #343434;
  border-radius: 8px;
  background: #161616;
  color: #e5e7eb;
  font-size: 0.82rem;
}

.threshold-control output {
  color: #93c5fd;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.threshold-control input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: #3b82f6;
}

.live-capture-message {
  width: min(100%, 640px);
  flex: 0 0 auto;
  padding: 0.7rem 0.9rem;
  border: 1px solid #15803d;
  border-radius: 8px;
  background: #0f2f1c;
  color: #bbf7d0;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.35;
  text-align: center;
}

.live-capture-message[hidden] {
  display: none;
}

.inference-status {
  position: static;
  width: min(100%, 640px);
  flex: 0 0 auto;
  overflow: hidden;
  padding: 0.75rem 1rem;
  margin-bottom: env(safe-area-inset-bottom);
  border: 1px solid #343434;
  border-radius: 8px;
  background: #161616;
  color: #f3f4f6;
  font-size: 0.9rem;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  pointer-events: none;
}

.inference-status--error {
  color: #fca5a5;
}

.model-result__heading {
  margin-bottom: 0.65rem;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: 0.01em;
}

.model-result__sequence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
}

.model-result__item {
  display: inline-flex;
  align-items: center;
  overflow: hidden;
  border: 1px solid #3f4d45;
  border-radius: 7px;
  background: #202722;
}

.model-result__character {
  min-width: 2rem;
  padding: 0.38rem 0.5rem;
  background: #22c55e;
  color: #07170c;
  font-size: 1rem;
  text-align: center;
}

.model-result__confidence {
  padding: 0.38rem 0.55rem;
  color: #dcfce7;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.model-result__empty {
  color: #9ca3af;
  font-size: 0.85rem;
}

.model-result__meta {
  margin-top: 0.65rem;
  color: #9ca3af;
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

/* Status messages */
.status-message {
  position: fixed;
  bottom: calc(6.5rem + env(safe-area-inset-bottom));
  left: 1rem;
  right: 1rem;
  padding: 0.85rem 1.1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.status-message[hidden] {
  display: none;
}

.status-message--info {
  background: #1e3a5f;
  color: #93c5fd;
  border: 1px solid #2563eb;
}

.status-message--success {
  background: #14532d;
  color: #86efac;
  border: 1px solid #16a34a;
}

.status-message--error {
  background: #450a0a;
  color: #fca5a5;
  border: 1px solid #dc2626;
}

.status-message--warning {
  background: #422006;
  color: #fcd34d;
  border: 1px solid #d97706;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (min-width: 480px) {
  .title {
    font-size: 2rem;
  }

  .top-logo {
    height: 80px;
    max-height: 80px;
    max-width: min(460px, 80vw);
  }

  .capture-btn {
    width: 96px;
    height: 96px;
  }
}

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