:root {
  --bg: #ebedf4;
  --panel: #fff;
  --ink: #0f1325;
  --muted: #5e6578;
  --line: #dcdfea;
  --accent: #2f5bff;
  --on: #fff;
  --bad: #b42318;
  --frame: #0f1325;
  --stage: #0b0f1e;
  --r: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #090c16;
    --panel: #121726;
    --ink: #e9ecf6;
    --muted: #98a0b6;
    --line: #232a3e;
    --accent: #7c98ff;
    --on: #0a1033;
    --bad: #ff8a80;
    --frame: #2a3350;
    --stage: #05070e;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    15px/1.45 "SF Pro Text",
    "Segoe UI",
    system-ui,
    sans-serif;
  padding: max(16px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

main {
  max-width: 62rem;
  margin: 0 auto;
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.8rem;
  margin: 0 0.2rem 1rem;
}

h1 {
  font:
    800 var(--t-xl)/1 ui-rounded,
    "SF Pro Rounded",
    system-ui,
    sans-serif;
  letter-spacing: -0.03em;
  margin: 0;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: var(--t-md);
}

h2 {
  font-size: var(--t-sm);
  font-weight: 600;
  margin: 0 0 0.55rem;
}

[hidden] {
  display: none !important;
}

.app {
  display: grid;
  gap: 1rem;
}

@media (min-width: 880px) {
  .app {
    grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
  }

  .stagecol {
    position: sticky;
    top: 1rem;
  }
}

.stagecol {
  display: grid;
  justify-items: center;
  gap: 0.7rem;
}

#phone {
  position: relative;
  width: 100%;
  max-width: min(300px, calc((100svh - 160px) * 0.5625));
  aspect-ratio: 9/16;
  border-radius: 32px;
  background: var(--stage);
  overflow: hidden;
  isolation: isolate;
  box-shadow:
    0 0 0 6px var(--frame),
    0 22px 40px -20px rgba(10, 16, 48, 0.55);
}

#phone .m {
  position: absolute;
  inset: 0;
}

#phone .m > * {
  position: absolute;
  width: 100%;
  height: 100%;
}

#phone .fg {
  object-fit: contain;
}

#phone[data-layout="crop"] .fg {
  object-fit: cover;
  cursor: grab;
  touch-action: none;
}
#phone[data-layout="crop"] .fg:active {
  cursor: grabbing;
}
@keyframes bouncePrev {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.04);
  }
}
#phone[data-fx="bounce"] .fg {
  animation: bouncePrev 1.8s ease-in-out infinite;
}

#phone .bg {
  object-fit: cover;
  filter: blur(22px) brightness(0.75);
  transform: scale(1.35);
}

#phone:not([data-layout="blur"]) .bg {
  display: none;
}

.grid {
  display: grid;
  gap: 2px;
}

.grid[data-n="2"] {
  grid-template-rows: 1fr 1fr;
}

.grid[data-n="3"],
.grid[data-n="4"] {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.grid[data-n="3"] img:first-child {
  grid-column: 1/3;
}

#phone .grid img {
  position: static;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#phone.noprev .m::after {
  content: "Pratinjau tidak tersedia untuk format ini. Tetap bisa diproses.";
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding: 2rem;
  text-align: center;
  color: #fff;
  font-size: var(--t-sm);
}

#phone.has::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(
    rgba(0, 0, 0, 0.4),
    transparent 18%,
    transparent 80%,
    rgba(0, 0, 0, 0.4)
  );
}

#segs {
  position: absolute;
  z-index: 2;
  inset: 12px 12px auto;
  display: flex;
  gap: 3px;
}

#segs i {
  position: relative;
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.38);
  overflow: hidden;
}

#segs i:first-child::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #fff;
  transform-origin: left;
  animation: fill 7s linear infinite;
}

@keyframes fill {
  from {
    transform: scaleX(0);
  }

  to {
    transform: scaleX(1);
  }
}

.who,
.reply {
  position: absolute;
  z-index: 2;
  color: #fff;
  font-size: var(--t-xs);
}

.who {
  top: 24px;
  left: 14px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.reply {
  left: 12px;
  right: 12px;
  bottom: 12px;
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 99px;
  color: rgba(255, 255, 255, 0.8);
}

#phone:not(.has) :is(#segs, .who, .reply) {
  display: none;
}

