:root {
    --bg-color: #000000;
    --color-accent-1: #cc0000; /* Klingon Red */
    --color-accent-2: #880000; /* Dark Blood Red */
    --color-accent-3: #ff6600; /* Aggressive Orange */
    --color-accent-4: #ffcc00; /* Warning Yellow */
    --color-accent-5: #ff0000; /* Alert Red */
    --color-accent-6: #220000; /* Deep Void Red */
    --color-accent-7: #ff9933; /* Flame Orange */
    
    --accent-color: var(--color-accent-1);
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --font-mono: 'JetBrains Mono', monospace;
    --font-sans: 'Inter', system-ui, sans-serif;
}

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

body {
    background-color: var(--bg-color);
    background-image: 
        linear-gradient(45deg, #110000 25%, transparent 25%), 
        linear-gradient(-45deg, #110000 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #110000 75%), 
        linear-gradient(-45deg, transparent 75%, #110000 75%);
    background-size: 40px 40px;
    background-position: 0 0, 0 20px, 20px 20px, 20px 0;
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.5rem;
}

/* Layout Elements */
.header-frame {
    height: 35px;
    display: flex;
    align-items: stretch;
    clip-path: polygon(0 0, 100% 0, 98% 100%, 2% 100%);
    border-bottom: 2px solid var(--color-accent-1);
}

.header-accent {
    width: 100px;
    background: var(--color-accent-2);
    clip-path: polygon(0 0, 100% 0, 80% 100%, 0% 100%);
    position: relative;
    flex-shrink: 0;
}

.header-bar {
    flex: 1;
    background: linear-gradient(90deg, var(--color-accent-2), var(--color-accent-6));
    display: flex;
    align-items: center;
    padding-right: 2rem;
    justify-content: center;
}

header, footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: 0;
}

.footer-frame {
    width: 100%;
    height: 30px;
    display: flex;
    align-items: stretch;
    clip-path: polygon(2% 0, 98% 0, 100% 100%, 0 100%);
    border-top: 2px solid var(--color-accent-1);
}

.footer-bar {
    flex: 1;
    background: linear-gradient(270deg, var(--color-accent-2), var(--color-accent-6));
    display: flex;
    align-items: center;
    padding-left: 2rem;
}

.footer-accent {
    width: 200px;
    background: var(--color-accent-2);
    clip-path: polygon(20% 0, 100% 0, 100% 100%, 0% 100%);
    position: relative;
    flex-shrink: 0;
}

main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    gap: 0.25rem;
    min-height: 0;
}

.column {
    display: flex;
    flex-direction: row;
    gap: 0.25rem;
    min-height: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.column::-webkit-scrollbar {
    display: none;
}

/* Middle column relative for handheld controls positioning */
.column:nth-child(2) {
    position: relative;
    flex-direction: column;
    overflow: hidden;
}

.flex-grow {
    flex: 1;
}

section {
    background: var(--color-accent-6);
    border: 1px solid var(--color-accent-2);
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 0;
    clip-path: polygon(5px 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%, 0 5px);
    min-width: 150px;
}

.column:nth-child(2) section {
    min-width: 0;
    clip-path: none;
    background: transparent;
    border: none;
}

/* Panels */
.panel-header {
    background: var(--color-accent-1);
    color: #ffffff;
    padding: 0.2rem 0.5rem;
    font-weight: 800;
    text-transform: uppercase;
    font-size: 0.6rem;
    text-align: left;
    clip-path: polygon(0 0, 85% 0, 100% 100%, 0 100%);
    margin-bottom: 0;
    border-bottom: 1px solid var(--color-accent-4);
}

.panel-content {
    padding: 0.4rem;
}

/* Typography */
h1 {
    font-size: 1rem;
    font-weight: 900;
    text-transform: uppercase;
    color: #ffffff;
    text-align: center;
    letter-spacing: 2px;
    text-shadow: 0 0 10px var(--color-accent-5);
}

.label-micro, .label-nano {
    font-size: 9px;
    text-transform: uppercase;
    color: var(--color-accent-3);
    font-weight: bold;
    font-family: var(--font-mono);
    letter-spacing: 1px;
}

/* Components */
.status-grid {
    display: flex;
    flex-direction: row;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.control-grid {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0.5rem;
    pointer-events: none;
    z-index: 20;
    height: 220px; /* Taller for larger buttons */
}

.control-grid > section {
    pointer-events: auto;
    width: 200px; /* Wider for larger buttons */
    background: rgba(34, 0, 0, 0.85);
    border: 2px solid var(--color-accent-1);
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.4);
    clip-path: polygon(15% 0, 85% 0, 100% 15%, 100% 85%, 85% 100%, 15% 100%, 0 85%, 0 15%);
    display: flex;
    flex-direction: column;
}

.d-pad-container {
    display: flex;
    justify-content: center;
    padding: 0.5rem;
}

.d-pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
}

.status-item {
    background: rgba(255, 0, 0, 0.1);
    border-left: 2px solid var(--color-accent-1);
    padding: 0.25rem 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.status-val {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--color-accent-3);
    font-weight: bold;
}

.btn {
    background: var(--color-accent-1);
    border: 2px solid var(--color-accent-4);
    color: #ffffff;
    padding: 0.25rem;
    clip-path: polygon(20% 0, 80% 0, 100% 20%, 100% 80%, 80% 100%, 20% 100%, 0 80%, 0 20%);
    cursor: pointer;
    font-weight: 900;
    font-size: 1.2rem; /* Larger arrows */
    text-transform: uppercase;
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 55px; /* Larger buttons */
    min-height: 55px;
}

.btn:hover {
    background: var(--color-accent-3);
    transform: scale(1.05);
    box-shadow: 0 0 15px var(--color-accent-3);
}

.btn:active {
    transform: scale(0.9);
    background: var(--color-accent-5);
}

.d-pad .btn {
    padding: 0;
}

.btn-primary { background: var(--color-accent-3); border-color: #fff; }
.btn-danger { background: var(--color-accent-5); border-color: #fff; }
.btn-warn { background: var(--color-accent-7); border-color: #fff; }

.viewport {
    position: relative;
    flex: 1;
    overflow: hidden;
    border: 2px solid var(--color-accent-1);
    clip-path: polygon(2% 0, 98% 0, 100% 2%, 100% 98%, 98% 100%, 2% 100%, 0 98%, 0 2%);
    background: #000;
}

.viewport img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: sepia(0.5) saturate(2) hue-rotate(-30deg) contrast(1.2);
    opacity: 0.8;
}

.viewport-label {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--color-accent-1);
    color: #fff;
    padding: 4px 12px;
    clip-path: polygon(0 0, 100% 0, 85% 100%, 0 100%);
    font-weight: 900;
    font-size: 11px;
    letter-spacing: 2px;
}

.telemetry-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.velocity-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-accent-2);
    padding: 0.5rem;
    border-right: 4px solid var(--color-accent-4);
}

