:root {
  --bg: #111114;
  --text: #f7f7fb;
  --muted: #b8b8c5;
  --line: rgba(255, 255, 255, 0.12);
  --accent: #ff5a7a;
  --accent2: #ffcc66;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at top, #2a2035 0, #111114 42%, #08080a 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 22px 18px calc(26px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
}

.screen { display: none; width: 100%; animation: fadeIn 180ms ease-out; }
.screen.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand-badge {
  display: inline-flex;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent2);
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: clamp(32px, 9vw, 48px);
  line-height: 1.05;
  letter-spacing: -0.06em;
  margin-bottom: 12px;
}

h2 {
  font-size: 32px;
  letter-spacing: -0.05em;
  margin-bottom: 8px;
}

.subtitle, .select-header p, .result-header p {
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

.frame-preview-wrap {
  width: 100%;
  background: linear-gradient(145deg, rgba(255,255,255,0.12), rgba(255,255,255,0.03));
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 16px;
  margin: 22px 0;
}

.frame-preview {
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  display: block;
  border-radius: 20px;
  background:
    linear-gradient(45deg, rgba(255,255,255,.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,.08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,.08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,.08) 75%);
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0px;
}

.notice {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 20px;
  padding: 16px;
  margin: 20px 0;
  display: grid;
  gap: 6px;
}

.notice strong { font-size: 14px; }
.notice span { font-size: 14px; color: var(--muted); line-height: 1.5; }

.primary-btn, .secondary-btn, .ghost-wide-btn, .ghost-btn {
  border: none;
  cursor: pointer;
  font-weight: 900;
  transition: transform 120ms ease, opacity 120ms ease;
}

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

.primary-btn:active, .secondary-btn:active, .ghost-wide-btn:active, .ghost-btn:active {
  transform: scale(0.98);
}

.primary-btn {
  width: 100%;
  min-height: 58px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--accent), #ff875a);
  color: #fff;
  font-size: 17px;
  box-shadow: 0 14px 36px rgba(255, 90, 122, 0.24);
}

.secondary-btn {
  width: 100%;
  min-height: 54px;
  border-radius: 18px;
  background: #fff;
  color: #17171b;
  font-size: 16px;
}

.ghost-wide-btn {
  width: 100%;
  min-height: 52px;
  border-radius: 18px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 16px;
}

.ghost-btn {
  min-height: 36px;
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 12px;
}

.ghost-link {
  display: grid;
  place-items: center;
  min-height: 52px;
  border-radius: 18px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  border: 1px solid var(--line);
  text-decoration: none;
  font-weight: 900;
}

.demo-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

.demo-links span { width: 100%; }
.demo-links a {
  color: var(--text);
  text-decoration: none;
  padding: 8px 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.shot-status {
  font-size: 15px;
  font-weight: 1000;
  color: var(--accent2);
}

.camera-wrap {
  position: relative;
  width: 100%;
  overflow: hidden;
  border-radius: 28px;
  background: #000;
  border: 1px solid var(--line);
  aspect-ratio: 3 / 4;
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(86px, 30vw, 150px);
  font-weight: 1000;
  color: white;
  text-shadow: 0 10px 28px rgba(0,0,0,0.5);
  background: rgba(0,0,0,0.08);
}

.flash {
  position: absolute;
  inset: 0;
  background: white;
  opacity: 0.9;
  animation: flash 260ms ease-out forwards;
}

@keyframes flash { to { opacity: 0; } }
.hidden { display: none !important; }

.help-text {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  margin: 14px 0;
  text-align: center;
}

.camera-actions, .result-actions, .select-actions {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.thumbs img, .select-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.select-header {
  text-align: center;
  margin-bottom: 18px;
}

.select-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.select-card {
  position: relative;
  border: 2px solid var(--line);
  background: rgba(255,255,255,0.06);
  border-radius: 18px;
  padding: 8px;
  cursor: pointer;
}

.select-card.selected {
  border-color: var(--accent2);
  box-shadow: 0 0 0 4px rgba(255, 204, 102, 0.18);
}

.select-number {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--accent2);
  color: #111;
  font-weight: 1000;
  opacity: 0;
}

.select-card.selected .select-number {
  opacity: 1;
}

.result-header {
  text-align: center;
  margin-bottom: 18px;
}

.result-image {
  display: block;
  width: min(100%, 390px);
  margin: 0 auto;
  border-radius: 22px;
  border: 1px solid var(--line);
  box-shadow: 0 20px 70px rgba(0,0,0,0.45);
  background: #222;
}

.tiny-note {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  margin-top: 12px;
  line-height: 1.5;
}

.error-detail {
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.06);
  border-radius: 16px;
  padding: 12px;
  color: #ffbdc9;
  max-height: 160px;
  overflow: auto;
}

@media (min-width: 900px) {
  .app-shell { width: min(100%, 820px); }
  .camera-wrap { aspect-ratio: 16 / 10; }
  .camera-actions, .result-actions, .select-actions {
    max-width: 440px;
    margin-left: auto;
    margin-right: auto;
  }
  .select-grid { grid-template-columns: repeat(4, 1fr); }
}
