/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 14px;
    background: #eef0f3;
    color: #333;
    min-height: 100vh;
}

a { color: #2e6da4; text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.clearfix::after { content: ""; display: table; clear: both; }

/* ── Layout ───────────────────────────────────────────────── */
.page-wrap { max-width: 820px; margin: 0 auto; padding: 0 12px 40px; }

.main-content { display: flex; flex-direction: column; gap: 12px; }

.ibox {
    background: #fff;
    border: 1px solid #d8dce2;
    border-radius: 6px;
    padding: 18px 20px;
}

/* ── Header ───────────────────────────────────────────────── */
.site-header {
    padding: 28px 0 20px;
    text-align: center;
}
.site-title {
    font-size: 28px;
    font-weight: 800;
    color: #1a2b45;
    letter-spacing: -0.5px;
}
.site-tagline {
    margin-top: 4px;
    color: #666;
    font-size: 14px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    line-height: 1.4;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary   { background: #1a2b45; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #253e60; }

.btn-secondary { background: #e8ecf1; color: #333; border: 1px solid #c8cdd6; }
.btn-secondary:hover:not(:disabled) { background: #dce1e9; }

.btn-link { background: none; color: #2e6da4; padding: 4px 0; font-weight: 600; font-size: 13px; }
.btn-link:hover { color: #1a5080; }

.btn-sml { padding: 5px 10px; font-size: 12px; }
.btn-lrg { padding: 10px 22px; font-size: 14px; }

.btn-generate {
    background: #e05c00;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    padding: 12px 32px;
    border-radius: 5px;
    letter-spacing: 0.2px;
    width: 100%;
}
.btn-generate:hover:not(:disabled) { background: #c75200; }

.show-adv { background: #e8ecf1; color: #444; border: 1px solid #c8cdd6; }
.down-arrow { font-size: 10px; display: inline-block; transition: transform 0.2s; }
.down-arrow.open { transform: rotate(180deg); }

/* ── URL Input Panel ──────────────────────────────────────── */
.url-section { display: flex; flex-direction: column; gap: 10px; }
.url-label { font-weight: 600; color: #444; font-size: 14px; }

.url-row {
    display: flex;
    gap: 8px;
}
.url-input {
    flex: 1;
    padding: 10px 12px;
    border: 2px solid #c8cdd6;
    border-radius: 4px;
    font-size: 14px;
    color: #222;
    outline: none;
    transition: border-color 0.15s;
}
.url-input:focus { border-color: #2e6da4; }
.url-input::placeholder { color: #999; }

.url-error {
    color: #c0392b;
    font-size: 13px;
    font-weight: 500;
}

/* ── Preview Section ──────────────────────────────────────── */
.g-preview-section { padding: 14px 16px; }

.preview-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}
.vid-info {
    font-size: 12px;
    color: #666;
    font-style: italic;
}

.preview-wrap {
    position: relative;
    width: 100%;
    background: #000;
    border-radius: 4px;
    overflow: hidden;
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Force the YT iframe to fill the container */
.preview-wrap iframe,
.preview-wrap #yt-player {
    display: block;
    width: 100% !important;
    aspect-ratio: 16 / 9;
    height: auto !important;
}

.preview-loading {
    position: absolute;
    inset: 0;
    background: #111;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: #aaa;
    font-size: 13px;
}

/* ── Crop Overlay ─────────────────────────────────────────── */
.crop-overlay {
    position: absolute;
    inset: 0;
    z-index: 6;
    cursor: crosshair;
}

.crop-box {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.48);
    cursor: move;
    box-sizing: border-box;
}

.crop-handle {
    position: absolute;
    width: 11px;
    height: 11px;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.4);
    border-radius: 2px;
}
/* Corner handles */
.ch-nw { top: -6px;  left: -6px;  cursor: nw-resize; }
.ch-ne { top: -6px;  right: -6px; cursor: ne-resize; }
.ch-se { bottom: -6px; right: -6px; cursor: se-resize; }
.ch-sw { bottom: -6px; left: -6px;  cursor: sw-resize; }
/* Edge handles */
.ch-n  { top: -6px;  left: 50%; transform: translateX(-50%); cursor: n-resize; }
.ch-s  { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: s-resize; }
.ch-e  { top: 50%; right: -6px; transform: translateY(-50%); cursor: e-resize; }
.ch-w  { top: 50%; left: -6px;  transform: translateY(-50%); cursor: w-resize; }

.crop-indicator {
    font-size: 12px;
    color: #c67c00;
    font-weight: 600;
    margin-top: 6px;
    padding: 4px 8px;
    background: #fff8e6;
    border: 1px solid #f0d080;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.crop-indicator .btn-link { font-size: 12px; padding: 0; color: #c67c00; text-decoration: underline; }

/* Crop button active state */
.btn-sml.crop-active {
    background: #1a2b45;
    color: #fff;
    border-color: #1a2b45;
}

/* ── Dual-Handle Slider ───────────────────────────────────── */
.time-section { margin-top: 12px; }

.dual-slider {
    padding: 10px 8px 4px;
    user-select: none;
}

.slider-track {
    position: relative;
    height: 8px;
    background: #d0d4db;
    border-radius: 4px;
    margin: 8px 0;
}

.slider-fill {
    position: absolute;
    top: 0;
    height: 100%;
    background: #2e6da4;
    border-radius: 4px;
    pointer-events: none;
}

.slider-handle {
    position: absolute;
    top: 50%;
    width: 18px;
    height: 18px;
    background: #fff;
    border: 3px solid #2e6da4;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    cursor: grab;
    transition: border-color 0.1s, box-shadow 0.1s;
    z-index: 2;
}
.slider-handle:hover,
.slider-handle:active {
    border-color: #1a5080;
    box-shadow: 0 0 0 4px rgba(46,109,164,0.2);
}
.slider-handle:active { cursor: grabbing; }

.time-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.time-input-wrap {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    color: #555;
}
.time-field {
    display: flex;
    align-items: stretch;
}
.time-num {
    width: 58px;
    padding: 5px 7px;
    border: 1px solid #c8cdd6;
    border-radius: 4px 0 0 4px;
    border-right: none;
    font-size: 13px;
    text-align: center;
    outline: none;
}
.time-num:focus { border-color: #2e6da4; }
.time-num:focus + .time-spin { border-color: #2e6da4; }
.time-spin {
    display: flex;
    flex-direction: column;
    border: 1px solid #c8cdd6;
    border-radius: 0 4px 4px 0;
    overflow: hidden;
}
.end-wrap .time-spin {
    border-radius: 4px 0 0 4px;
    border-right: none;
    border-left: 1px solid #c8cdd6;
}
.end-wrap .time-num {
    border-radius: 0 4px 4px 0;
    border-left: none;
    border-right: 1px solid #c8cdd6;
}
.spin-btn {
    flex: 1;
    width: 16px;
    padding: 0;
    border: none;
    border-bottom: 1px solid #c8cdd6;
    background: #f4f5f7;
    color: #666;
    font-size: 6px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}
.spin-btn:last-child { border-bottom: none; }
.spin-btn:hover { background: #e4e8ed; color: #222; }
.spin-btn:active { background: #d8dde5; }

.time-cur-btn {
    background: none;
    border: none;
    padding: 0 1px;
    font-size: 15px;
    color: #9aa;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
}
.time-cur-btn:hover { color: #2e6da4; }

.end-wrap { margin-left: auto; }

.play-icon { font-size: 10px; }

/* ── Settings Section ─────────────────────────────────────── */
.g-settings-section { display: flex; flex-direction: column; gap: 14px; }

.setting-group { margin-bottom: 2px; }

.g-opt {
    display: inline-block;
    font-weight: 700;
    color: #444;
    min-width: 80px;
    font-size: 13px;
    vertical-align: middle;
}

/* Width size buttons */
.g-sizes { display: inline-flex; flex-wrap: wrap; gap: 4px; }

.g-size {
    padding: 5px 11px;
    background: #e8ecf1;
    border: 1px solid #c8cdd6;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
    color: #444;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.g-size:hover { background: #d8dce5; }
.g-size.on {
    background: #1a2b45;
    border-color: #1a2b45;
    color: #fff;
}

.g-btns-wrap { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* Advanced Options */
.g-adv {
    background: #f7f9fb;
    border: 1px solid #e0e4ea;
    border-radius: 4px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.g-adv p { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.g-adv small { color: #777; font-size: 12px; }
.g-opt-description { color: #888; font-size: 12px; }

.g-sml-input {
    width: 70px;
    padding: 5px 7px;
    border: 1px solid #c8cdd6;
    border-radius: 3px;
    font-size: 13px;
    text-align: center;
    outline: none;
}
.g-sml-input:focus { border-color: #2e6da4; }

.check-list { display: flex; flex-direction: column; gap: 7px; }

.check-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #333;
}
.check-wrap input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #2e6da4;
}
.check-text { user-select: none; }

.select-wrap {
    display: inline-block;
}
.select-wrap select {
    padding: 5px 8px;
    border: 1px solid #c8cdd6;
    border-radius: 3px;
    font-size: 13px;
    background: #fff;
    color: #333;
    outline: none;
    cursor: pointer;
}
.select-wrap select:focus { border-color: #2e6da4; }

/* ── Stats Bars ───────────────────────────────────────────── */
.vgif-limits {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.vgif-limit {
    position: relative;
    flex: 1;
    min-width: 120px;
    height: 26px;
    background: #e8ecf1;
    border-radius: 3px;
    overflow: hidden;
    cursor: default;
}

.bar-fill {
    position: absolute;
    top: 0; left: 0;
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s, background 0.3s;
}
.bar-fill.green  { background: #4caf50; }
.bar-fill.yellow { background: #ff9800; }
.bar-fill.red    { background: #e53935; }

.bar-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    white-space: nowrap;
}

.bar-tip {
    display: none;
    position: absolute;
    bottom: 130%;
    left: 50%;
    transform: translateX(-50%);
    background: #222;
    color: #fff;
    padding: 6px 9px;
    border-radius: 4px;
    font-size: 11px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}
.vgif-limit:hover .bar-tip { display: block; }

/* ── Generate / Loading / Result ─────────────────────────── */
.gen-wrap { text-align: center; }


.gen-loading {
    text-align: center;
    padding: 24px;
    color: #555;
}
.gen-loading p { margin-top: 10px; font-size: 14px; font-weight: 600; }
.gen-loading small { color: #888; font-size: 12px; }

.gen-error {
    background: #fdf0ef;
    border: 1px solid #f0b8b3;
    border-radius: 4px;
    padding: 12px 14px;
    color: #c0392b;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
}

.gen-result {
    text-align: center;
    border-top: 1px solid #e8ecf1;
    padding-top: 18px;
}
.gen-result h3 { font-size: 16px; color: #1a2b45; margin-bottom: 6px; }

.result-meta { color: #666; font-size: 13px; margin-bottom: 12px; }
.result-size { font-weight: 600; }

.result-img {
    max-width: 100%;
    border: 1px solid #ddd;
    border-radius: 4px;
    display: block;
    margin: 0 auto 14px;
}

.result-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #dde1e8;
    border-top-color: #2e6da4;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    margin: 0 auto;
}
.spinner-lg { width: 40px; height: 40px; border-width: 4px; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Footer ───────────────────────────────────────────────── */
.site-footer {
    text-align: center;
    padding: 24px 0 12px;
    color: #999;
    font-size: 12px;
}
.site-footer a { color: #2e6da4; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 520px) {
    .url-row { flex-direction: column; }
    .end-wrap { margin-left: 0; }
    .time-inputs { justify-content: space-between; }
    .btn-generate { font-size: 15px; }
}