.drop {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-content: center;
  gap: 0.45rem;
  padding: 1.6rem;
  text-align: center;
  cursor: pointer;
  color: #c4cbe4;
  font-size: var(--t-sm);
  line-height: 1.4;
}

.drop strong {
  color: #fff;
  font-size: var(--t-lg);
  letter-spacing: -0.01em;
}

.drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

#phone:not(.has) .drop {
  outline: 1.5px dashed rgba(255, 255, 255, 0.28);
  outline-offset: -14px;
  border-radius: 32px;
}

.drop:focus-within,
.drop.over {
  outline: 2px solid var(--accent) !important;
  outline-offset: -10px;
}

#phone.has .drop {
  inset: auto auto 56px 50%;
  transform: translateX(-50%);
  width: max-content;
  padding: 0.4rem 0.95rem;
  border-radius: 99px;
  background: rgba(10, 14, 30, 0.6);
  backdrop-filter: blur(8px);
}

#phone.has .drop span {
  display: none;
}

#phone.has .drop strong {
  font-size: var(--t-sm);
  font-weight: 600;
}

#chips {
  list-style: none;
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 300px;
  font-size: var(--t-sm);
  color: var(--muted);
}

#chips li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.15rem 0;
}

#chips span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctl {
  display: grid;
  gap: 0.75rem;
  align-content: start;
  min-width: 0;
}

#f {
  background: var(--panel);
  border-radius: 22px;
  padding: 0.2rem 1.1rem 1.1rem;
}

.card {
  padding: 1rem 0;
  border-bottom: 1px solid var(--line);
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

details.adv {
  border-bottom: 1px solid var(--line);
}

details.adv > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  padding: 1rem 0;
  font-size: var(--t-sm);
  font-weight: 600;
}

details.adv > summary::-webkit-details-marker {
  display: none;
}

details.adv > summary::after {
  content: "+";
  color: var(--muted);
}

details.adv[open] > summary::after {
  content: "\2013";
}

details.adv .card {
  border: 0;
  padding: 0.2rem 0 1rem;
}

.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  background: var(--bg);
  padding: 3px;
  border-radius: 12px;
}

.seg label {
  position: relative;
  min-width: 0;
}

.seg input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.seg span {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 2.4rem;
  padding: 0.4rem 0.25rem;
  border-radius: 9px;
  font-size: var(--t-sm);
  text-align: center;
  color: var(--muted);
  transition:
    background 0.15s,
    color 0.15s;
}

.seg input:checked + span {
  background: var(--ink);
  color: var(--panel);
  font-weight: 600;
}

.seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.seg input:disabled + span {
  opacity: 0.35;
}

.g {
  width: 1.1rem;
  aspect-ratio: 9/16;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  color: inherit;
  --cut: var(--bg);
}

.seg input:checked + span .g {
  --cut: var(--ink);
}

.g-blur {
  background:
    linear-gradient(currentColor, currentColor) center/100% 36% no-repeat,
    color-mix(in srgb, currentColor 30%, transparent);
}

.g-fit {
  background: linear-gradient(currentColor, currentColor) center/100% 36%
    no-repeat;
}

.g-crop {
  background: currentColor;
}

.g-grid {
  background:
    linear-gradient(
      90deg,
      transparent calc(50% - 1px),
      var(--cut) 0 calc(50% + 1px),
      transparent 0
    ),
    linear-gradient(
      transparent calc(50% - 1px),
      var(--cut) 0 calc(50% + 1px),
      transparent 0
    ),
    currentColor;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
}

input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#audio {
  width: 100%;
  font-size: var(--t-md);
  color: var(--muted);
}

#audio::file-selector-button {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 99px;
  padding: 0.45rem 0.9rem;
  margin-right: 0.7rem;
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}

label:has(> input[type="checkbox"]) {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: var(--t-md);
}

input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  margin: 0.1rem 0 0;
  accent-color: var(--accent);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field + .field {
  margin-top: 0.75rem;
}

.hint {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: var(--t-sm);
}

button,
.btn {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: var(--r);
  padding: 0.9rem 1rem;
  background: var(--accent);
  color: var(--on);
  width: 100%;
  cursor: pointer;
  display: block;
  text-align: center;
  text-decoration: none;
  transition: transform 0.1s;
}

button:active {
  transform: scale(0.99);
}

button:disabled {
  opacity: 0.5;
  cursor: progress;
}

.btn.sm {
  width: auto;
  padding: 0.4rem 0.9rem;
  font-size: var(--t-sm);
  border-radius: 99px;
  background: var(--bg);
  color: var(--ink);
}

#go {
  margin-top: 1rem;
}

#status,
#results .card {
  background: var(--panel);
  border: 0;
  border-radius: 22px;
  padding: 1.1rem;
}

#status.err {
  color: var(--bad);
}

#stage {
  display: flex;
  justify-content: space-between;
  font-size: var(--t-md);
}

.bar {
  height: 6px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
  margin: 0.6rem 0 0.8rem;
}

.bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s;
}

.bar.ind i {
  width: 35%;
  animation: slide 1.1s ease-in-out infinite alternate;
}

@keyframes slide {
  to {
    margin-left: 65%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bar.ind i {
    animation: none;
    margin-left: 30%;
  }

  #segs i:first-child::after {
    animation: none;
    transform: scaleX(0.4);
  }
}

.warn {
  color: var(--muted);
  font-size: var(--t-md);
  margin: 0.5rem 0 0;
}

.err-note {
  color: var(--bad);
  margin: 0.75rem 0 0;
}

.res {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: var(--t-md);
}

.res + video,
.res + img {
  width: 100%;
  max-height: 22rem;
  object-fit: contain;
  background: #000;
  border-radius: 14px;
  display: block;
}

.clip {
  position: relative;
  height: 46px;
  margin-top: 0.7rem;
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
}

#clipWin,
#vWin {
  position: absolute;
  top: 0;
  bottom: 0;
  min-width: 6px;
  border-radius: 10px;
  background: var(--accent);
  opacity: 0.6;
  pointer-events: none;
}

.clip input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
}

#vprev {
  width: 100%;
  max-height: 260px;
  background: #000;
  border-radius: 14px;
  display: block;
  margin-bottom: 0.7rem;
}

.card .btn {
  margin-top: 0.7rem;
}

/* --- Tactile Studio Upgrades --- */
#durVal,
#loopVal,
#pct,
#clipInfo,
#trimInfo,
#chips li span:last-child,
.t-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-left: auto;
}

.badge {
  font:
    600 var(--t-xs)/1.2 ui-monospace,
    "SF Mono",
    Consolas,
    monospace;
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  letter-spacing: -0.02em;
}

#phone .cap-live {
  position: absolute;
  z-index: 2;
  left: 12px;
  right: 12px;
  bottom: 52px;
  color: #fff;
  font-size: var(--t-xs);
  line-height: 1.35;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  background: rgba(8, 11, 22, 0.52);
  padding: 0.35rem 0.6rem;
  border-radius: 10px;
  backdrop-filter: blur(6px);
  pointer-events: none;
  word-break: break-word;
  max-height: 4.5rem;
  overflow: hidden;
}

#phone.safe-guide::after {
  content: "AREA AMAN STORY";
  position: absolute;
  z-index: 2;
  inset: 9% 3% 16%;
  border: 1px dashed rgba(255, 255, 255, 0.45);
  border-radius: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 6px 8px;
  font:
    600 var(--t-2xs)/1 ui-monospace,
    monospace;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.65);
  pointer-events: none;
}

.stage-tools {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  width: 100%;
  max-width: 300px;
}

.pill-toggle {
  font-size: var(--t-xs);
  line-height: 1;
  font-weight: 600;
  padding: 0.38rem 0.7rem;
  border-radius: 99px;
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--line);
  width: auto;
  cursor: pointer;
}

.pill-toggle[aria-pressed="true"] {
  background: var(--ink);
  color: var(--panel);
  border-color: var(--ink);
}

.clip {
  border: 1px solid var(--line);
}

.clip canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.55;
}

#clipWin,
#vWin {
  border-left: 3px solid var(--ink);
  border-right: 3px solid var(--ink);
  box-sizing: border-box;
}

.mix-box {
  margin-top: 0.75rem;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  background: var(--bg);
  display: grid;
  gap: 0.55rem;
}

.mix-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr 2.6rem;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--t-sm);
}

.mix-row span:last-child {
  text-align: right;
  font-family: ui-monospace, monospace;
  color: var(--muted);
}

/* --- Tambahan Bagian 2 --- */
input[type="text"],
input[type="password"],
textarea {
  font-size: 16px;
}

