:root {
  --sky-0: #f8fcff;
  --sky-1: #d9e9ff;
  --sky-2: #ffe9f3;
  --glass: rgba(255, 255, 255, 0.82);
  --glass-border: rgba(255, 255, 255, 0.95);
  --ink: #1f3f63;
  --soft: #587798;
  --shadow: 0 12px 30px rgba(72, 118, 170, 0.2);
  --radius: 24px;
  --btn-border: rgba(255, 255, 255, 0.98);
  --btn-shadow: 0 10px 22px rgba(66, 106, 146, 0.22);
  --btn-shadow-press: 0 4px 10px rgba(66, 106, 146, 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family:
    "SF Pro Rounded",
    "SF Pro Text",
    "PingFang SC",
    "Helvetica Neue",
    Arial,
    sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 6% 8%, #fff6c8 0, transparent 30%),
    radial-gradient(circle at 92% 5%, #ffd8ea 0, transparent 31%),
    linear-gradient(165deg, var(--sky-0), var(--sky-1) 50%, var(--sky-2));
}

.app-shell {
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 10px 12px 18px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.hero {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.badge {
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  color: #355578;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.96);
}

.hero h1 {
  margin: 0;
  font-size: clamp(30px, 7vw, 48px);
}

.flow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: 2px;
}

.flow span {
  min-width: 46px;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  color: #5b7a99;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.96);
}

.flow span.active {
  color: #12324e;
  background: linear-gradient(145deg, #fff2ad, #ffcc88);
}

.flow span.done {
  color: #166437;
  background: linear-gradient(145deg, #d9ffe9, #9ef3c5);
}

.hint {
  margin: 0 0 0 auto;
  font-size: 12px;
  color: var(--soft);
  text-align: right;
  max-width: 58%;
}

.stage-card {
  position: relative;
  padding: 10px;
  border-radius: var(--radius);
  background: var(--glass);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

#stage {
  display: block;
  width: 100%;
  max-height: 67vh;
  border-radius: 18px;
  background: #9cb8d4;
  touch-action: none;
}

#camera {
  position: absolute;
  left: -99999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.status {
  position: absolute;
  left: 18px;
  bottom: 18px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(255, 255, 255, 0.95);
  font-size: 14px;
  font-weight: 700;
  color: #2b4968;
}

.auto-dock {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(96px, 130px) 1fr minmax(96px, 130px);
  align-items: center;
  gap: 10px;
  transition: all 160ms ease;
}

.mini-btn {
  border: 1px solid var(--btn-border);
  border-radius: 18px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 1),
    inset 0 -8px 18px rgba(255, 255, 255, 0.18),
    var(--btn-shadow);
  transition:
    transform 120ms ease,
    filter 140ms ease,
    box-shadow 180ms ease;
}

.mini-btn::after {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent 52%);
  mix-blend-mode: screen;
}

.mini-btn:active {
  transform: translateY(2px) scale(0.98);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    inset 0 -3px 8px rgba(255, 255, 255, 0.12),
    var(--btn-shadow-press);
}

.mini-btn {
  min-height: 74px;
  font-size: 30px;
  background:
    radial-gradient(circle at 20% 15%, rgba(255, 255, 255, 0.86), transparent 35%),
    linear-gradient(165deg, rgba(255, 255, 255, 0.98), rgba(227, 242, 255, 0.9));
}

.mini-btn:hover {
  filter: brightness(1.04);
}

.mini-btn:focus-visible,
.opt-btn:focus-visible {
  outline: 3px solid rgba(114, 201, 255, 0.8);
  outline-offset: 2px;
}

.mini-btn:disabled,
.shutter-btn:disabled {
  opacity: 0.46;
  cursor: not-allowed;
}

.done-btn {
  font-size: 24px;
}

.shutter-wrap {
  justify-self: center;
  width: 132px;
  height: 132px;
  border-radius: 999px;
  position: relative;
  display: grid;
  place-items: center;
  background:
    conic-gradient(#32c36c var(--progress), rgba(200, 222, 240, 0.35) 0),
    radial-gradient(circle, rgba(255, 255, 255, 0.95) 63%, transparent 64%);
  box-shadow: 0 10px 24px rgba(64, 117, 168, 0.22);
}

.shutter-wrap.recording {
  animation: pulseRecord 800ms ease-in-out infinite;
  box-shadow:
    0 0 0 5px rgba(54, 201, 106, 0.22),
    0 12px 24px rgba(64, 117, 168, 0.24);
}

.shutter-wrap.locked::after {
  content: "REC";
  position: absolute;
  top: -8px;
  right: -6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
  color: #fff;
  background: #ff5a45;
  border: 1px solid rgba(255, 255, 255, 0.95);
}

.shutter-wrap.recording .shutter-btn {
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.78), transparent 33%),
    linear-gradient(155deg, #ffcdc2, #ff7a68 55%, #e25544);
}

.shutter-btn {
  width: 94px;
  height: 94px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 1);
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.95), transparent 33%),
    linear-gradient(155deg, #fff7bf, #ffd782 52%, #ffb56f);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 8px 16px rgba(79, 123, 165, 0.2);
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

.shutter-btn:active {
  transform: scale(0.96);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 4px 10px rgba(79, 123, 165, 0.2);
}

.result-card {
  margin-top: 12px;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.option-card {
  margin-top: 10px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--glass-border);
  background: var(--glass);
  box-shadow: var(--shadow);
}

body[data-ui-mode="capture"] .option-card,
body[data-ui-mode="capture"] .result-card,
body[data-ui-mode="capture"] #addTextBtn,
body[data-ui-mode="capture"] #doneBtn {
  display: none;
}

body[data-ui-mode="capture"] .auto-dock {
  grid-template-columns: 1fr;
  justify-items: center;
}

body[data-ui-mode="recording"] .result-card {
  display: none;
}

body[data-ui-mode="saved"] .option-card,
body[data-ui-mode="saved"] .result-card,
body[data-ui-mode="saved"] #addTextBtn,
body[data-ui-mode="saved"] #doneBtn {
  display: none;
}

