:root {
  color-scheme: light;
  --paper: #f4f1e8;
  --card: #fffefa;
  --ink: #191a17;
  --muted: #67675f;
  --line: #d9d5c9;
  --orange: #f05b35;
  --orange-dark: #ca3f1d;
  --yellow: #f3c84b;
  --green: #28795c;
  --shadow: 0 10px 28px rgba(50, 45, 30, 0.08);
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 4%, rgba(243, 200, 75, 0.24), transparent 24rem),
    var(--paper);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, a { font: inherit; }

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

.app {
  width: min(100%, 520px);
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}

.intro {
  display: flex;
  align-items: center;
  gap: 13px;
  margin: 2px 2px 24px;
}

.mark {
  display: grid;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  place-items: center;
  border-radius: 50%;
  background: var(--yellow);
  font-size: 25px;
  transform: rotate(-7deg);
}

h1, h2, p { margin: 0; }

h1 {
  font-size: clamp(28px, 9vw, 38px);
  line-height: 1;
  letter-spacing: -0.045em;
}

.intro p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 15px;
}

.card {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid rgba(25, 26, 23, 0.08);
  border-radius: 20px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

h2 {
  font-size: 18px;
  letter-spacing: -0.02em;
}

.counter, output {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

.counter {
  padding: 5px 9px;
  border-radius: 999px;
  background: #eeece4;
}

.source-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.button {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.button:active:not(:disabled) { transform: translateY(2px); }

.button:focus-visible, .frame-action:focus-visible, .slider:focus-visible,
.preview-open:focus-visible, .preview-close:focus-visible, .format-checkbox:focus-visible {
  outline: 3px solid rgba(40, 121, 92, 0.32);
  outline-offset: 3px;
}

.button-primary {
  color: white;
  background: var(--ink);
}

.button-primary span { color: var(--orange); }

.button-secondary {
  border: 1.5px solid var(--line);
  background: white;
  color: var(--ink);
}

.button-secondary span { font-size: 20px; }

.hint {
  margin-top: 13px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.frames {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  padding: 2px 1px 5px;
  overflow-x: auto;
  overscroll-behavior-inline: contain;
  scroll-snap-type: x proximity;
}

.frames:empty { display: none; }

.frame {
  position: relative;
  flex: 0 0 76px;
  scroll-snap-align: start;
}

.frame img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid white;
  border-radius: 12px;
  background: #ece9df;
  box-shadow: 0 0 0 1px var(--line);
  object-fit: cover;
}

.frame-number {
  position: absolute;
  top: 5px;
  left: 5px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: rgba(25, 26, 23, 0.82);
  font-size: 11px;
  font-weight: 850;
}

.frame-tools {
  display: flex;
  justify-content: center;
  gap: 2px;
  margin-top: 6px;
}

.frame-action {
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.frame-action:disabled { opacity: 0.22; cursor: default; }
.frame-action.remove { color: var(--orange-dark); }

.error {
  margin-top: 12px;
  color: var(--orange-dark);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.slider {
  width: 100%;
  height: 28px;
  margin: 0;
  accent-color: var(--orange);
  cursor: pointer;
}

.scale {
  display: flex;
  justify-content: space-between;
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.result {
  margin-bottom: 14px;
  padding: 22px 18px;
  border-radius: 22px;
  background: var(--card);
  box-shadow: var(--shadow);
}

.preview-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.preview-status {
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}

.preview-open {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: #ece9df;
  cursor: zoom-in;
  overflow: hidden;
}

#gif-preview {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto;
  background: #ece9df;
  object-fit: cover;
}

.preview-expand {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 7px 10px;
  border-radius: 999px;
  color: white;
  background: rgba(25, 26, 23, 0.78);
  font-size: 11px;
  font-weight: 800;
  backdrop-filter: blur(5px);
}

.format-card { padding-block: 16px; }

.format-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  cursor: pointer;
}

.format-option span { display: grid; gap: 4px; }

.format-option strong { font-size: 16px; }

.format-option small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.format-checkbox {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--orange);
  cursor: pointer;
}

.preview-dialog {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border: 0;
  background: rgba(8, 9, 8, 0.96);
}

.preview-dialog[open] {
  display: grid;
  place-items: center;
}

.preview-dialog::backdrop { background: rgba(8, 9, 8, 0.96); }

.fullscreen-preview {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.preview-close {
  position: fixed;
  z-index: 1;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: grid;
  width: 46px;
  height: 46px;
  padding: 0 0 4px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: white;
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
  font-size: 32px;
  line-height: 1;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.button-download {
  width: 100%;
  color: white;
  background: var(--green);
}

.button-download.is-disabled {
  color: #9c9a93;
  background: #dedbd2;
  cursor: wait;
  pointer-events: none;
}

.button-reset { width: 100%; }

footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 22px 8px 2px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

footer span { color: var(--green); }

.privacy-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

footer p { margin: 0; }

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

[hidden] { display: none !important; }

@media (max-width: 370px) {
  .source-buttons { grid-template-columns: 1fr; }
  .card { padding: 16px; }
  .button { min-height: 50px; }
}

@media (min-width: 700px) {
  .app { padding-top: 44px; }
}

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