/* cegah zoom otomatis iOS */
.seg span {
  min-height: 2.75rem;
}

@media (pointer: coarse) {
  .btn.sm,
  .pill-toggle {
    min-height: 44px;
  }
}

.actbar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  margin: 1rem -1.1rem -1.1rem;
  padding: 0.7rem 1.1rem max(0.8rem, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 0 0 22px 22px;
}

.actbar #go {
  margin-top: 0;
}

.sum {
  margin: 0 0 0.5rem;
  color: var(--muted);
  font:
    600 var(--t-sm)/1.3 ui-monospace,
    "SF Mono",
    Consolas,
    monospace;
  font-variant-numeric: tabular-nums;
}

.qr {
  margin-left: auto;
  position: relative;
}

.qr summary {
  list-style: none;
  cursor: pointer;
  font-size: var(--t-sm);
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border-radius: 99px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.qr summary::-webkit-details-marker {
  display: none;
}

.qr img {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  z-index: 30;
  width: 148px;
  height: 148px;
  padding: 8px;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 14px 30px -12px rgba(10, 16, 48, 0.5);
}

/* HP: setelah file dipilih, pratinjau mengecil dan menempel di atas */
@media (max-width: 879px) {
  .app {
    display: block;
  }

  /* sticky tidak jalan di item grid satu kolom */
  .stagecol {
    margin-bottom: 0.8rem;
  }

  .stagecol:has(#phone.has) {
    position: sticky;
    top: 0;
    z-index: 20;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    justify-items: stretch;
    gap: 0.4rem 0.9rem;
    margin: 0 -14px 0.8rem;
    padding: max(10px, env(safe-area-inset-top)) 14px 10px;
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--line);
  }

  .stagecol:has(#phone.has) #phone {
    grid-row: 1 / span 2;
    width: calc(22svh * 0.5625);
    max-width: 36vw;
    border-radius: 18px;
    box-shadow: 0 0 0 3px var(--frame);
  }

  .stagecol:has(#phone.has) :is(.stage-tools, #chips) {
    max-width: none;
    justify-content: flex-start;
  }

  #phone.has :is(.who, .reply, .cap-live) {
    display: none;
  }

  #phone.has #segs {
    inset: 8px 8px auto;
  }

  #phone.has .drop {
    inset: auto auto 10px 50%;
  }

  #status,
  #results {
    scroll-margin-top: calc(22svh + 24px);
  }
}

dialog {
  border: 0;
  border-radius: 22px;
  padding: 1.2rem;
  background: var(--panel);
  color: var(--ink);
  width: min(92vw, 22rem);
}
dialog::backdrop {
  background: rgba(5, 7, 14, 0.6);
}
@keyframes kb {
  0%,
  100% {
    transform: scale(1.03);
  }
  50% {
    transform: scale(1.13) translate(1%, 1%);
  }
}
#phone[data-fx="kb"] .fg {
  animation: kb 9s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  #phone[data-fx="kb"] .fg {
    animation: none;
  }
}

:root {
  --t-2xs: 0.62rem;
  --t-xs: 0.72rem;
  --t-sm: 0.8rem;
  --t-md: 0.88rem;
  --t-lg: 1.15rem;
  --t-xl: 1.4rem;
}
#sheetBtn {
  display: none;
}
@media (max-width: 879px) {
  .stagecol:has(#phone.has) #sheetBtn {
    display: inline-block;
  }
  .stagecol.sheet:has(#phone.has) {
    position: fixed;
    inset: 0;
    z-index: 40;
    margin: 0;
    overflow: auto;
    padding: max(16px, env(safe-area-inset-top)) 16px
      max(16px, env(safe-area-inset-bottom));
    grid-template-columns: 1fr;
    justify-items: center;
    align-content: start;
    background: var(--bg);
    backdrop-filter: none;
  }
  .stagecol.sheet:has(#phone.has) #phone {
    grid-row: auto;
    width: min(80vw, calc(62svh * 0.5625));
    max-width: none;
    border-radius: 32px;
    box-shadow: 0 0 0 6px var(--frame);
  }
  .stagecol.sheet:has(#phone.has) :is(.who, .cap-live) {
    display: block;
  }
  .stagecol.sheet:has(#phone.has) .reply {
    display: flex;
  }
}
