@import url('theme.css');

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
}

body {
    font-family: Arial, sans-serif;
    color: #fff;
    background: #000;
    overflow: hidden;
}

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

.app-stage {
    position: relative;
    width: 100%;
    height: 100%;
    background: #000;
}

#video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    pointer-events: none;
}

#canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Nav */
.app-nav {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.4);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(8px);
}

.app-nav-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 0.85rem;
    min-height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.65rem;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none !important;
    color: #fff !important;
    min-width: 0;
}

.app-brand img {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
}

.app-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.app-brand-name {
    font-weight: 700;
    font-size: 0.92rem;
}

.app-brand-sub {
    font-size: 0.66rem;
    color: rgba(255, 255, 255, 0.85);
}

.app-brand-by {
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.7);
}

.nav-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    justify-content: flex-end;
    align-items: center;
}

.chip-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.3rem 0.2rem 0.45rem;
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.chip-group-label {
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.5);
    padding: 0 0.2rem;
    user-select: none;
}

.chip {
    padding: 0.4rem 0.65rem;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.28);
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.chip-save {
    border-color: rgba(94, 234, 212, 0.35);
    background: rgba(15, 40, 45, 0.55);
}

.chip:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: rgba(255, 255, 255, 0.5);
}

.chip.is-on {
    background: rgba(233, 69, 96, 0.35);
    border-color: rgba(245, 163, 181, 0.7);
}

.mood-line {
    position: absolute;
    left: 12px;
    bottom: 88px;
    z-index: 15;
    margin: 0;
    padding: 0.4rem 0.65rem;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: capitalize;
    pointer-events: none;
}

/* Always-visible active effects */
.live-fx {
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 52px;
    z-index: 15;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    pointer-events: none;
}

/* ── Mobile camera shutter dock (vertical / phone) ── */
.capture-dock {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 35;
    justify-content: center;
    align-items: center;
    gap: 2.25rem;
    padding: 0.85rem 1rem calc(0.95rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 40%, rgba(0, 0, 0, 0.25) 85%, transparent);
    pointer-events: none;
}

.capture-dock .shutter {
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    background: transparent;
}

.shutter-photo {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #1a1a1a;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.35), 0 6px 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.shutter-photo:active {
    transform: scale(0.94);
}

.shutter-icon {
    display: block;
}

.shutter-video {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45), 0 6px 18px rgba(0, 0, 0, 0.35);
    transition: transform 0.12s ease, background 0.15s ease;
}

.shutter-video-core {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #e11d2e;
    box-shadow: 0 0 0 2px rgba(225, 29, 46, 0.35);
    transition: border-radius 0.15s ease, width 0.15s ease, height 0.15s ease, background 0.15s ease;
}

.shutter-video:active {
    transform: scale(0.94);
}

.shutter-video.is-on {
    background: rgba(225, 29, 46, 0.2);
    box-shadow: 0 0 0 3px rgba(225, 29, 46, 0.65), 0 6px 18px rgba(0, 0, 0, 0.4);
    animation: rec-pulse 1.2s ease-in-out infinite;
}

.shutter-video.is-on .shutter-video-core {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: #ff3b4a;
}

.fx-chip {
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 0.7rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.85);
}

.fx-chip.is-on {
    border-color: rgba(245, 163, 181, 0.7);
    background: rgba(233, 69, 96, 0.35);
    color: #fff;
}

/* Start overlay */
.status {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    text-align: center;
    background: var(--ktm-gradient);
    background-size: 400% 400%;
    animation: ktm-gradient-shift var(--ktm-shift-duration) ease infinite;
}

.status[hidden] {
    display: none !important;
}

.status-card {
    max-width: 360px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 16px;
    padding: 1.5rem;
}

.status-card h1 {
    margin: 0 0 0.5rem;
    font-size: 1.25rem;
}

.status-card p {
    margin: 0 0 1rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.95rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.15rem;
    border: none;
    border-radius: 10px;
    background: var(--ktm-gradient-btn);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
}

/* Footer */
.app-footer {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    padding: 0.65rem 1rem;
    text-align: center;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(0, 0, 0, 0.4);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.app-footer a { font-weight: 600; }

.boot-error {
    position: absolute;
    top: 70px;
    left: 12px;
    right: 12px;
    z-index: 100;
    margin: 0;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    background: rgba(120, 20, 40, 0.92);
    border: 1px solid rgba(255, 120, 140, 0.5);
    font-size: 0.85rem;
    color: #fff;
}

/* Debug panel — above canvas/footer */
.debug-panel {
    position: fixed;
    top: 64px;
    right: 10px;
    z-index: 9999;
    width: min(300px, calc(100vw - 20px));
    max-height: calc(100vh - 120px);
    overflow: auto;
    padding: 0.75rem 0.8rem 0.9rem;
    border-radius: 12px;
    background: rgba(8, 6, 16, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    font-size: 0.72rem;
    line-height: 1.35;
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
}

.debug-panel[hidden],
.debug-panel:not(.is-open) {
    display: none !important;
}

.debug-panel.is-open {
    display: block !important;
}

.debug-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.55rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.debug-fps {
    font-variant-numeric: tabular-nums;
    color: #f5a3b5;
    font-weight: 700;
}

.debug-section {
    margin-bottom: 0.65rem;
}

.debug-section h4 {
    margin: 0 0 0.3rem;
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.55);
}

.debug-kv {
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.85);
}