.velocity-val {
    font-size: 1.1rem;
    color: var(--color-accent-4);
    text-shadow: 0 0 5px var(--color-accent-4);
}

textarea {
    width: 100%;
    background: #000;
    border: 1px solid var(--color-accent-1);
    color: var(--color-accent-3);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 0.5rem;
    resize: none;
}

.log-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.log-area {
    flex: 1;
    overflow-y: auto;
    background: #000;
    border: 1px solid var(--color-accent-2);
    padding: 0.25rem;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--color-accent-3);
    scrollbar-width: thin;
    scrollbar-color: var(--color-accent-1) #000;
    min-width: 200px;
}

.log-area p {
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(255, 0, 0, 0.1);
}

.tag {
    background: var(--color-accent-2);
    color: #fff;
    padding: 4px 10px;
    font-size: 10px;
    clip-path: polygon(10% 0, 100% 0, 90% 100%, 0 100%);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: bold;
}

.tag:hover {
    background: var(--color-accent-1);
}

.tag-active {
    background: var(--color-accent-3);
    color: #000;
}

.footer-stats {
    display: flex;
    gap: 1.5rem;
    font-weight: 900;
    font-size: 11px;
    color: #ffffff;
}

.data-value {
    color: var(--color-accent-4);
}

.system-status {
    color: #ffffff;
    font-weight: 900;
    font-size: 11px;
    padding: 10px 20px 0 0;
    text-align: right;
    letter-spacing: 2px;
}

