:root {
  --bg: #efe8dc;
  --panel: rgba(255, 255, 255, 0.8);
  --panel-strong: rgba(255, 255, 255, 0.94);
  --text: #181511;
  --muted: #5e564d;
  --accent: #111111;
  --accent-soft: #d8cdc0;
  --line: rgba(24, 21, 17, 0.08);
  --shadow: 0 20px 40px rgba(52, 42, 31, 0.14);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-top: max(env(safe-area-inset-top), 16px);
  --safe-right: max(env(safe-area-inset-right), 16px);
  --safe-bottom: max(env(safe-area-inset-bottom), 16px);
  --safe-left: max(env(safe-area-inset-left), 16px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: 'Manrope', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.75), transparent 34%),
    radial-gradient(circle at bottom right, rgba(191, 164, 129, 0.24), transparent 26%),
    linear-gradient(180deg, #f6f0e8 0%, #e7ded1 100%);
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

.app-shell {
  min-height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.app-shell--fullscreen {
  padding: 0;
}

.phone-stage {
  width: min(100%, 920px);
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  margin: 0 auto;
  position: relative;
  display: flex;
  flex-direction: column;
  border-radius: 36px;
  overflow: hidden;
  background: rgba(255, 251, 247, 0.7);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
}

.phone-stage--fullscreen {
  width: 100%;
  min-height: 100dvh;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.screen {
  flex: 1;
  min-height: 0;
  position: relative;
}

.screen-pad {
  padding: 20px;
}

.hero-screen {
  background-size: cover;
  background-position: center;
}

.hero-screen--tap {
  cursor: pointer;
}

.hero-screen::before {
  content: '';
  position: absolute;
  inset: 0;
  background: transparent;
}

.hero-content {
  position: relative;
  z-index: 1;
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 20px;
  padding: 28px 24px 28px;
  color: #fff7ef;
}

.hero-content--center {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.eyebrow {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hero-title,
.panel-title {
  margin: 0;
  font-size: clamp(30px, 7vw, 56px);
  line-height: 0.95;
  font-weight: 800;
}

.hero-copy,
.panel-copy,
.status-copy {
  margin: 0;
  font-size: 16px;
  line-height: 1.5;
  color: inherit;
}

.panel-copy,
.status-copy {
  color: var(--muted);
}

.logo-mark {
  width: min(48vw, 220px);
}

.primary-button,
.secondary-button,
.ghost-button,
.tab-button,
.login-input {
  min-height: 48px;
}

.primary-button,
.secondary-button,
.ghost-button,
.tab-button,
.selection-card,
.action-card {
  border: 0;
  border-radius: 999px;
}

.primary-button,
.secondary-button,
.ghost-button {
  width: 100%;
  padding: 14px 18px;
  font-weight: 800;
}

.primary-button {
  background: var(--accent);
  color: #fff;
}

.primary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary-button {
  background: rgba(24, 21, 17, 0.08);
  color: var(--text);
}

.ghost-button {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(24, 21, 17, 0.12);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  overflow: hidden;
}

.panel-header {
  padding: 20px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.top-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.top-actions .ghost-button {
  width: auto;
  padding-inline: 18px;
}

.sticky-footer {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(239, 232, 220, 0) 0%, rgba(239, 232, 220, 0.95) 30%, rgba(239, 232, 220, 1) 100%);
  backdrop-filter: blur(12px);
}

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

.tab-button {
  padding: 12px 10px;
  font-size: 15px;
  font-weight: 800;
  background: rgba(24, 21, 17, 0.07);
  color: var(--muted);
}

.tab-button.is-active {
  background: var(--accent);
  color: #fff;
}

.selection-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 20px 20px;
  -webkit-overflow-scrolling: touch;
}

.selection-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding-bottom: 12px;
}

.selection-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  text-align: left;
  background: var(--panel-strong);
  box-shadow: 0 14px 26px rgba(40, 31, 22, 0.08);
  border-radius: 22px;
  border: 2px solid transparent;
  position: relative;
}

.selection-card.is-selected {
  border-color: #111111;
  box-shadow: 0 18px 28px rgba(17, 17, 17, 0.18);
}

.selection-check {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: #18a957;
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(24, 169, 87, 0.34);
  z-index: 2;
}

.selection-thumb {
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  overflow: hidden;
  background: #f3ece4;
}

.selection-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.selection-label {
  font-size: 14px;
  font-weight: 700;
}

.selection-hint {
  margin: 0;
  padding: 0 20px;
  font-size: 13px;
  color: var(--muted);
}

.camera-panel,
.result-panel,
.login-panel,
.status-panel {
  min-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.camera-shell,
.result-shell,
.login-card,
.status-card {
  margin: auto 20px 20px;
  padding: 18px;
  border-radius: var(--radius-xl);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}

.camera-shell--fullscreen,
.result-shell--fullscreen {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.camera-shell--portrait {
  width: min(100%, 640px);
  margin: 0 auto 16px;
}

.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 9 / 16;
  border-radius: 26px;
  overflow: hidden;
  background: #111;
}

.camera-stage--portrait {
  aspect-ratio: 9 / 16;
  min-height: 62dvh;
  max-height: min(78dvh, 980px);
}

.camera-shell--fullscreen .camera-stage {
  flex: 1;
  min-height: 0;
  height: auto;
  aspect-ratio: auto;
  border-radius: 0;
}

.camera-video,
.capture-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.camera-video,
.capture-preview {
  object-fit: cover;
  background: #111;
}

.camera-overlay {
  position: absolute;
  inset: auto 14px 14px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(17, 17, 17, 0.58);
  color: #fff;
  font-size: 14px;
  line-height: 1.45;
  backdrop-filter: blur(8px);
}

.camera-actions,
.result-actions,
.login-actions,
.stack-actions {
  display: grid;
  gap: 12px;
}

.camera-shell--portrait .camera-actions {
  margin-top: 16px;
}

.camera-shell--fullscreen .camera-actions,
.result-shell--fullscreen .result-actions {
  position: absolute;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 6;
}

.info-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(24, 21, 17, 0.08);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-wrap,
.status-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  z-index: 1;
}

.login-card,
.status-card {
  width: min(100%, 460px);
  margin: 0;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-input {
  width: 100%;
  padding: 0 16px;
  border-radius: 16px;
  border: 1px solid rgba(24, 21, 17, 0.12);
  background: rgba(255, 255, 255, 0.9);
  color: var(--text);
}

.field-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.error-box {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(179, 40, 33, 0.1);
  color: #8a231f;
  font-size: 14px;
  line-height: 1.5;
}

.result-grid {
  display: grid;
  gap: 16px;
}

.result-grid--single {
  grid-template-columns: minmax(0, 1fr);
  height: 100%;
}

.result-image-card {
  padding: 14px;
  border-radius: 24px;
  background: rgba(245, 239, 231, 0.92);
}

.result-image-card img {
  width: 100%;
  border-radius: 18px;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: #ddd2c1;
}

.result-shell--fullscreen .result-image-card {
  flex: 1;
  min-height: 0;
  height: auto;
  padding: 0;
  border-radius: 0;
  background: #111;
}

.result-shell--fullscreen .result-image-card img {
  height: 100%;
  border-radius: 0;
  aspect-ratio: auto;
}

.result-shell--fullscreen {
  padding-bottom: calc(144px + env(safe-area-inset-bottom));
}

.processing-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(9, 8, 7, 0.68);
  color: #fff;
  text-align: center;
  padding: 20px;
  z-index: 5;
}

.processing-card {
  width: min(100%, 300px);
  display: grid;
  gap: 14px;
}

.spinner {
  width: 52px;
  height: 52px;
  margin: 0 auto;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  animation: spin 0.9s linear infinite;
}

.landscape-warning {
  display: none;
}

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

@media (min-width: 768px) {
  .screen-pad,
  .panel-header,
  .selection-scroll,
  .sticky-footer,
  .camera-shell,
  .result-shell {
    padding-left: 28px;
    padding-right: 28px;
  }

  .selection-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
  }

  .result-grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
    align-items: start;
  }

  .camera-shell--fullscreen,
  .result-shell--fullscreen {
    padding-left: 0;
    padding-right: 0;
  }

  .camera-shell--portrait {
    width: min(100%, 720px);
  }
}

@media (orientation: landscape) and (max-width: 1024px) {
  .landscape-warning {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(17, 17, 17, 0.92);
    color: #fff;
    text-align: center;
    z-index: 999;
  }

  .landscape-warning-card {
    max-width: 320px;
    display: grid;
    gap: 10px;
  }

  .landscape-warning h2 {
    margin: 0;
    font-size: 28px;
  }

  .landscape-warning p {
    margin: 0;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.82);
  }
}
