:root {
  font-family:Inter,ui-sans-serif,system-ui,sans-serif;
  --bg:var(--tg-theme-bg-color,#f6f4ef);
  --text:var(--tg-theme-text-color,#282f2a);
  --surface:var(--tg-theme-section-bg-color,var(--bg));
  --secondary:var(--tg-theme-secondary-bg-color,#efefe6);
  --button-text:var(--tg-theme-button-text-color,#fff);
  --danger:var(--tg-theme-destructive-text-color,#922f1c);
  --trim:#eee;
  --stable-height:100vh;
  /* Browser and Telegram device insets describe the same system UI.
     Telegram's content inset reserves additional space for its own controls. */
  --safe-top:calc(max(env(safe-area-inset-top,0px),var(--device-inset-top,0px)) + var(--content-inset-top,0px));
  --safe-right:calc(max(env(safe-area-inset-right,0px),var(--device-inset-right,0px)) + var(--content-inset-right,0px));
  --safe-bottom:calc(max(env(safe-area-inset-bottom,0px),var(--device-inset-bottom,0px)) + var(--content-inset-bottom,0px));
  --safe-left:calc(max(env(safe-area-inset-left,0px),var(--device-inset-left,0px)) + var(--content-inset-left,0px));
  --page-top:24px;
  --page-side:36px;
  --page-bottom:40px;
  color:var(--text);
  background:var(--bg);
  font-synthesis:none;
  color-scheme:light;
  --accent:var(--tg-theme-button-color,#cc543b);
  --line:var(--tg-theme-section-separator-color,color-mix(in srgb,var(--text) 18%,var(--bg)));
  --muted:var(--tg-theme-hint-color,#687067);
}
@supports(height:100svh) {
  :root { --stable-height:100svh; }
}
* {
  box-sizing:border-box;
}
[hidden] {
  display:none!important;
}
body {
  margin:0;
}
main {
  max-width:1160px;
  margin:auto;
  padding:calc(var(--page-top) + var(--safe-top)) calc(var(--page-side) + var(--safe-right)) calc(var(--page-bottom) + var(--safe-bottom)) calc(var(--page-side) + var(--safe-left));
}
header {
  display:flex;
  justify-content:space-between;
  align-items:center;
  margin-bottom:48px;
}
.wordmark {
  font-size:32px;
  font-weight:850;
  letter-spacing:-1.8px;
  text-decoration:none;
  color:inherit;
}
.dot {
  color:var(--accent);
}
button,input {
  font:inherit;
}
button {
  min-height:44px;
  padding:10px 17px;
  border:1px solid var(--line);
  border-radius:10px;
  background:var(--surface);
  color:inherit;
  cursor:pointer;
  font-size:14px;
  font-weight:600;
}
button:hover {
  border-color:var(--muted);
  background:var(--surface);
}
button:disabled {
  opacity:.45;
  cursor:default;
}
button:focus-visible,input:focus-visible,canvas:focus-visible {
  outline:3px solid var(--accent);
  outline-offset:3px;
}
.pill {
  border-radius:30px;
  padding:8px 20px;
  background:var(--secondary);
}
.primary {
  color:var(--button-text);
  background:var(--accent);
  border-color:var(--accent);
}
.primary:hover {
  background:var(--accent);
  border-color:var(--accent);
}
h1 {
  font-size:clamp(32px,5vw,58px);
  letter-spacing:-2px;
  line-height:1.05;
  margin:12px 0 18px;
  font-weight:760;
}
h2 {
  font-size:22px;
  letter-spacing:-.5px;
  margin:0 0 12px;
}
h3 {
  font-size:18px;
  margin:0;
}
p {
  line-height:1.55;
  color:var(--muted);
}
.intro {
  margin-bottom:28px;
}
.intro>p:last-child {
  font-size:16px;
}
.eyebrow {
  font-size:11px;
  letter-spacing:1.5px;
  font-weight:700;
  color:var(--accent);
  margin:0 0 10px;
}
.notice {
  padding:12px 16px;
  border:1px solid var(--line);
  background:var(--secondary);
  border-radius:10px;
  font-size:14px;
  line-height:1.5;
  margin:16px 0;
}
.notice.error {
  color:var(--danger);
  background:color-mix(in srgb,var(--danger) 12%,var(--bg));
  border-color:var(--danger);
}
#account {
  display:flex;
  justify-content:space-between;
  gap:12px;
  font-size:13px;
  color:var(--muted);
  margin:20px 0;
}
.upload-panel {
  border:1px dashed var(--line);
  border-radius:16px;
  background:var(--secondary);
  padding:28px;
  text-align:center;
  margin:20px 0 28px;
}
.upload-label {
  display:grid;
  justify-items:center;
  gap:9px;
  cursor:pointer;
}
.upload-label strong {
  font-size:18px;
}
.upload-label>span:last-child {
  font-size:13px;
  color:var(--muted);
}
.upload-icon {
  font-size:28px;
  background:var(--surface);
  border-radius:50%;
  width:52px;
  height:52px;
  display:grid;
  place-items:center;
  color:var(--accent);
}
#file {
  position:absolute;
  width:1px;
  height:1px;
  opacity:0;
}
#file:focus-visible+.upload-label,.upload-panel:focus-within {
  outline:3px solid var(--accent);
}
progress {
  width:100%;
  accent-color:var(--accent);
  margin-top:20px;
}
.job-panel {
  border:1px solid var(--line);
  padding:24px;
  border-radius:16px;
  margin:20px 0;
  background:var(--surface);
}
.job-panel p {
  margin-bottom:0;
}
.actions {
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-top:14px;
}
.editor-heading {
  display:flex;
  flex-wrap:wrap;
  gap:20px;
  align-items:center;
  justify-content:space-between;
  margin:36px 0 20px;
}
#fullscreen {
  min-height:36px;
  white-space:nowrap;
}
.editor-heading span {
  font-size:12px;
  color:var(--muted);
  max-width:45%;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.workspace {
  display:grid;
  grid-template-columns:minmax(0,1fr) 270px;
  gap:28px;
}
.crop-column {
  min-width:0;
}
.stage {
  background:#242924;
  border-radius:14px;
  overflow:hidden;
  display:flex;
  justify-content:center;
  align-items:center;
  min-height:220px;
  padding:14px;
}
#canvas {
  width:100%;
  height:auto;
  max-height:min(440px,max(120px,calc((var(--stable-height) - var(--safe-top) - var(--safe-bottom)) * .5)));
  object-fit:contain;
  display:block;
  touch-action:none;
  cursor:crosshair;
}
.hint {
  font-size:12px;
  color:var(--muted);
  line-height:1.5;
  margin:12px 0;
}
#play {
  width:100%;
  margin-top:12px;
}
.crop-controls {
  display:grid;
  grid-template-columns:1fr 1fr;
  gap:10px;
  margin:18px 0;
}
label {
  font-size:12px;
  color:var(--muted);
  display:grid;
  gap:6px;
}
input[type=number] {
  width:100%;
  min-width:0;
  background:var(--surface);
  color:inherit;
  border:1px solid var(--line);
  border-radius:8px;
  padding:11px 12px;
  font-size:14px;
}
.check {
  display:flex;
  align-items:center;
  gap:8px;
  min-height:34px;
}
input[type=checkbox] {
  accent-color:var(--accent);
  width:17px;
  height:17px;
}
.timeline-scroll {
  overflow-x:auto;
  overflow-y:hidden;
  padding:12px 24px;
  scrollbar-width:none;
}
.timeline-scroll::-webkit-scrollbar {
  display:none;
}
.filmstrip {
  overflow:visible;
  height:92px;
  position:relative;
  min-width:100%;
}
.interval {
  position:absolute;
  top:0;
  height:92px;
  border:3px solid var(--trim);
  background:transparent;
  border-radius:0;
  min-width:8px;
  cursor:grab;
  touch-action:none;
  display:flex;
  align-items:center;
  justify-content:space-between;
  z-index:auto;
}
.trim-handle {
  min-width:18px;
  width:18px;
  min-height:calc(100% + 6px);
  height:calc(100% + 6px);
  border:none;
  border-radius:0;
  background:var(--trim);
  padding:0;
  cursor:ew-resize;
  position:absolute;
  z-index:4;
  top:-3px;
  color:white;
  touch-action:none;
}
.trim-handle:after {
  content:'';
  position:absolute;
  left:50%;
  top:50%;
  transform:translate(-50%,-50%);
  width:3px;
  height:28px;
  border-radius:2px;
  background:#777;
}
.trim-handle:hover,.trim-handle:active {
  background:var(--trim);
  border:none;
}
#in-handle {
  left:-3px;
  transform:translateX(-100%);
  border-radius:8px 0 0 8px;
}
#out-handle {
  right:-3px;
  transform:translateX(100%);
  border-radius:0 8px 8px 0;
}
.playhead {
  position:absolute;
  top:0;
  bottom:0;
  width:8px;
  transform:translateX(-50%);
  cursor:ew-resize;
  touch-action:none;
  z-index:3;
}
.playhead::after {
  content:'';
  position:absolute;
  top:0;
  bottom:0;
  left:calc(50% - 1px);
  width:2px;
  background:#fff;
  box-shadow:0 0 0 1px #282f2a55;
  pointer-events:none;
}
footer {
  border-top:1px solid var(--line);
  padding-top:20px;
  margin-top:24px;
  display:flex;
  justify-content:space-between;
  gap:16px;
  align-items:center;
  flex-wrap:wrap;
}
footer span:empty {
  display:none;
}
footer span {
  font-size:12px;
  color:var(--muted);
}
footer .primary {
  min-width:180px;
}
.footnote {
  font-size:11px;
  border-top:1px solid var(--line);
  padding-top:18px;
  margin-top:36px;
}
.pro-panel {
  background:var(--secondary);
  border-radius:16px;
  padding:24px;
  margin-top:20px;
}
@media(max-width:700px) {
  main {
    --page-top:18px;
    --page-side:18px;
    --page-bottom:28px;
  }
  header {
    margin-bottom:28px;
  }
  .intro {
    margin-bottom:20px;
  }
  h1 {
    letter-spacing:-1px;
  }
  .upload-panel {
    padding:22px 16px;
  }
  .workspace {
    grid-template-columns:1fr;
    gap:16px;
  }
  .stage {
    padding:10px;
    min-height:160px;
  }
  #canvas {
    max-height:min(380px,max(120px,calc((var(--stable-height) - var(--safe-top) - var(--safe-bottom)) * .5)));
  }
  aside {
    display:block;
  }
  #play {
    font-size:12px;
  }
  .editor-heading {
    margin-top:26px;
  }
  footer {
    position:sticky;
    bottom:var(--safe-bottom);
    background:var(--bg);
    padding:14px 0;
    z-index:5;
  }
  footer span {
    max-width:40%;
  }
  footer .primary {
    min-width:0;
    flex:1;
  }
  .trim-handle {
    width:24px;
    min-width:24px;
  }
  .notice {
    font-size:13px;
  }
  #account {
    font-size:12px;
  }
}
.editing header {
  margin-bottom:20px;
}
.editing .intro {
  display:none;
}
.editing .upload-panel {
  padding:12px 16px;
}
.editing .upload-label {
  display:flex;
  flex-wrap:wrap;
  justify-content:center;
  align-items:center;
  gap:8px 16px;
}
.editing .upload-icon {
  display:none;
}
.editing .upload-label strong {
  font-size:14px;
}
.editing .editor-heading {
  margin-top:24px;
}
.replace-video {
  display:none;
}
@media (max-width:700px) {
  .editing .upload-panel {
    display:none;
  }
  .editing .replace-video {
    display:inline-flex;
    align-items:center;
    min-height:36px;
    padding:0 10px;
    border:1px solid var(--line);
    border-radius:8px;
    font-size:12px;
    white-space:nowrap;
    cursor:pointer;
  }
  .editor-heading #source-name {
    flex:1;
    min-width:0;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
}

