:root {
  --bg: #eef6fc;
  --surface: rgba(255, 255, 255, 0.95);
  --ink: #10263a;
  --muted: #60778b;
  --line: rgba(0, 65, 116, 0.16);
  --navy: #003b6f;
  --navy-dark: #00294f;
  --blue: #0067a9;
  --blue-bright: #1689d1;
  --sky: #6fc3ef;
  --ice: #dff3ff;
  --accent: #0b78b7;
  --danger: #c63f4f;
  --shadow: 0 16px 40px rgba(0, 53, 96, 0.16);
  --small-shadow: 0 8px 22px rgba(0, 53, 96, 0.11);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    radial-gradient(circle at 6% 2%, rgba(22, 137, 209, 0.20), transparent 24rem),
    radial-gradient(circle at 96% 17%, rgba(111, 195, 239, 0.28), transparent 24rem),
    radial-gradient(circle at 50% 100%, rgba(0, 103, 169, 0.13), transparent 29rem),
    linear-gradient(155deg, #eef7fd, #ffffff 52%, #e4f2fb);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid rgba(22, 137, 209, 0.48);
  outline-offset: 3px;
}

.app-shell {
  width: min(100%, 780px);
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    14px
    max(34px, env(safe-area-inset-bottom));
}

.hero {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 112px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 26px;
  color: #fff;
  background:
    linear-gradient(145deg, rgba(255,255,255,0.12), transparent 42%),
    linear-gradient(135deg, #00294f, #004c84 56%, #1689d1);
  box-shadow: 0 19px 48px rgba(0, 48, 87, 0.28);
}

.hero-icon {
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 9px 24px rgba(0,0,0,0.22);
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.55rem, 7vw, 2.4rem);
  line-height: 1;
  letter-spacing: -0.05em;
}

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin: 17px 0;
}

.action-button {
  min-height: 105px;
  padding: 14px 10px;
  border: 0;
  border-radius: 22px;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-weight: 850;
}

.photo-action {
  background: linear-gradient(145deg, #0067a9, #1689d1 58%, #5eb7e8);
}

.number-action {
  background: linear-gradient(145deg, #003b6f, #0067a9 56%, #1689d1);
}

.action-button:active {
  transform: translateY(1px);
}

.action-icon {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 7px;
  border: 1px solid rgba(255,255,255,0.38);
  border-radius: 16px;
  background: rgba(255,255,255,0.14);
  font-size: 1.15rem;
  font-weight: 900;
}

.input-panel {
  margin-bottom: 15px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--small-shadow);
  backdrop-filter: blur(13px);
}

.input-panel[hidden] {
  display: none;
}

.panel-heading,
.results-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-heading h2,
.results-heading h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: -0.035em;
}

.panel-close {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 12px;
  color: var(--danger);
  background: #fff0f2;
  cursor: pointer;
  font-size: 1.25rem;
  font-weight: 900;
}

.number-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.number-display {
  display: flex;
  align-items: center;
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid rgba(0,103,169,0.26);
  border-radius: 15px;
  color: var(--ink);
  overflow-x: auto;
  background: #fff;
  white-space: nowrap;
  font-size: clamp(1rem, 4.8vw, 1.22rem);
  font-weight: 850;
  letter-spacing: 0.06em;
}

.number-display.empty {
  color: #8c8496;
  font-weight: 700;
  letter-spacing: normal;
}

.keypad-digit {
  display: inline-block;
  padding: 3px 1px;
  border-radius: 4px;
}

.keypad-caret {
  display: inline-block;
  width: 2px;
  height: 1.35em;
  margin: 0 1px;
  background: var(--blue-bright);
  vertical-align: -0.25em;
  animation: blink 900ms steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

.clear-button {
  min-width: 71px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--danger);
  background: #fff2f4;
  cursor: pointer;
  font-weight: 850;
}

.helper {
  margin: 9px 2px 12px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.cursor-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.cursor-controls button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #f0ecf7;
  font-size: 1.1rem;
  font-weight: 900;
}

.ten-key {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ten-key button {
  min-height: 58px;
  border: 1px solid rgba(117,72,255,0.15);
  border-radius: 15px;
  color: var(--ink);
  background: #f8f5ff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.8);
  font-size: 1.35rem;
  font-weight: 900;
}

.ten-key button:active,
.cursor-controls button:active {
  background: rgba(22,137,209,0.15);
  transform: translateY(1px);
}

.ten-key .key-clear {
  color: var(--danger);
  background: #fff0f2;
  font-size: 0.94rem;
}

.generate-button {
  width: 100%;
  min-height: 52px;
  margin-top: 10px;
  border: 0;
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(135deg, var(--navy), var(--blue-bright));
  box-shadow: 0 9px 21px rgba(0,103,169,0.25);
  cursor: pointer;
  font-weight: 900;
}

.photo-preview {
  display: block;
  width: 100%;
  max-height: 330px;
  margin-top: 11px;
  border-radius: 15px;
  object-fit: contain;
  background: #e9e4ef;
}

.photo-status {
  min-height: 20px;
  margin: 9px 2px 0;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.4;
}

.progress-track {
  height: 8px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(22,137,209,0.13);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--sky), var(--blue-bright), var(--navy));
  transition: width 150ms ease;
}

.current-number-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  width: 100%;
  min-height: 38px;
  margin: 0 0 14px;
  padding: 4px 5px 4px 10px;
  border: 1px solid rgba(0,103,169,0.18);
  border-radius: 11px;
  color: var(--ink);
  background: rgba(255,255,255,0.78);
  box-shadow: 0 4px 12px rgba(0, 53, 96, 0.07);
}

.current-number-strip[hidden] {
  display: none;
}

.current-number-value {
  min-width: 0;
  padding: 5px 2px;
  overflow-x: auto;
  border: 0;
  color: var(--ink);
  background: transparent;
  white-space: nowrap;
  text-align: left;
  font-size: clamp(0.74rem, 3.25vw, 0.89rem);
  font-weight: 900;
  letter-spacing: 0.035em;
  scrollbar-width: none;
}

.current-number-value::-webkit-scrollbar {
  display: none;
}

.current-number-clear {
  min-height: 30px;
  padding: 5px 9px;
  border: 0;
  border-radius: 8px;
  color: var(--danger);
  background: #fff0f2;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 900;
}

body.input-open .current-number-strip,
body.input-open .results-section,
body.input-open .notice {
  display: none !important;
}

.results-section {
  margin-top: 3px;
}

.result-count {
  display: grid;
  place-items: center;
  min-width: 34px;
  min-height: 30px;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--navy);
  background: rgba(22,137,209,0.13);
  font-size: 0.86rem;
  font-weight: 900;
}

.results {
  display: grid;
  gap: 14px;
  margin-top: 11px;
}

.empty-results {
  padding: 27px 17px;
  border: 2px dashed rgba(0,103,169,0.22);
  border-radius: 20px;
  color: var(--muted);
  background: rgba(255,255,255,0.54);
  text-align: center;
  line-height: 1.45;
}

.barcode-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 21px;
  overflow: hidden;
  background: rgba(255,255,255,0.95);
  box-shadow: var(--small-shadow);
}

.barcode-tap {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 14px;
  overflow: hidden;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

.barcode-wrap {
  display: grid;
  place-items: center;
  min-height: 135px;
  padding: 12px 12px 2px;
  overflow: hidden;
  background: #fff;
}

.barcode-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.candidate-number {
  margin: 8px 8px 12px;
  overflow-wrap: anywhere;
  text-align: center;
  font-size: clamp(0.95rem, 4.8vw, 1.16rem);
  font-weight: 900;
  letter-spacing: 0.055em;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}

.card-actions button {
  min-height: 43px;
  padding: 8px 5px;
  border: 0;
  border-radius: 13px;
  color: #fff;
  cursor: pointer;
  font-size: 0.80rem;
  font-weight: 900;
}

.share-button {
  background: linear-gradient(135deg, #0067a9, #1689d1);
}

.download-button {
  background: linear-gradient(135deg, #1689d1, #6fc3ef);
}

.notice {
  margin-top: 20px;
  padding: 12px 14px;
  border: 1px solid rgba(69,43,102,0.10);
  border-radius: 15px;
  color: var(--muted);
  background: rgba(255,255,255,0.54);
  font-size: 0.78rem;
  line-height: 1.45;
}

.fullscreen-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  background: #fff;
}

.fullscreen-modal[hidden] {
  display: none;
}

.fullscreen-surface {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  width: 100%;
  height: 100%;
  padding:
    max(46px, env(safe-area-inset-top))
    14px
    max(12px, env(safe-area-inset-bottom));
  background: #fff;
}

.fullscreen-close {
  position: absolute;
  top: max(9px, env(safe-area-inset-top));
  right: 10px;
  z-index: 3;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 13px;
  color: #fff;
  background: #003b6f;
  cursor: pointer;
  font-size: 1.35rem;
  font-weight: 900;
}

.fullscreen-stage {
  display: grid;
  place-items: center;
  align-content: center;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.fullscreen-stage canvas {
  display: block;
  width: min(94%, 1500px);
  max-width: 100%;
  height: auto;
  max-height: 70%;
  object-fit: contain;
  background: #fff;
}

.fullscreen-number {
  margin-top: 11px;
  max-width: 96%;
  overflow-wrap: anywhere;
  color: #000;
  text-align: center;
  font-size: clamp(1rem, 4vw, 1.55rem);
  font-weight: 900;
  letter-spacing: 0.07em;
}

.fullscreen-navigation {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 9px;
  align-items: center;
  width: min(100%, 500px);
}

.fullscreen-navigation button {
  min-height: 43px;
  border: 0;
  border-radius: 13px;
  color: #fff;
  background: #00558f;
  cursor: pointer;
  font-weight: 850;
}

.fullscreen-navigation button:disabled {
  opacity: 0.38;
}

.fullscreen-navigation span {
  min-width: 64px;
  text-align: center;
  font-weight: 900;
}

/* Visual landscape fallback when browser orientation locking is unavailable. */
.fullscreen-modal.force-landscape .fullscreen-surface {
  inset: auto;
  left: 50%;
  top: 50%;
  width: 100dvh;
  height: 100dvw;
  transform: translate(-50%, -50%) rotate(90deg);
}

.fullscreen-modal.force-landscape .fullscreen-stage canvas {
  width: min(94%, 1500px);
  max-height: 68%;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 150;
  max-width: calc(100% - 28px);
  padding: 11px 16px;
  border-radius: 999px;
  color: #fff;
  background: #003b6f;
  box-shadow: 0 9px 27px rgba(0,0,0,0.24);
  transform: translate(-50%, 18px);
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  text-align: center;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

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

@media (orientation: landscape) {
  .fullscreen-stage canvas {
    width: min(95%, 1600px);
    max-height: 72%;
  }

  .fullscreen-number {
    margin-top: 7px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 9px;
    padding-right: 9px;
  }

  .hero {
    min-height: 102px;
    padding: 15px;
  }

  .hero-icon {
    width: 62px;
    height: 62px;
  }

  .action-grid {
    gap: 8px;
  }

  .action-button {
    min-height: 98px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
    animation: none !important;
  }
}
