:root {
    --bg: #0c0c11;
    --surface: #14141b;
    --border: #242430;
    --text: #c8c8d0;
    --text-dim: #55555f;
    --text-muted: #3a3a44;
    --accent: #0044ff;
    --window-off: #0d0d14;
    --window-selected-border: #f0c040;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'DM Mono', monospace;
    -webkit-font-smoothing: antialiased;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 100;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 480px;
    margin: 0 auto;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-tag {
    font-family: 'Instrument Serif', serif;
    font-size: 1.4rem;
    letter-spacing: 0.08em;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-status {
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.15em;
    color: var(--text-dim);
    padding: 0.2rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 2px;
}

.header-status.active {
    color: #40e070;
    border-color: #40e07040;
    background: #40e07008;
}

.live-indicators {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
}

.live-dot.online {
    background: #40e070;
    box-shadow: 0 0 6px #40e07080;
    animation: pulse-dot 2s ease-in-out infinite;
}

.live-dot.night {
    background: #f0c040;
    box-shadow: 0 0 6px #f0c04080;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.live-status {
    font-size: 0.5rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

/* View section — tower SVG or camera */
.view-section {
    position: relative;
    flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    background: #0a0a0e;
}

.svg-view {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem 0;
}

.svg-view.hidden { display: none; }

.tower {
    height: 50dvh;
    max-height: 420px;
}

.camera-view {
    display: none;
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 5;
    max-height: 50dvh;
    overflow: hidden;
}

.camera-view.visible { display: block; }

.camera-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scale(1.6);
    transform-origin: 58% 52%;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    letter-spacing: 0.15em;
    color: var(--text-muted);
}

.camera-overlay.hidden { display: none; }

/* View toggle button */
.view-toggle {
    position: absolute;
    bottom: 0.6rem;
    right: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.6rem;
    background: #14141bcc;
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 2px;
    font-family: 'DM Mono', monospace;
    font-size: 0.55rem;
    transition: all 0.15s;
    z-index: 5;
}

.view-toggle:hover {
    color: var(--text);
    border-color: #444;
}

.view-label {
    letter-spacing: 0.1em;
}

/* Windows */
.window {
    fill: var(--window-off);
    stroke: #1e1e28;
    stroke-width: 0.8;
    transition: fill 0.3s ease, stroke 0.3s ease, filter 0.3s ease;
    cursor: pointer;
}

.window.selected {
    stroke: var(--window-selected-border);
    stroke-width: 1.2;
    stroke-dasharray: 2 1;
    animation: dash 4s linear infinite;
}

.window.lit {
    stroke-width: 0.5;
    filter: url(#glow-strong);
}

.window.lit.selected {
    stroke: var(--window-selected-border) !important;
    stroke-width: 1.2;
    stroke-dasharray: 2 1;
}

@keyframes dash {
    to { stroke-dashoffset: -12; }
}

.floor-label {
    font-family: 'DM Mono', monospace;
    font-size: 7px;
    fill: var(--text-muted);
    transition: fill 0.2s;
    pointer-events: none;
}

.floor-label.selected { fill: var(--window-selected-border); }
.floor-label.lit { fill: var(--text-dim); }

.floor-sel {
    fill: transparent;
    transition: fill 0.2s;
    pointer-events: none;
}

.floor-sel.selected { fill: var(--window-selected-border); }
.floor-hit { cursor: pointer; }

.blink { animation: blink 3s ease-in-out infinite; }

@keyframes blink {
    0%, 45%, 55%, 100% { opacity: 1; }
    50% { opacity: 0.15; }
}

/* Controls */
.controls {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tower-info {
    font-size: 0.55rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-align: center;
}

.tower-info .night { color: #f0c040; }
.tower-info .day { color: var(--text-dim); }
.tower-info .busy { color: #ff6060; }

.tagline {
    font-family: 'Instrument Serif', serif;
    font-size: 0.85rem;
    color: var(--text-dim);
    font-style: italic;
    text-align: center;
    letter-spacing: 0.02em;
}

.control-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.control-label {
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.18em;
    color: var(--text-muted);
}

/* Color picker */
.color-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.color-picker-wrap {
    position: relative;
    width: 36px;
    height: 36px;
}

.color-picker-wrap input[type="color"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.color-preview {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--border);
    pointer-events: none;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.3s;
}

.color-preview.active {
    box-shadow: 0 0 20px var(--accent), 0 0 40px color-mix(in srgb, var(--accent) 30%, transparent);
}

.color-hex {
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}

/* Floor buttons */
.floor-buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.floor-btn {
    font-family: 'DM Mono', monospace;
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid var(--border);
    padding: 0.35rem 0.75rem;
    cursor: pointer;
    transition: all 0.15s;
    border-radius: 2px;
}

.floor-btn:hover { color: var(--text); border-color: #444; }
.floor-btn:active { background: #1a1a24; }

.floor-count {
    font-size: 0.6rem;
    color: var(--text-dim);
    letter-spacing: 0.1em;
}

/* Start button */
.start-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    width: 100%;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 2px;
}

.start-btn:hover { background: #1a1a24; border-color: #333; }
.start-btn:active { background: #222230; transform: scale(0.995); }

.start-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.start-btn:disabled:hover { background: var(--surface); border-color: var(--border); }

.start-btn.connected { border-color: #40e070; background: #40e07008; }
.start-btn.connected .start-btn-text { color: #40e070; }

.start-btn.firing {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, var(--surface));
    box-shadow: 0 0 30px color-mix(in srgb, var(--accent) 15%, transparent);
}

.start-btn-text {
    font-family: 'DM Mono', monospace;
    font-size: 0.85rem;
    font-weight: 500;
    letter-spacing: 0.25em;
}

.start-btn-sub {
    font-size: 0.55rem;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

/* Session timer */
.session-bar {
    display: none;
    align-items: center;
    gap: 0.6rem;
}

.session-bar.visible { display: flex; }

.session-timer-track {
    flex: 1;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.session-timer-fill {
    height: 100%;
    width: 100%;
    background: #40e070;
    border-radius: 2px;
    transition: width 1s linear, background 0.3s;
}

.session-timer-fill.warning { background: #f0c040; }
.session-timer-fill.critical { background: #ff5050; }

.session-time {
    font-size: 0.6rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
    min-width: 3ch;
}

/* Presets */
.preset-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.preset-select {
    font-family: 'DM Mono', monospace;
    font-size: 0.6rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    color: var(--text-dim);
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 0.35rem 1.2rem 0.35rem 0.5rem;
    border-radius: 2px;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%2355555f'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}

.preset-select:hover { border-color: #444; color: var(--text); }
.preset-select option { background: var(--surface); color: var(--text); }

/* Sequence */
.sequence-section {
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.timeline {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding: 0.4rem 0;
    min-height: 52px;
    align-items: center;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.timeline:empty::after {
    content: 'No frames — set colors then add a frame';
    font-size: 0.55rem;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    width: 100%;
    text-align: center;
}

.frame {
    flex-shrink: 0;
    width: 40px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 2px;
    background: var(--surface);
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1px;
    transition: border-color 0.15s, background 0.15s;
}

.frame:hover { border-color: #444; }
.frame.active { border-color: #f0c040; background: #f0c04008; }

.frame-index {
    position: absolute;
    top: 1px;
    left: 3px;
    font-size: 0.45rem;
    color: var(--text-muted);
}

.frame-strip {
    width: 20px;
    height: 3px;
    border-radius: 1px;
}

.frame-delete {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #332020;
    border: 1px solid #552020;
    color: #aa4444;
    font-size: 8px;
    line-height: 12px;
    text-align: center;
    cursor: pointer;
    display: none;
}

.frame:hover .frame-delete { display: block; }
.frame-delete:hover { background: #552020; color: #ff6666; }

/* Speed slider */
.speed-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.speed-row input[type="range"] {
    width: 100px;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

.speed-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-dim);
    border: 2px solid var(--border);
    cursor: pointer;
}

.speed-row input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text-dim);
    border: 2px solid var(--border);
    cursor: pointer;
}

.speed-value {
    font-size: 0.6rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
}

/* Play button */
.play-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 2px;
    margin-bottom: env(safe-area-inset-bottom, 0.5rem);
}

.play-btn:hover { background: #1a1a24; border-color: #333; }
.play-btn:active { background: #222230; }
.play-btn.playing { border-color: #f0c040; background: #f0c04008; }

.play-btn-icon { font-size: 0.7rem; }

.play-btn-text {
    font-family: 'DM Mono', monospace;
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.2em;
}
