:root {
  --text: #fff;
  --muted: rgba(255, 255, 255, .65);
  --glass: rgba(0, 0, 0, .38);
  --glass-strong: rgba(18, 18, 20, .82);
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --accent: #ffd60a;
  --danger: #ff453a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

[hidden] { display: none !important; }

/* ---------- Kamera ---------- */
.cam {
  position: fixed;
  inset: 0;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}

@media (min-width: 600px) {
  .cam {
    inset: auto;
    left: 50%;
    top: 50%;
    width: min(100vw, calc(100dvh * 9 / 16));
    height: min(100dvh, 900px);
    transform: translate(-50%, -50%);
    border-radius: 28px;
  }
  body { background: #111; }
  :fullscreen .cam { border-radius: 0; }
}

.cam video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: filter .25s;
}
.cam video.mirror { transform: scaleX(-1); }

/* Bingkai rasio: area di luar bingkai digelapkan seperti aplikasi kamera bawaan */
.frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: left .25s, top .25s, width .25s, height .25s, box-shadow .25s;
}
.frame.masked { box-shadow: 0 0 0 200vmax rgba(0, 0, 0, .88); }

.ratio-btn span { font-size: .68rem; font-weight: 700; letter-spacing: .02em; }

.guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  fill: none;
  stroke: rgba(255, 255, 255, .5);
  stroke-width: 1;
  overflow: visible;
}
.guide * { vector-effect: non-scaling-stroke; }
.guide .faint { stroke: rgba(255, 255, 255, .22); }
.guide .spiral { stroke: rgba(255, 255, 255, .75); stroke-width: 1.5; }

.message {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 32px;
  text-align: center;
  color: var(--muted);
  line-height: 1.5;
}
.message p { margin: 0; max-width: 300px; }

.pill {
  background: #fff;
  color: #000;
  font-weight: 600;
  padding: 10px 22px;
  border-radius: 999px;
}

.countdown {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 9rem;
  font-weight: 200;
  text-shadow: 0 4px 30px rgba(0,0,0,.5);
  pointer-events: none;
}
.countdown span { animation: pop 1s ease-out; }
@keyframes pop { from { transform: scale(1.6); opacity: 0; } 30% { opacity: 1; } to { transform: scale(1); } }

.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.on { animation: flash .4s ease-out; }
@keyframes flash { from { opacity: .85; } to { opacity: 0; } }

.toast {
  position: absolute;
  top: calc(var(--safe-top) + 72px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--glass-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: .85rem;
  max-width: calc(100% - 32px);
  text-align: center;
  z-index: 5;
  animation: fade 2.2s ease forwards;
}
@keyframes fade { 0% { opacity: 0; } 8%, 85% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Bar atas ---------- */
.top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: calc(var(--safe-top) + 14px) 16px 28px;
  background: linear-gradient(to bottom, rgba(0,0,0,.5), transparent);
}
.top-center { display: flex; gap: 10px; }

.icon-btn {
  position: relative;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform .15s, background .2s, color .2s, opacity .2s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.on { color: var(--accent); }
.icon-btn.plain { background: none; backdrop-filter: none; }
.icon-btn.big { width: 52px; height: 52px; }
.icon-btn.big svg { width: 26px; height: 26px; }
.icon-btn.spin svg { animation: spin .45s ease; }
@keyframes spin { to { transform: rotate(180deg); } }

.badge {
  position: absolute;
  bottom: -2px;
  right: -4px;
  background: var(--accent);
  color: #000;
  font-size: .65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 999px;
}

.rec-pill {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 20px);
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--danger);
  padding: 6px 14px;
  border-radius: 8px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: .95rem;
}
.rec-pill i { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Bar bawah ---------- */
.bottom {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 40px 0 calc(var(--safe-bottom) + 20px);
  background: linear-gradient(to top, rgba(0,0,0,.65) 40%, transparent);
}

.filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scroll-snap-type: x proximity;
  padding: 0 calc(50% - 40px) 14px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }

.filter {
  flex: none;
  scroll-snap-align: center;
  font-size: .75rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(0,0,0,.25);
  transition: color .2s, background .2s;
}
.filter.active { color: #000; background: #fff; }

.modes {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 14px;
}
.mode {
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 4px 2px;
  transition: color .2s;
}
.mode.active { color: var(--accent); }

.controls {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 32px;
}
.controls .thumb { justify-self: start; }
.controls .icon-btn { justify-self: end; }

.thumb {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,.85);
  background: rgba(255,255,255,.12);
  transition: transform .15s, opacity .2s;
}
.thumb:active { transform: scale(.9); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.bump { animation: bump .35s ease; }
@keyframes bump { 50% { transform: scale(1.15); } }

.shutter {
  position: relative;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 4px solid #fff;
  transition: transform .12s, opacity .2s;
}
.shutter::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: #fff;
  transition: inset .25s, border-radius .25s, background .25s, opacity .2s;
}
.shutter:active { transform: scale(.9); }
.shutter:disabled { opacity: .35; }
.shutter.busy::after { opacity: .5; }
.cam.video .shutter::after { background: var(--danger); }
.cam.recording .shutter::after { inset: 21px; border-radius: 6px; }

