:root {
  color-scheme: light;
  --brand: #153d36;
  --brand-strong: #0c2d28;
  --accent: #d2a94f;
  --surface: #ffffff;
  --canvas: #edf2ef;
  --text: #18322d;
  --muted: #60736e;
  --line: #d7e0dd;
  --danger: #9b2c2c;
  --warning: #8a5b00;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(210, 169, 79, 0.16), transparent 34rem),
    var(--canvas);
}

.app-shell {
  width: calc(100% - 24px);
  max-width: 620px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 0 72px;
  display: grid;
  align-items: center;
}

.clock-card {
  overflow: hidden;
  padding: clamp(20px, 5vw, 40px);
  border: 1px solid rgba(21, 61, 54, 0.09);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(21, 61, 54, 0.12);
}

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

.brand-logos {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.brand-logo {
  width: 64px;
  height: 72px;
  object-fit: contain;
}

.loah-logo {
  width: 58px;
}

.brand-divider {
  color: var(--accent);
  font-size: 1.25rem;
  font-weight: 800;
}

.eyebrow,
.section-label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  color: var(--brand);
  font-size: clamp(1.35rem, 5vw, 2rem);
}

.clock {
  margin: 28px 0 24px;
  padding: 18px;
  border-radius: 18px;
  color: #ffffff;
  text-align: center;
  background: linear-gradient(135deg, var(--brand-strong), var(--brand));
}

#clock-time,
#clock-date {
  display: block;
}

#clock-time {
  font-size: clamp(2.35rem, 12vw, 4.25rem);
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  letter-spacing: 0.03em;
}

#clock-date {
  margin-top: 8px;
  color: #dce9e5;
  font-size: 0.95rem;
  text-transform: capitalize;
}

.status {
  margin-bottom: 20px;
  text-align: center;
}

.status h2,
.workflow-panel h2 {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 1.35rem;
}

.status p,
.hint {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.status-action {
  margin-top: 14px;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  width: 100%;
  margin-bottom: 12px;
  color: var(--brand);
  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

#matricula {
  width: 100%;
  min-height: 64px;
  padding: 8px 16px;
  border: 2px solid var(--line);
  border-radius: 14px;
  color: var(--brand-strong);
  background: #fbfdfc;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.45em;
  text-align: center;
}

#pairing-code,
#device-name {
  width: 100%;
  min-height: 48px;
  margin: 6px 0 14px;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 12px;
  color: var(--brand-strong);
  background: #fbfdfc;
  font: inherit;
}

#pairing-panel label {
  display: block;
  color: var(--brand);
  font-weight: 700;
  text-align: left;
}

.pairing-camera-start {
  margin: 16px 0;
}

.pairing-camera-region {
  width: min(100%, 360px);
  margin: 16px auto;
}

.pairing-camera-view {
  width: 100%;
  aspect-ratio: 1;
}

.pairing-camera-view video {
  display: block;
  width: 100%;
  height: 100%;
  border: 3px solid var(--accent);
  border-radius: 16px;
  object-fit: cover;
  background: var(--brand-strong);
}

.pairing-camera-status {
  margin: 10px 0;
  color: var(--muted);
  line-height: 1.4;
}

.pairing-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

#matricula-hint {
  margin: 8px 0 16px;
  font-size: 0.85rem;
  text-align: center;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

button {
  min-height: 48px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 750;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.key-button {
  min-height: 58px;
  border: 1px solid var(--line);
  color: var(--brand-strong);
  background: #f5f8f7;
  font-size: 1.35rem;
}

.key-button:hover:not(:disabled) {
  background: #e8efec;
}

.key-action {
  font-size: 0.88rem;
}

.primary-button,
.secondary-button,
.danger-button {
  width: 100%;
  padding: 12px 16px;
}

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

.secondary-button {
  border: 1px solid var(--line);
  color: var(--brand);
  background: #f5f8f7;
}

.danger-button {
  color: #ffffff;
  background: var(--danger);
}

#prepare-button {
  margin-top: 14px;
}

.workflow-panel {
  text-align: center;
}

.event-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 20px 0 12px;
}

.event-button {
  padding: 14px 16px;
  border: 1px solid var(--line);
  color: var(--brand);
  background: #f5f8f7;
  text-align: left;
}

.event-button.expected {
  border-color: var(--accent);
  box-shadow: inset 4px 0 var(--accent);
}

.success-mark,
.error-mark {
  display: grid;
  width: 62px;
  height: 62px;
  margin: 0 auto 14px;
  border-radius: 50%;
  place-items: center;
  color: #ffffff;
  background: var(--brand);
  font-size: 2rem;
  font-weight: 800;
}

.error-mark {
  background: var(--danger);
}

.result-name {
  margin: 14px 0 4px;
  font-size: 1.2rem;
  font-weight: 750;
}

.result-event {
  margin: 0;
  color: var(--muted);
}

.result-time {
  display: grid;
  gap: 4px;
  margin: 22px 0;
  padding: 16px;
  border-radius: 14px;
  background: #f1f6f4;
}

#result-clock {
  color: var(--brand);
  font-size: 2rem;
}

.unexpected-indicator {
  padding: 10px;
  border-radius: 10px;
  color: var(--warning);
  background: #fff6dc;
  font-weight: 700;
}

.error-panel p {
  color: var(--muted);
}

dialog {
  width: min(92vw, 480px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
  background: rgba(8, 27, 24, 0.72);
}

.dialog-content {
  padding: 26px;
}

.dialog-content h2 {
  margin-top: 0;
  color: var(--brand);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 22px;
}

:focus-visible {
  outline: 4px solid #e2b84f;
  outline-offset: 3px;
}

[hidden],
[inert] {
  display: none !important;
}

.admin-shortcut {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 36px;
  height: 36px;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 50%;
  place-items: center;
  color: #ffffff;
  background: var(--brand);
  font-size: 1rem;
  text-decoration: none;
  box-shadow: 0 5px 18px rgba(21, 61, 54, 0.28);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 520px) {
  .app-shell {
    width: 100%;
    min-height: 100dvh;
    padding: 0;
    align-items: stretch;
  }

  .clock-card {
    min-height: 100vh;
    min-height: 100dvh;
    padding:
      max(18px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(58px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
    border: 0;
    border-radius: 0;
  }

  .brand-logo {
    width: 50px;
    height: 58px;
  }

  .loah-logo {
    width: 46px;
  }

  dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    max-height: calc(100dvh - env(safe-area-inset-top));
    border-radius: 20px 20px 0 0;
  }

  .dialog-content {
    max-height: calc(100dvh - env(safe-area-inset-top));
    padding: 24px max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    overflow-y: auto;
  }

  .dialog-actions {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) and (max-height: 740px) {
  .clock-card {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .brand-header {
    gap: 10px;
  }

  .brand-logo {
    width: 40px;
    height: 44px;
  }

  .loah-logo {
    width: 36px;
  }

  .brand-logos {
    gap: 5px;
  }

  .clock {
    margin: 12px 0;
    padding: 12px;
  }

  #clock-time {
    font-size: clamp(2.15rem, 14vw, 3.2rem);
  }

  .status {
    margin-bottom: 14px;
  }

  .status h2,
  .workflow-panel h2 {
    font-size: 1.15rem;
  }

  #matricula {
    min-height: 52px;
  }

  #matricula-hint {
    margin-bottom: 10px;
  }

  .keypad-grid {
    gap: 7px;
  }

  .key-button {
    min-height: 48px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }
}