.timeline-wrap {
  position:relative;
  padding-top:0;
}
.frame-bubble {
  position:absolute;
  top:-72px;
  z-index:5;
  width:64px;
  height:64px;
  transform:translateX(-50%);
  pointer-events:none;
}
.frame-bubble canvas {
  display:block;
  width:64px;
  height:64px;
  border:2px solid white;
  border-radius:50%;
  background:#282f2a;
}
.frame-bubble::after {
  content:'';
  position:absolute;
  top:64px;
  left:calc(50% + var(--line-offset, 0px));
  height:20px;
  border-left:2px solid white;
}
.timeline-frames {
  position:absolute;
  top:0;
  width:100%;
  height:92px;
  pointer-events:none;
  overflow:hidden;
  border-radius:0;
}
.timeline-frames canvas {
  position:absolute;
  top:0;
  height:100%;
  object-fit:cover;
  opacity:.8;
}
.timeline-scroll {
  touch-action:pan-x pan-y;
}

:root[data-theme="dark"] {
  --bg:var(--tg-theme-bg-color,#212121);
  --text:var(--tg-theme-text-color,#eee);
  --secondary:var(--tg-theme-secondary-bg-color,#181818);
  --muted:var(--tg-theme-hint-color,#aaa);
}

.crop-column .timeline-wrap {
  margin-top:8px;
}
.playhead:focus-visible::after {
  box-shadow:0 0 0 2px var(--accent);
}

.clip-range {
  display:block;
  margin:12px 0 6px;
  text-align:center;
  font-size:12px;
  font-variant-numeric:tabular-nums;
  color:var(--text);
}