/* Saat merekam: sembunyikan kontrol yang tidak relevan */
.cam.recording #settingsBtn,
.cam.recording .top-center,
.cam.recording .filters,
.cam.recording .modes,
.cam.recording .thumb,
.cam.recording #switchBtn { opacity: 0; pointer-events: none; }
.cam.recording .rec-pill { display: flex; }

/* ---------- Galeri ---------- */
.sheet {
  position: fixed;
  inset: 0;
  background: #0b0b0c;
  z-index: 10;
  display: flex;
  flex-direction: column;
  animation: slideUp .28s cubic-bezier(.2,.8,.2,1);
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }

.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.05rem; }
#count { color: var(--muted); font-weight: 400; }

.text-btn { font-size: .9rem; padding: 8px; }
.text-btn.danger { color: var(--danger); }

.gallery-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-content: start;
  gap: 2px;
  padding-bottom: var(--safe-bottom);
}
@media (min-width: 600px) { .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); } }

.tile { position: relative; display: block; aspect-ratio: 1; overflow: hidden; background: #1a1a1a; }
.tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .dur {
  position: absolute;
  right: 6px;
  bottom: 6px;
  font-size: .72rem;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,.8);
}
.tile .dur::before { content: "▶ "; font-size: .6rem; }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px 24px calc(var(--safe-bottom) + 24px);
  color: var(--muted);
  text-align: center;
}
.empty svg { width: 64px; height: 64px; stroke-width: 1.2; opacity: .6; }
.empty p { margin: 0 0 8px; }

/* ---------- Penampil ---------- */
.viewer {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 20;
  display: flex;
  flex-direction: column;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }

.viewer-head {
  display: flex;
  align-items: center;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  font-size: .9rem;
  color: var(--muted);
}
.viewer-head span:first-of-type { flex: 1; text-align: center; }
.viewer-head .spacer { width: 44px; }

.viewer-stage { flex: 1; min-height: 0; display: flex; touch-action: pan-y; }
.viewer-stage img,
.viewer-stage video { width: 100%; height: 100%; object-fit: contain; background: #000; }

.viewer-actions {
  display: flex;
  justify-content: space-around;
  padding: 12px 16px calc(var(--safe-bottom) + 16px);
}

.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: .75rem;
  min-width: 72px;
  padding: 8px;
  border-radius: 12px;
}
.action:active { background: rgba(255,255,255,.1); }
.action.danger { color: var(--danger); }

/* ---------- Pengaturan ---------- */
.modal { position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); animation: fadeIn .2s ease; }
.modal-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(var(--safe-bottom) + 16px);
  animation: slideUp .3s cubic-bezier(.2,.8,.2,1);
}
.handle { width: 40px; height: 5px; border-radius: 3px; background: rgba(255,255,255,.25); margin: 0 auto 12px; }
.modal-panel h3 { margin: 0 0 8px; text-align: center; font-size: 1.05rem; }

.group-label { margin: 16px 4px 6px; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.group { background: var(--surface-2); border-radius: 14px; overflow: hidden; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px 14px;
  font-size: .95rem;
}
.row + .row { border-top: 1px solid rgba(255,255,255,.08); }
.row small { display: block; color: var(--muted); font-size: .75rem; margin-top: 2px; }
label.row { cursor: pointer; }

.seg { display: flex; background: rgba(0,0,0,.35); border-radius: 9px; padding: 2px; flex: none; }
.seg button { padding: 6px 10px; font-size: .8rem; border-radius: 7px; color: var(--muted); transition: background .2s, color .2s; }
.seg button.active { background: #636366; color: #fff; }

.switch {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 999px;
  background: #48484a;
  position: relative;
  cursor: pointer;
  transition: background .2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
  transition: transform .2s;
}
.switch:checked { background: #34c759; }
.switch:checked::after { transform: translateX(20px); }

.done-btn {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  border-radius: 14px;
  background: #fff;
  color: #000;
  font-weight: 600;
}

/* Layar landscape di HP: kontrol di samping */
@media (orientation: landscape) and (max-height: 500px) {
  .top { flex-direction: column; justify-content: flex-start; gap: 12px; right: auto; bottom: 0; padding: 16px; background: none; }
  .top-center { flex-direction: column; gap: 12px; }
  .bottom { left: auto; top: 0; width: 220px; padding: 16px; display: flex; flex-direction: column; justify-content: center; background: linear-gradient(to left, rgba(0,0,0,.6), transparent); }
  .filters { padding: 0 0 12px; }
  .controls { padding: 0; }
}
