:root {
    --bg-color-dark: #121212;
    --text-color: #ffffff;
    --layer-0-bg: #000000;
    --layer-1-z: 10;
    --layer-2-z: 20;
    --layer-3-z: 30;
    --layer-4-z: 1000;
}

* {
    box-sizing: border-box;
    accent-color: #cccccc !important; /* Soft Silver Accent */
}

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color-dark);
    color: var(--text-color);
    font-family: 'Inter', 'Segoe UI', sans-serif;
    overflow: hidden;
    /* For monitor, overridden if needed in control */
}

/* =========================================
   Monitor specific layers
========================================= */
#monitor-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background-color: var(--layer-0-bg);
    transform-origin: center center;
}

.layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass if not needed */
}

/* Layer 1: Video/Image */
#layer-media {
    z-index: var(--layer-1-z);
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--layer-0-bg);
    position: relative;
    overflow: hidden;
}

#layer-media video,
#layer-media img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* Adds black bars to non-16:9 material */
}

#layer-media video.camera-rotated,
#layer-media img.camera-rotated {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 177.77% !important;
    height: 56.25% !important;
    transform: translate(-50%, -50%) rotate(90deg);
    object-fit: cover;
}

/* Layer 2: Prompter Box */
#layer-prompter {
    z-index: var(--layer-2-z);
    position: absolute;
    display: block;
    box-sizing: border-box;
    font-size: 4rem;
    font-weight: bold;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.8);
    white-space: pre-wrap;
    overflow: hidden;
    /* width, height, top, left, background-color are set via JS */
}

#prompter-content {
    position: absolute;
    width: 100%;
    transition: transform 0.1s linear;
}

/* Layer 3: Timer */
#layer-timer {
    z-index: var(--layer-3-z);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    padding: 30px;
    box-sizing: border-box;
}

.timer-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    width: auto;
    height: auto;
    padding: 2vh 4vh;
}

#countdown-display {
    font-family: inherit;
    font-size: 15vh;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 20px rgba(0, 0, 0, 1);
    line-height: 1.1;
    margin: 0;
    white-space: nowrap;
}

#current-time-display {
    font-family: inherit;
    font-size: 5vh;
    opacity: 0.8;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 10px rgba(0, 0, 0, 1);
    line-height: 1.1;
    margin: 0;
}

/* Timer color states */
.timer-normal {
    color: #ffffff;
}

#seek-bar {
    accent-color: #cccccc;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

#seek-bar::-webkit-slider-runnable-track {
    background: rgba(255, 255, 255, 0.1); 
    border-radius: 4px;
    height: 4px;
}

#seek-bar::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: #cccccc;
    border: 1px solid #333;
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    position: relative;
    z-index: 10;
}

.timer-warning {
    color: #ff9800; /* Yellow to Orange */
}

/* 1 min */
.timer-danger {
    color: #ff0000;
    animation: blink 1s infinite;
}

/* 10 sec, blinking */
.timer-over {
    color: #ff0000;
    animation: flash 0.5s infinite;
}

/* exceeded */

@keyframes blink {

    0%,
    49% {
        opacity: 1;
    }

    50%,
    100% {
        opacity: 0;
    }
}

@keyframes flash {

    0%,
    49% {
        color: #ff0000;
        text-shadow: 0 0 20px red;
    }

    50%,
    100% {
        color: #ffffff;
        text-shadow: none;
    }
}

/* Layer 4: Panic Blackout */
#layer-panic {
    z-index: var(--layer-4-z);
    background-color: black;
    display: none;
}

.panic-active #layer-panic {
    display: block;
}

/* =========================================
   Control specific styles
========================================= */
body.control-ui {
    overflow: hidden;
    background-color: #121212;
    color: #eeeeee;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, #222, #181818);
    padding: 8px 15px;
    border-bottom: 1px solid #333;
    height: 50px;
    box-sizing: border-box;
}

.top-bar .brand {
    font-size: 1.1rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
}

.top-group {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.03);
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.top-status {
    font-size: 0.9rem;
}

.top-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Bottom Bar (Performance Monitor) */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 24px;
    background: #000;
    border-top: 1px solid #222;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 0 15px;
    font-size: 0.7rem;
    color: #666;
    z-index: 2000;
    box-sizing: border-box;
    gap: 15px;
}

.perf-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.perf-value {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-weight: bold;
    transition: color 0.3s;
}

/* Color codes for Performance */
.perf-normal {
    color: #4caf50;
}

/* Green */
.perf-warning {
    color: #ffeb3b;
    text-shadow: 0 0 5px rgba(255, 235, 59, 0.3);
}

/* Yellow */
.perf-critical {
    color: #f44336;
    text-shadow: 0 0 8px rgba(244, 67, 54, 0.5);
    font-weight: 900;
}

/* Red */

.modules-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 15px;
    padding: 15px;
    height: calc(100vh - 50px - 24px);
    /* minus top-bar and bottom-bar */
    box-sizing: border-box;
}

@media (max-width: 1200px) {
    .modules-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 800px) {
    body.control-ui {
        overflow: auto;
    }

    .modules-grid {
        grid-template-columns: 1fr;
        height: auto;
    }
}

.module-card {
    background: #1e1e1e;
    border: 1px solid #333;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.module-header {
    background: #252525;
    padding: 8px 12px;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.module-header .toggle-switch {
    display: none;
    /* Hide the main enable checkbox since the whole header is clickable */
}

/* Ensure Sync toggle label or other specific controls remain visible */
.sync-toggle-label {
    display: flex !important;
    user-select: none;
}

.module-header:hover {
    background: #333;
}

.module-card.enabled {
    border-color: #555;
    background: #252525;
}

.module-card.enabled .module-header {
    background: rgba(255, 255, 255, 0.05);
    border-bottom-color: #444;
}

.module-card.enabled .module-header h2 {
    color: #cccccc;
}

/* Synced State - Sophisticated Silver */
.module-card.synced {
    border-color: #777;
    border-width: 1.5px;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
}

.module-card.synced .module-header {
    background: #444;
    border-bottom-color: #555;
}

.module-card.synced .module-header h2 {
    color: #e0e0e0;
}

/* All Synced State */
.module-card.synced-all {
    border-color: #999;
    background: #2a2a2a;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.4);
}

.module-card.synced-all .module-header {
    background: #555;
    border-bottom-color: #666;
}

.module-card.synced-all .module-header h2 {
    color: #ffffff;
    font-weight: 700;
}

.module-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.module-body {
    padding: 10px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.drop-zone {
    border: 2px dashed #555;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    color: #888;
    cursor: pointer;
    transition: all 0.3s;
}

.drop-zone.dragover,
textarea.dragover {
    border: 2px dashed #ffffff !important;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1) !important;
}

.media-info {
    font-size: 0.9em;
    color: #aaa;
    text-align: center;
}

.preview-area {
    background: #000;
    border-radius: 8px;
    aspect-ratio: 16 / 9;
    max-height: 360px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: aspect-ratio 0.3s ease;
    position: relative;
}

.vertical-mode .preview-area {
    aspect-ratio: 9 / 16;
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 600px;
    margin: 0 auto;
}

.preview-area video,
.preview-area img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.preview-area video.camera-rotated,
.preview-area img.camera-rotated {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 177.77% !important;
    height: 56.25% !important;
    transform: translate(-50%, -50%) rotate(90deg);
    object-fit: cover;
}

.timeline-container {
    display: flex;
    align-items: center;
    gap: 10px;
    font-variant-numeric: tabular-nums;
    font-size: 0.9rem;
}

.timeline-container input[type="range"] {
    flex: 1;
}

.main-controls {
    display: flex;
    gap: 10px;
}

button {
    background: #333;
    border: 1px solid #555;
    color: white;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    transition: background 0.2s, transform 0.1s;
    font-family: inherit;
}

button:hover {
    background: #333;
}

button.primary {
    background: #cccccc;
    border-color: #cccccc;
    color: #222222;
    font-size: 0.9rem;
    font-weight: 800;
    padding: 12px 20px;
    letter-spacing: 0.5px;
}

button.primary:hover {
    background: #b0b0b0;
}

button.secondary {
    background: #333333;
    border-color: #444;
    color: #cccccc;
    font-size: 0.85rem;
}

button.secondary:hover {
    background: #444444;
}

button.warning-btn {
    background: #444;
    border-color: #555;
    color: #fff;
}

button.warning-btn:hover {
    background: #555;
}

button.danger {
    background: #000;
    border-color: #888;
    color: #fff;
}

button.danger:hover {
    background: #222;
}

button.outline-btn {
    background: transparent;
    border: 1px solid #888;
}

button.outline-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Status Active State (Inverted) */
.status-active {
    background-color: #ffffff !important;
    color: #000000 !important;
    border-color: #ffffff !important;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
}



.markers-section {
    background: #252525;
    border-radius: 8px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    flex: 1; /* カラムの下まで広げる */
    min-height: 0;
}

.markers-section h4 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: #bbb;
}

.marker-list {
    list-style: none;
    padding: 0;
    margin: 25px 0 0 0; /* ヘッダーとの間にさらに余裕を持たせる */
    overflow-y: auto;
    flex: 1; /* カラムの残り空間をすべて使い切る */
    min-height: 0;
}

.marker-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 15px; /* さらに広く */
    background: #333;
    margin-bottom: 10px; /* 余白を確保 */
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.marker-item:hover {
    background: #3a3a3a;
    transform: translateY(-1px);
}

.marker-item.is-looping {
    background: rgba(255, 255, 255, 0.1);
    border-right: 4px solid #ffffff;
}

.marker-color-btn {
    width: 20px; /* ハーフサイズに縮小 */
    height: 20px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    padding: 0;
    cursor: pointer;
    background: none;
    box-shadow: 0 1px 4px rgba(0,0,0,0.5);
    transition: transform 0.2s, box-shadow 0.2s;
}

.marker-color-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}

.marker-color-palette {
    display: none;
    background: rgba(30, 30, 30, 0.9);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 6px 8px;
    grid-template-columns: repeat(9, 1fr); /* 全9色を横並びで1行表示 */
    gap: 6px;
    z-index: 1000;
    border-radius: 8px;
    margin-top: 6px;
    width: auto;
    box-shadow: 0 4px 16px rgba(0,0,0,0.7);
}

.palette-color {
    width: 18px; /* チップも縮小 */
    height: 18px;
    border: 1.5px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.palette-color:hover {
    border-color: rgba(255, 255, 255, 0.8);
    transform: scale(1.2);
}

.palette-color.active {
    border-color: #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5);
}

.marker-loop-span {
    position: absolute;
    height: 8px; /* トラッカーの高さに合わせる */
    top: 50%;
    margin-top: -4px;
    opacity: 0.8;
    border-radius: 4px;
    pointer-events: none;
    z-index: 10;
    box-shadow: inset 0 0 5px rgba(255,255,255,0.5); /* Monochrome Glow */
}

.field-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.field-item label {
    font-size: 0.72rem;
    color: #aaa;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.field-item input[type="range"] {
    accent-color: #ffffff;
}

.field-item input[type="range"],
.field-item input[type="text"],
.field-item select,
.field-item textarea {
    width: 100%;
    box-sizing: border-box;
}

/* Generic Settings Block UI */
.settings-block {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid #444;
    margin-top: 5px;
    margin-bottom: 5px;
}

.settings-block .field-item label {
    font-size: 0.72rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: bold;
}

.settings-block h3 {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    color: #bbb;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid #333;
    padding-bottom: 5px;
}

input[type="text"],
textarea,
select {
    background: #333;
    border: 1px solid #555;
    color: white;
    padding: 10px;
    border-radius: 4px;
}

textarea {
    resize: vertical;
}

.toggle-switch {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
    font-weight: normal;
    color: #ccc;
    accent-color: #ffffff;
}

.marker-item.active {
    border-left: 4px solid #ffffff;
}

/* Markers on Timeline */
.marker-pin {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background-color: #ff9800;
    border: 2px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 9px;
    font-weight: bold;
    color: #000;
    box-shadow: 0 0 0 1px #000, 0 0 5px rgba(0, 0, 0, 0.5);
    z-index: 100 !important;
    pointer-events: auto;
    will-change: left; /* GPU加速を有効にしてドラッグの遅延（残像）を軽減 */
    /* Allow clicking the pin itself if needed */
}

.marker-pin:hover {
    background-color: #ffc107;
    transform: translate(-50%, -50%) scale(1.2);
    transition: transform 0.1s;
}

/* Marker Actions inside the List */
.marker-action {
    background: #222;
    border: 1px solid #555;
    color: #eee;
    font-size: 0.75rem;
    padding: 2px 4px;
    border-radius: 3px;
}

/* Program Monitor Scaling */
.program-monitor-viewport {
    width: 100%;
    aspect-ratio: 16 / 9;
    max-height: 360px;
    position: relative;
    overflow: hidden;
    background: #000;
    border-radius: 8px;
    transition: aspect-ratio 0.3s ease;
}

.vertical-mode .program-monitor-viewport {
    aspect-ratio: 9 / 16;
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 600px;
    margin: 0 auto;
}

.program-monitor-viewport iframe {
    position: absolute;
    top: 0;
    left: 0;
    border: none;
    transform-origin: 0 0;
    pointer-events: none;
}

/* Media Controls Grid */
.media-ctrl-grid {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
    align-items: stretch;
}

.media-btn-step {
    padding: 0 10px;
    background: #333;
    border: 1px solid #555;
    color: #fff;
    cursor: pointer;
    border-radius: 4px;
    font-weight: bold;
}

.media-btn-step:hover {
    background: #444;
}

/* Settings reset helper */
.resettable {
    cursor: pointer;
}

.resettable:hover {
    text-decoration: underline;
    text-decoration-style: dotted;
}