.debug-kv b {
    color: #fff;
    font-weight: 700;
}

.meter {
    display: grid;
    grid-template-columns: 64px 1fr 36px;
    gap: 0.3rem;
    align-items: center;
    margin-bottom: 0.25rem;
    font-family: ui-monospace, Menlo, Consolas, monospace;
}

.meter span {
    color: rgba(255, 255, 255, 0.7);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.meter i {
    display: block;
    height: 6px;
    width: 0%;
    border-radius: 99px;
    background: linear-gradient(90deg, #0f3460, #e94560);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    background-color: rgba(255, 255, 255, 0.08);
    max-width: 100%;
}

.meter {
    background: transparent;
}

.meter i {
    background-image: linear-gradient(90deg, #0f3460, #e94560);
    background-repeat: no-repeat;
    background-color: rgba(255, 255, 255, 0.1);
}

.meter em {
    font-style: normal;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.8);
}

.meter.fx span {
    font-size: 0.65rem;
}

.meter.fx.is-active span {
    color: #f5a3b5;
}

.debug-map .map-row {
    margin-bottom: 0.45rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.7rem;
    line-height: 1.35;
}

.debug-map .map-row:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.debug-map b {
    color: #fff;
}

.debug-map code {
    font-size: 0.68rem;
    color: #f5a3b5;
    background: rgba(0, 0, 0, 0.35);
    padding: 0.05rem 0.3rem;
    border-radius: 4px;
}

.debug-map span {
    color: rgba(255, 255, 255, 0.65);
}

#dbg-master,
#dbg-recover,
.ctrl-range,
.master-range {
    width: 100%;
    accent-color: #e94560;
}

.slider-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 0.25rem;
    font-size: 0.62rem;
    color: rgba(255, 255, 255, 0.45);
    font-variant-numeric: tabular-nums;
}

.slider-meta span:nth-child(2) {
    color: rgba(255, 255, 255, 0.8);
    font-weight: 600;
}

.slider-hint {
    margin: 0 0 0.35rem;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.3;
}

.ktm-toast {
    position: fixed;
    left: 50%;
    bottom: 64px;
    transform: translateX(-50%) translateY(12px);
    z-index: 10000;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    background: rgba(8, 6, 16, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.ktm-toast.is-on {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#btn-video.is-on {
    background: rgba(220, 40, 60, 0.55);
    border-color: rgba(255, 120, 140, 0.85);
    animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 40, 60, 0.45); }
    50% { box-shadow: 0 0 0 6px rgba(220, 40, 60, 0); }
}

@media (max-width: 520px) {
    .chip-group-label {
        display: none;
    }
}

/* Portrait / phone: shutter dock, hide desktop Save chips */
@media (max-width: 820px) and (orientation: portrait),
       (max-width: 520px) {
    .chip-group-save {
        display: none !important;
    }

    .capture-dock {
        display: flex;
    }

    .app-footer {
        display: none;
    }

    .mood-line {
        bottom: calc(108px + env(safe-area-inset-bottom, 0px));
    }

    .live-fx {
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
    }

    .debug-panel {
        bottom: calc(100px + env(safe-area-inset-bottom, 0px));
        max-height: calc(100vh - 180px);
    }

    .ktm-toast {
        bottom: calc(120px + env(safe-area-inset-bottom, 0px));
    }
}

/* Manual override controls */
.ctrl {
    display: grid;
    grid-template-columns: 52px 52px 1fr 36px;
    gap: 0.25rem 0.3rem;
    align-items: center;
    margin-bottom: 0.45rem;
    font-family: ui-monospace, Menlo, Consolas, monospace;
    font-size: 0.68rem;
}

.ctrl-drives {
    grid-column: 1 / -1;
    font-size: 0.6rem;
    color: rgba(255, 255, 255, 0.45);
    padding-left: 0.1rem;
    line-height: 1.25;
}

.ctrl.is-manual .ctrl-drives {
    color: rgba(245, 163, 181, 0.75);
}

.ctrl-live-wrap {
    display: flex;
    align-items: center;
    gap: 0.2rem;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    user-select: none;
    font-size: 0.62rem;
}

.ctrl-live {
    margin: 0;
    accent-color: #5eead4;
}

.ctrl-label {
    color: rgba(255, 255, 255, 0.75);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ctrl-val {
    font-style: normal;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: rgba(255, 255, 255, 0.85);
}

.ctrl.is-manual {
    background: rgba(233, 69, 96, 0.12);
    border-radius: 6px;
    padding: 0.15rem 0.2rem;
}

.ctrl.is-manual .ctrl-label,
.ctrl.is-manual .ctrl-val {
    color: #f5a3b5;
}

.ctrl.is-manual .ctrl-live-wrap {
    color: #f5a3b5;
}

.chip-block {
    width: 100%;
    justify-content: center;
    border-radius: 8px;
    padding: 0.45rem 0.65rem;
}

.debug-actions {
    margin-top: 0.25rem;
}

@media (max-width: 480px) {
    .app-brand-sub,
    .app-brand-by {
        display: none;
    }

    .chip {
        padding: 0.35rem 0.5rem;
        font-size: 0.7rem;
    }

    .debug-panel {
        top: auto;
        bottom: 48px;
        right: 8px;
        left: 8px;
        width: auto;
        max-height: 42vh;
    }
}
