:root {
  color-scheme: dark;
  --bg: #090909;
  --surface: #111111;
  --surface-2: #191919;
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.24);
  --text: #f5f3ef;
  --muted: #989894;
  --accent: #ff3434;
  --accent-ink: #130000;
  --danger: #ff6b6b;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 24px;
  --dur-fast: 150ms;
  --dur-base: 250ms;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; margin: 0; background: var(--bg); }
body { overflow-x: hidden; }
button, input { font: inherit; }
button { color: inherit; }

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(to bottom, #000, transparent 75%);
}

.boot {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 14px;
}

.boot-logo {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line-strong), 0 12px 32px rgba(0,0,0,.24);
  animation: boot-pulse 1.25s var(--ease) infinite alternate;
}

.app {
  position: relative;
  width: min(100%, 560px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) 18px calc(112px + var(--safe-bottom));
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  margin-bottom: clamp(34px, 8vh, 72px);
}

.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand img { object-fit: cover; border-radius: 50%; box-shadow: 0 0 0 1px rgba(255,255,255,.18); }
.brand div { display: grid; gap: 2px; min-width: 0; }
.brand strong { font-size: 15px; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }

.quota {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: rgba(20,20,20,.72);
  backdrop-filter: blur(14px);
}
.quota span { color: var(--muted); font-size: 11px; }
.quota strong { font-size: 16px; }
.quota time { grid-column: 1 / -1; margin-top: -5px; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.quota:has(time:not([hidden])) { padding-block: 7px; }

.screen { display: none; animation: screen-in var(--dur-base) var(--ease) both; }
.screen.active { display: block; }
.screen-head { margin-bottom: 26px; }
.screen-head.compact { margin-bottom: 20px; }
.step-label {
  display: block;
  margin-bottom: 11px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; max-width: 460px; font-size: clamp(34px, 10vw, 54px); line-height: .96; letter-spacing: -.055em; }
.screen-head p { max-width: 440px; margin-bottom: 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
h2 { margin-bottom: 0; font-size: 18px; letter-spacing: -.025em; }

.upload-card {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  max-height: 430px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  cursor: pointer;
  background-color: #111;
  background-image:
    linear-gradient(45deg, #191919 25%, transparent 25%),
    linear-gradient(-45deg, #191919 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #191919 75%),
    linear-gradient(-45deg, transparent 75%, #191919 75%);
  background-position: 0 0, 0 14px, 14px -14px, -14px 0;
  background-size: 28px 28px;
  transition: border-color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.upload-card:active { transform: scale(.995); }
.upload-card:focus-within { outline: 3px solid rgba(255,52,52,.28); outline-offset: 3px; }
.upload-card input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-empty { display: grid; justify-items: center; gap: 8px; padding: 30px; background: rgba(9,9,9,.86); border: 1px solid var(--line); border-radius: 22px; }
.upload-empty strong { font-size: 17px; }
.upload-empty small { color: var(--muted); }
.upload-icon { width: 48px; height: 48px; display: grid; place-items: center; color: var(--accent); }
.icon-box { border: 1px solid rgba(255,52,52,.22); border-radius: 15px; background: rgba(255,52,52,.08); }
.upload-icon svg { width: 27px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#source-preview { width: 100%; height: 100%; object-fit: contain; }
.replace-file { position: absolute; right: 14px; bottom: 14px; padding: 10px 14px; border-radius: 14px; background: rgba(0,0,0,.74); border: 1px solid rgba(255,255,255,.2); backdrop-filter: blur(12px); font-size: 13px; font-weight: 700; }
.field-error { min-height: 20px; margin: 9px 2px 0; color: var(--danger); font-size: 13px; line-height: 1.45; }
.file-facts { display: flex; justify-content: space-between; gap: 16px; padding: 12px 2px 0; color: var(--muted); font-size: 12px; }
.file-facts span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status-card {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 48px 1fr 24px;
  align-items: center;
  gap: 14px;
  margin-bottom: 30px;
  padding: 11px 13px;
  text-align: left;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface);
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.status-card:active { transform: scale(.99); }
.status-card.selected { border-color: var(--accent); }
.status-card span:nth-child(2) { display: grid; gap: 5px; min-width: 0; }
.status-card small { color: var(--muted); font-size: 11px; }
.status-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.status-card svg { width: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.status-orb { width: 48px; height: 48px; display: grid; place-items: center; overflow: hidden; border-radius: 16px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.22); }
.status-orb .gift-media { width: 45px; height: 45px; }

.collection-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; }
.collection-head span { color: var(--muted); font-size: 12px; }
.gift-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.gift-card {
  position: relative;
  min-height: 196px;
  display: grid;
  align-content: space-between;
  overflow: hidden;
  padding: 12px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--gift-gradient);
  cursor: pointer;
  isolation: isolate;
  transition: transform var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.gift-card::before { content: ""; position: absolute; inset: -10%; z-index: -2; opacity: .2; background-color: transparent; background-image: var(--gift-pattern-image, radial-gradient(circle, var(--gift-pattern, rgba(255,255,255,.18)) 0 2px, transparent 2.5px)); background-repeat: repeat; background-size: 34px 34px; transform: rotate(-7deg) scale(1.16); filter: saturate(.35) brightness(1.45); }
.gift-card::after { content: ""; position: absolute; inset: 0; z-index: -1; background: linear-gradient(to top, rgba(0,0,0,.76), transparent 66%); }
.gift-card:active { transform: scale(.98); }
.gift-card.selected { border-color: #fff; box-shadow: inset 0 0 0 2px #fff; }
.gift-media { display: block; width: 126px; height: 126px; justify-self: center; object-fit: contain; pointer-events: none; filter: drop-shadow(0 10px 18px rgba(0,0,0,.34)); }
.gift-card strong { color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; text-shadow: 0 1px 6px #000; }
.gift-check { position: absolute; right: 9px; top: 9px; width: 27px; height: 27px; display: grid; place-items: center; border-radius: 50%; background: #fff; color: #050505; font-size: 14px; font-weight: 900; opacity: 0; transform: scale(.7); transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }
.gift-card.selected .gift-check { opacity: 1; transform: scale(1); }
.collection-state { min-height: 150px; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); font-size: 13px; text-align: center; }
.loader { width: 28px; height: 28px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }

.device-field { margin: 28px 0 0; padding: 0; border: 0; }
.device-field legend { margin-bottom: 12px; font-size: 14px; font-weight: 700; }
.device-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.device-switch input { position: absolute; opacity: 0; }
.device-switch span { display: grid; place-items: center; min-height: 46px; border-radius: 13px; color: var(--muted); cursor: pointer; transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease); }
.device-switch input:checked + span { background: var(--text); color: #080808; font-weight: 750; }
.device-switch input:focus-visible + span { outline: 3px solid rgba(255,52,52,.3); }

.result-card { position: relative; margin: 0; overflow: hidden; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.result-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.result-loader { position: absolute; left: 50%; top: 50%; z-index: 1; width: 34px; height: 34px; margin: -17px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; opacity: 0; animation: spin .8s linear infinite; transition: opacity var(--dur-fast) var(--ease); }
.result-card.loading .result-loader { opacity: 1; }
.result-card.loading img { opacity: 0; }
.download-list { display: grid; gap: 9px; margin-top: 16px; }
.download-button { display: grid; grid-template-columns: 42px 1fr 24px; align-items: center; gap: 10px; min-height: 66px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); text-align: left; cursor: pointer; }
.download-button .download-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: var(--accent); color: #080808; font-size: 22px; }
.download-button .download-icon svg { width: 21px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.download-button span:nth-child(2) { display: grid; gap: 3px; }
.download-button strong { font-size: 14px; }
.download-button small { color: var(--muted); font-size: 11px; }
.download-button svg { width: 20px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.text-action { width: 100%; min-height: 52px; margin-top: 12px; border: 0; background: transparent; color: var(--muted); font-weight: 700; cursor: pointer; }

.error-screen { min-height: 62vh; place-content: center; text-align: center; }
.error-screen.active { display: grid; }
.error-screen h1 { font-size: 34px; }
.error-screen p { color: var(--muted); line-height: 1.5; }
.error-sign { width: 64px; height: 64px; margin: 0 auto 22px; display: grid; place-items: center; border-radius: 20px; background: var(--accent); color: #080808; font-size: 34px; font-weight: 900; }

.fallback-action { position: fixed; left: 18px; right: 18px; bottom: calc(14px + var(--safe-bottom)); z-index: 10; width: min(calc(100% - 36px), 524px); min-height: 56px; margin-inline: auto; border: 0; border-radius: 18px; background: var(--accent); color: var(--accent-ink); font-weight: 800; cursor: pointer; }
.fallback-action:disabled { opacity: .38; }
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-bottom)); z-index: 30; max-width: calc(100% - 36px); padding: 11px 15px; border: 1px solid var(--line-strong); border-radius: 14px; background: rgba(22,22,22,.94); color: var(--text); font-size: 13px; box-shadow: 0 18px 50px rgba(0,0,0,.34); opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: opacity var(--dur-base) var(--ease), transform var(--dur-base) var(--ease); }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 700px) {
  .app { padding-inline: 24px; }
  .gift-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .gift-card { min-height: 164px; }
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f4f2ef;
    --surface: #ffffff;
    --surface-2: #e9e7e4;
    --line: rgba(0,0,0,.1);
    --line-strong: rgba(0,0,0,.2);
    --text: #111111;
    --muted: #6d6b67;
    --accent-ink: #fff;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f2ef;
  --surface: #ffffff;
  --surface-2: #e9e7e4;
  --line: rgba(0,0,0,.1);
  --line-strong: rgba(0,0,0,.2);
  --text: #111111;
  --muted: #6d6b67;
  --accent-ink: #fff;
}

:root[data-theme="light"] .quota { background: rgba(255,255,255,.76); }
:root[data-theme="light"] .upload-empty { background: rgba(255,255,255,.88); }
:root[data-theme="light"] .toast { background: rgba(255,255,255,.96); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes boot-pulse { to { transform: scale(.92); opacity: .72; } }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } }
