body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    background-color: grey;
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: border-box;
}

.page-container {
    display: flex;
    flex-direction: column;
    align-items: center; /* Center content to prevent overflow */
    height: 100vh; /* Full viewport height */
    max-height: 100vh; /* Ensure it doesn't exceed viewport height */
    overflow: hidden; /* Hide overflow */
}

.content-area {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-top: 58px;
    padding-left: 5px;
}

.feed-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    overflow: hidden;
    position: relative;
    background-color: #000;
}

.main-feed {
    /* Start with full width, but allow shrinking */
    width: 100%;
    height: auto;

    /* Constrain by container dimensions */
    max-width: 100%;
    max-height: 100%;

    /* Enforce aspect ratio */
    aspect-ratio: 16/9;

    /* Center in container */
    margin: auto;

    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

/* For very wide screens (ultrawide), switch to height-based sizing to prevent overflow */
@media (min-aspect-ratio: 2/1) {
    .main-feed {
        height: 100%;
        width: auto;
    }
}

.largeIframe, .largeCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.largeIframe {
    z-index: 1;
}

.largeCanvas {
    pointer-events: auto;
}

#overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

#drawingLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
}

#drawingLayer.pen-active {
    z-index: 3;
    pointer-events: auto;
}

.SidePanel {
    height: 100%;
    width: 22%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: #18181b;
    overflow: hidden;
    margin: 8px;
}

.OBS_Controls {
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    margin-bottom: 4px;
    height: 320px;
}

#obs.smallIframe {
    width: 400px;
    min-width: 300px;
    max-width: 100%;
    height: 100%;
    min-height: 200px;
    max-height: 100%;
    flex-shrink: 0;
    border-radius: 8px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
    background: #111;
}

.Chat {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #18181b;
    border-radius: 8px;
    overflow: hidden;
}

#chat.smallIframe {
    width: 100%;
    height: 100%;
    border: none;
    background: #18181b;
    object-fit: cover;
    display: block;
    overflow: hidden;
    transform: scale(1);
}

iframe {
    border: none !important;
    outline: none !important;
}

#feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border: none;
    outline: none;
}

/* OBS Control Panel Styles */
.obs-control-group {
    display: flex;
    flex-direction: row;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.obs-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-indicator {
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

.status-indicator.disconnected {
    background-color: #dc3545;
    color: white;
}

.status-indicator.connected {
    background-color: #28a745;
    color: white;
}

.obs-scenes {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.scene-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.scene-buttons {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.scene-btn {
    padding: 6px 12px;
    background-color: #444;
    color: white;
    border: 2px solid #666;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.scene-btn:hover {
    background-color: #555;
}

.scene-btn.active {
    background-color: #4caf50;
    border-color: #4caf50;
}

.scene-dropdown {
    display: flex;
    gap: 5px;
    align-items: center;
}

.scene-dropdown label {
    color: white;
    font-size: 12px;
}

.scene-dropdown select {
    padding: 4px 8px;
    background-color: #333;
    color: white;
    border: 1px solid #666;
    border-radius: 4px;
    font-size: 12px;
}

.stream-controls {
    display: flex;
    gap: 5px;
}

.obs-btn {
    padding: 6px 12px;
    background-color: #2196f3;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

.obs-btn:hover:not(:disabled) {
    background-color: #1976d2;
}

.obs-btn:disabled {
    background-color: #666;
    cursor: not-allowed;
    opacity: 0.5;
}

.obs-btn.streaming {
    background-color: #dc3545;
}

.obs-btn.streaming:hover {
    background-color: #c82333;
}

.toolbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4px;
    background-color: #f5f5f5;
    border-radius: 5px;
}

.tool-group {
    display: flex;
    gap: 5px;
    align-items: center;
    flex-shrink: 0;
    height: 32px; /* Fixed height to fit within top bar */
}

.shortcut-help {
    margin-left: 15px;
    font-size: 12px;
    color: #fff;
    font-style: italic;
}

.letter-selector {
    display: flex;
    align-items: center;
    gap: 5px;
}

.letter-selector select {
    padding: 5px;
    font-size: 16px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background-color: white;
}

.tool-btn {
    padding: 4px;
    font-size: 18px;
    border: 2px solid #444;
    border-radius: 4px;
    background-color: #333;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 32px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tool-btn:hover {
    background-color: #444;
    transform: scale(1.05);
}

.tool-btn.active {
    border-color: #4caf50;
    background-color: #1b5e20;
}

.tool-info {
    font-size: 14px;
    color: #666;
    text-align: center;
}

.config-panel {
    background-color: #f5f5f5;
    padding: 20px;
    border-radius: 5px;
    margin: 10px 0;
    transition: max-height 0.3s ease-out;
    overflow: hidden;
}

.config-panel.hidden {
    max-height: 0;
    padding: 0;
    margin: 0;
}

.config-section {
    margin-bottom: 20px;
}

.config-section h3 {
    margin: 0 0 10px 0;
    color: #333;
}

.input-group {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.input-group input,
.input-group select {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.input-group input[readonly] {
    background-color: #eee;
}

.input-group button {
    padding: 8px 16px;
    background-color: #4caf50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.input-group button:hover {
    background-color: #45a049;
}

#copyShareUrl {
    background-color: #2196f3;
}

#copyShareUrl:hover {
    background-color: #1976d2;
}

.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: rgba(33, 33, 33, 0.95);
    padding: 8px 10px;
    z-index: 1000;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 16px;
    height: 40px;
    overflow-x: auto;
    overflow-y: visible;
}

.minimal-controls {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-right: 16px;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s;
    min-width: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.icon-btn.active {
    background-color: rgba(76, 175, 80, 0.3);
}

.tool-panel {
    background-color: transparent;
    transition: all 0.3s ease;
    overflow: hidden;
    max-width: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
    white-space: nowrap;
    flex-shrink: 0;
}

.tool-panel.hidden {
    max-width: 0;
    opacity: 0;
    padding: 0;
    margin: 0;
    visibility: hidden;
}

.tool-panel:not(.hidden) {
    max-width: none;
    opacity: 1;
    padding: 0 0px;
    visibility: visible;
}

.settings-group {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-shrink: 0;
    height: 32px; /* Fixed height to fit within top bar */
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    flex-shrink: 0;
}

.setting-item label {
    color: white;
    min-width: 50px;
}

.setting-item input {
    padding: 6px 10px;
    border: 1px solid #444;
    border-radius: 4px;
    background-color: #333;
    color: white;
    width: 100px;
    min-width: 0;
    height: 32px;
}

.setting-item input[type="number"] {
    width: 50px;
}

.setting-item button {
    padding: 6px 12px;
    background-color: #4caf50;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    height: 32px;
    white-space: nowrap;
}

.setting-item button:hover {
    background-color: #45a049;
}

.tool-select {
    padding: 6px;
    font-size: 14px;
    border: 2px solid #444;
    border-radius: 4px;
    background-color: #333;
    color: white;
    height: 32px;
}

/* Add custom scrollbar styling */
.top-bar::-webkit-scrollbar {
    height: 6px;
}

.top-bar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.top-bar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.top-bar::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Adjust top bar to not hide tooltips */
.top-bar::after {
    z-index: 1001;
}

#GridElement {
    color: #666; /* Default grey color when grid is off */
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    transition: color 0.2s ease;
}

#GridElement.active {
    color: white; /* White color when grid is shown */
}

/* Viewer mode canvas elements - both the element and renderer need to be 1920x1080 */
body.viewer-mode .largeIframe,
body.viewer-mode .largeCanvas {
    width: 1920px !important;
    height: 1080px !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

body.viewer-mode #overlay {
    width: 1920px !important;
    height: 1080px !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

body.viewer-mode #drawingLayer {
    width: 1920px !important;
    height: 1080px !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Viewer Mode Container Styles - Enforce strict 0,0 positioning */
body.viewer-mode {
    background-color: transparent !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    width: 1920px !important;
    height: 1080px !important;
}

body.viewer-mode .page-container,
body.viewer-mode .content-area,
body.viewer-mode .feed-container {
    width: 1920px !important;
    height: 1080px !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    background: transparent !important;
    overflow: hidden !important;
    display: block !important; /* Override flex if needed */
}

body.viewer-mode .main-feed {
    width: 1920px !important;
    height: 1080px !important;
    max-width: none !important;
    max-height: none !important;
    aspect-ratio: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    box-shadow: none !important;
    background: transparent !important;
    display: block !important;
}

body.viewer-mode .top-bar,
body.viewer-mode .SidePanel,
body.viewer-mode .footer {
    display: none !important;
}