body[data-ui-mode="saved"] .auto-dock {
  grid-template-columns: 1fr;
  justify-items: center;
}

.option-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
}

.option-row + .option-row {
  margin-top: 8px;
}

.opt-btn {
  border: 1px solid rgba(255, 255, 255, 1);
  background:
    radial-gradient(circle at 18% 20%, rgba(255, 255, 255, 0.8), transparent 30%),
    linear-gradient(165deg, rgba(255, 255, 255, 0.96), rgba(233, 245, 255, 0.86));
  color: var(--ink);
  border-radius: 999px;
  min-height: 38px;
  padding: 0 15px;
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 6px 14px rgba(76, 118, 156, 0.16);
  transition:
    transform 120ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

#effectOptions .opt-btn {
  min-height: 48px;
  padding: 0 18px;
  font-size: 16px;
  border-radius: 14px;
}

#effectOptions {
  padding-bottom: 8px;
}

.opt-btn.active {
  background:
    radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.75), transparent 32%),
    linear-gradient(150deg, #fff5a9, #ffc882);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 8px 18px rgba(227, 151, 61, 0.24);
}

.opt-btn:active {
  transform: translateY(1px) scale(0.98);
}

#resultVideo,
#resultImage {
  width: 100%;
  min-height: 120px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.95);
  background: #c9d7e8;
  object-fit: cover;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 680px) {
  .hint {
    display: none;
  }
  .auto-dock {
    grid-template-columns: minmax(86px, 108px) 1fr minmax(86px, 108px);
    gap: 8px;
  }
  .mini-btn {
    min-height: 64px;
    border-radius: 16px;
  }
  .mini-btn {
    font-size: 24px;
  }
  .done-btn {
    font-size: 21px;
  }
  .shutter-wrap {
    width: 114px;
    height: 114px;
  }
  .shutter-btn {
    width: 82px;
    height: 82px;
  }
  .result-card {
    grid-template-columns: 1fr;
  }
  .opt-btn {
    min-height: 34px;
    font-size: 13px;
    padding: 0 12px;
  }
  #effectOptions .opt-btn {
    min-height: 42px;
    padding: 0 14px;
    font-size: 14px;
  }
  .flow {
    width: 100%;
    order: 10;
  }
  .flow span {
    flex: 1;
    min-width: 0;
  }
}

@media (orientation: landscape) and (min-width: 900px) {
  body.ipad-landscape .app-shell {
    max-width: 1200px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 250px;
    grid-template-areas:
      "hero hero"
      "stage dock"
      "stage options"
      "stage result";
    gap: 10px;
    align-items: start;
  }

  body.ipad-landscape .hero {
    grid-area: hero;
    margin-bottom: 0;
  }

  body.ipad-landscape .stage-card {
    grid-area: stage;
  }

  body.ipad-landscape .auto-dock {
    grid-area: dock;
    margin-top: 0;
    grid-template-columns: 1fr;
    gap: 8px;
    justify-items: center;
  }

  body.ipad-landscape .mini-btn {
    min-height: 62px;
    width: 100%;
    font-size: 22px;
  }

  body.ipad-landscape .shutter-wrap {
    width: 118px;
    height: 118px;
  }

  body.ipad-landscape .shutter-btn {
    width: 86px;
    height: 86px;
  }

  body.ipad-landscape .result-card {
    grid-area: result;
    margin-top: 0;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  body.ipad-landscape .option-card {
    grid-area: options;
    margin-top: 0;
    padding: 12px;
  }

  body.ipad-landscape .option-row {
    gap: 6px;
  }

  body.ipad-landscape .opt-btn {
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }
  body.ipad-landscape #effectOptions .opt-btn {
    min-height: 44px;
    padding: 0 13px;
    font-size: 14px;
  }

  body.ipad-landscape #resultVideo,
  body.ipad-landscape #resultImage {
    min-height: 96px;
    max-height: 154px;
  }

  body.ipad-landscape .hint {
    max-width: 68%;
  }
}

@keyframes pulseRecord {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.02);
  }
  100% {
    transform: scale(1);
  }
}