.selection-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    overflow-y: auto;
}

/* Top Column: Horizontal distribution for Power and Sensors */
.column:nth-child(1) .selection-list {
    flex-direction: row;
    flex-wrap: wrap;
}

.column:nth-child(1) section {
    min-width: 0;
    flex: 1;
}

/* Bottom Column: Positioned between controls in a single row */
.column:nth-child(3) {
    position: absolute;
    bottom: 0.5rem;
    left: 210px; /* Offset by left control width */
    right: 210px; /* Offset by right control width */
    height: auto; /* Allow height to be determined by children */
    display: flex;
    flex-direction: row; /* Horizontal alignment */
    gap: 0.25rem;
    z-index: 15;
    background: transparent; /* Remove background from container */
    padding: 0;
    border: none;
    clip-path: none;
    align-items: flex-end; /* Align sections to the bottom */
}

.column:nth-child(3) section {
    min-width: 120px; /* Minimum width for each section */
    flex: 1;
    background: rgba(34, 0, 0, 0.9);
    border: 1px solid var(--color-accent-1);
    clip-path: polygon(5% 0, 95% 0, 100% 10%, 100% 100%, 0 100%, 0 10%);
    display: flex;
    flex-direction: column-reverse; /* Header at the bottom */
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    height: 30px; /* Collapsed height (header only) */
    overflow: hidden;
}

/* Expand on hover or focus-within */
.column:nth-child(3) section:hover,
.column:nth-child(3) section:focus-within {
    height: 210px; /* Expanded height matching controls */
    box-shadow: 0 0 20px rgba(255, 0, 0, 0.4);
    background: rgba(44, 0, 0, 0.95);
    z-index: 30;
}

.column:nth-child(3) section .panel-header {
    cursor: pointer;
    height: 30px;
    display: flex;
    align-items: center;
    border-bottom: none;
    border-top: 1px solid var(--color-accent-4); /* Border on top since it's at the bottom */
    clip-path: none; /* Reset clip path for the header */
    background: var(--color-accent-2);
}

.column:nth-child(3) section .panel-content {
    flex: 1;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease 0.1s;
    padding: 0.5rem;
    min-height: 0;
}

.column:nth-child(3) section:hover .panel-content,
.column:nth-child(3) section:focus-within .panel-content {
    opacity: 1;
    transform: translateY(0);
}

.operations-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    justify-content: center;
    height: 100%;
}

.log-area {
    flex: 1;
    overflow-y: auto;
    background: #000;
    border: 1px solid var(--color-accent-2);
    padding: 0.25rem;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--color-accent-3);
    scrollbar-width: thin;
    scrollbar-color: var(--color-accent-1) #000;
    min-width: 0;
    height: 100%;
}

.check-item, .radio-item {
    background: var(--color-accent-2);
    color: #ffffff;
    padding: 0.25rem 0.5rem;
    clip-path: polygon(0 0, 95% 0, 100% 100%, 5% 100%);
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.65rem;
    font-family: var(--font-mono);
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s;
}

.radio-item { background: var(--color-accent-6); border-left: 4px solid var(--color-accent-3); }
.check-item { background: var(--color-accent-6); border-left: 4px solid var(--color-accent-1); }

.radio-item:hover, .check-item:hover {
    background: var(--color-accent-2);
    padding-left: 1.5rem;
}

.multi-select-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: #000;
}
::-webkit-scrollbar-thumb {
    background: var(--color-accent-1);
}

