/* ============================================================================
   BB84 QUANTUM KEY DISTRIBUTION SIMULATOR - STYLESHEET
   ============================================================================ */

/* CSS Variables */
:root {
    /* Terminal Green Theme */
    --color-bg-primary: #0a0a0a;
    --color-bg-secondary: #001100;
    --color-bg-tertiary: #000000;
    --color-bg-overlay: rgba(0, 20, 0, 0.3);

    --color-green-primary: #33ff33;
    --color-green-bright: #44ff44;
    --color-green-dark: #003300;
    --color-green-darker: #001100;
    --color-green-shadow: rgba(0, 255, 0, 0.03);
    --color-green-glow: rgba(0, 255, 0, 0.5);

    --color-text-primary: #33ff33;
    --color-text-bright: #44ff44;
    --color-text-muted: #888888;
    --color-text-cyan: #00ffff;
    --color-text-blue: #00ccff;
    --color-text-yellow: #ffcc00;
    --color-text-orange: #ffaa00;
    --color-text-red: #ff6666;
    --color-text-blue-light: #66ccff;

    /* Breach Red Theme */
    --color-breach-bg: #1a0505;
    --color-breach-bg-dark: #100000;
    --color-breach-bg-darker: #200000;
    --color-breach-bg-accent: #400000;
    --color-breach-bg-hover: #600000;

    --color-breach-primary: #ff0000;
    --color-breach-bright: #ff4444;
    --color-breach-light: #ff8888;
    --color-breach-glow: rgba(255, 0, 0, 0.5);
    --color-breach-glow-strong: rgba(255, 0, 0, 0.8);
    --color-breach-shadow: rgba(80, 0, 0, 0.8);
    --color-breach-overlay: rgba(80, 0, 0, 0.15);

    /* Sizing */
    --chat-panel-width: 400px;
    --border-width: 2px;
    --border-width-thick: 3px;

    /* Animations */
    --transition-fast: 0.2s;
    --animation-blink: 1s;
    --animation-dots: 1.5s;
    --animation-pulse: 2s;

    /* Typography */
    --font-mono: 'Courier New', monospace;
    --font-size-base: 14px;
    --font-size-small: 12px;
    --font-size-smaller: 11px;
    --font-size-large: 16px;
    --font-size-xlarge: 18px;
    --font-size-xxlarge: 20px;
    --line-height-base: 1.6;
    --line-height-compact: 1.4;
    --line-height-relaxed: 1.5;
}

/* ============================================================================
   BASE STYLES
   ============================================================================ */

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

body {
    background: var(--color-bg-primary);
    min-height: 100vh;
    display: flex;
    padding: 0;
    font-family: var(--font-mono);
    overflow: hidden;
}

/* ============================================================================
   LAYOUT
   ============================================================================ */

.container {
    display: flex;
    width: 100%;
    height: 100vh;
    gap: 0;
}

/* ============================================================================
   CRT SCREEN EFFECTS
   ============================================================================ */

.screen {
    background: var(--color-bg-primary);
    padding: 0;
    box-shadow:
        inset 0 0 100px var(--color-green-shadow),
        inset 0 0 20px rgba(0, 0, 0, 0.8);
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Scanline effect */
.screen::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 10;
}

/* Glow effect */
body::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(
        ellipse at center,
        transparent 0%,
        rgba(0, 0, 0, 0.25) 100%
    );
    pointer-events: none;
    z-index: 5;
}

.screen-title {
    padding: 15px 20px 10px 20px;
    text-align: center;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.screen-title h1 {
    color: var(--color-green-primary);
    text-shadow: 0 0 5px var(--color-green-primary);
    font-size: var(--font-size-xxlarge);
    margin-bottom: 5px;
    letter-spacing: 2px;
}

.screen-title .screen-subtitle {
    color: var(--color-green-primary);
    text-shadow: 0 0 3px var(--color-green-primary);
    font-size: var(--font-size-small);
}

/* ============================================================================
   CHAT PANEL
   ============================================================================ */

.chat-panel {
    background: var(--color-bg-primary);
    width: var(--chat-panel-width);
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15),
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
    pointer-events: none;
    z-index: 10;
}

.chat-window {
    margin: 20px;
    border: var(--border-width) solid var(--color-green-primary);
    background: var(--color-bg-tertiary);
    display: flex;
    flex-direction: column;
    flex: 1;
    position: relative;
    z-index: 1;
    min-height: 0;
}

.chat-header {
    background: var(--color-bg-secondary);
    border-bottom: var(--border-width) solid var(--color-green-primary);
    padding: 8px 10px;
    text-align: center;
}

.chat-header h2 {
    color: var(--color-green-primary);
    text-shadow: 0 0 5px var(--color-green-primary);
    font-size: var(--font-size-base);
    margin-bottom: 5px;
}

.chat-messages {
    color: var(--color-green-primary);
    text-shadow: 0 0 3px var(--color-green-primary);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 15px;
}

#chatMessages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 5px;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#chatMessages::-webkit-scrollbar {
    width: 8px;
}

#chatMessages::-webkit-scrollbar-track {
    background: var(--color-bg-secondary);
}

#chatMessages::-webkit-scrollbar-thumb {
    background: var(--color-green-dark);
    border: 1px solid var(--color-green-primary);
}

#chatMessages::-webkit-scrollbar-thumb:hover {
    background: #004400;
}

.chat-message {
    margin-bottom: 15px;
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.chat-message .sender {
    color: var(--color-text-cyan);
    text-shadow: 0 0 5px var(--color-text-cyan);
    font-weight: bold;
    margin-bottom: 3px;
}

.chat-message.alice .sender {
    color: var(--color-green-primary);
    text-shadow: 0 0 5px var(--color-green-primary);
}

.chat-message.bob .sender {
    color: var(--color-text-blue);
    text-shadow: 0 0 5px var(--color-text-blue);
}

.chat-message.system .sender {
    color: var(--color-text-yellow);
    text-shadow: 0 0 5px var(--color-text-yellow);
}

.chat-message .message {
    color: var(--color-green-primary);
    text-shadow: 0 0 3px var(--color-green-primary);
    font-size: var(--font-size-small);
    line-height: var(--line-height-compact);
    padding-left: 10px;
    border-left: var(--border-width) solid var(--color-green-dark);
}

/* ============================================================================
   CONTROL PANEL
   ============================================================================ */

.control-panel {
    margin: 0 20px 20px 20px;
    border: var(--border-width) solid var(--color-green-primary);
    background: var(--color-bg-tertiary);
    position: relative;
    z-index: 1;
}

.panel-header {
    background: var(--color-bg-secondary);
    border-bottom: var(--border-width) solid var(--color-green-primary);
    padding: 8px 10px;
    text-align: center;
}

.panel-header h3 {
    color: var(--color-green-primary);
    text-shadow: 0 0 5px var(--color-green-primary);
    font-size: 13px;
    font-weight: bold;
}

.panel-content {
    padding: 15px;
}

.config-row {
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.config-label {
    color: var(--color-text-bright);
    font-size: var(--font-size-small);
}

.config-input {
    background: var(--color-bg-secondary);
    color: var(--color-green-primary);
    border: 1px solid var(--color-green-primary);
    padding: 5px 8px;
    font-family: var(--font-mono);
    font-size: var(--font-size-small);
    width: 80px;
    text-align: center;
}

.config-input:focus {
    outline: none;
    box-shadow: 0 0 5px var(--color-green-primary);
}

.checkbox-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

input[type="checkbox"] {
    display: none;
}

.ascii-checkbox {
    color: var(--color-green-primary);
    text-shadow: 0 0 3px var(--color-green-primary);
    font-size: var(--font-size-base);
    cursor: pointer;
    user-select: none;
    font-weight: bold;
}

.ascii-checkbox:hover {
    color: var(--color-text-bright);
    text-shadow: 0 0 5px var(--color-text-bright);
}

.panel-button {
    width: 100%;
    margin-top: 10px;
}

/* ============================================================================
   TERMINAL DISPLAY
   ============================================================================ */

.status-window {
    margin: 0 20px 15px 20px;
    border: var(--border-width) solid var(--color-green-primary);
    background: var(--color-bg-tertiary);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.terminal-window {
    margin: 0 20px 20px 20px;
    border: var(--border-width) solid var(--color-green-primary);
    background: var(--color-bg-tertiary);
    display: flex;
    flex-direction: column;
    flex: 1;
    position: relative;
    z-index: 1;
    min-height: 0;
}

.window-header {
    background: var(--color-bg-secondary);
    border-bottom: var(--border-width) solid var(--color-green-primary);
    padding: 8px 10px;
    text-align: center;
    flex-shrink: 0;
}

.window-header h2 {
    color: var(--color-green-primary);
    text-shadow: 0 0 5px var(--color-green-primary);
    font-size: var(--font-size-base);
    margin-bottom: 5px;
}

.window-header .window-subtitle {
    font-size: var(--font-size-smaller);
    color: var(--color-text-bright);
}

.terminal {
    color: var(--color-green-primary);
    text-shadow: 0 0 3px var(--color-green-primary);
    font-size: var(--font-size-base);
    line-height: var(--line-height-base);
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    padding: 15px;
}

.state-display {
    padding: 15px;
    position: relative;
    z-index: 1;
}

.state-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 13px;
}

.state-label {
    color: var(--color-green-primary);
}

.state-value {
    color: var(--color-green-primary);
    text-shadow: 0 0 3px var(--color-green-primary);
    font-weight: bold;
}

.state-value.active {
    color: var(--color-text-cyan);
    text-shadow: 0 0 5px var(--color-text-cyan);
}

.state-value.complete {
    color: var(--color-green-primary);
}

.state-value.pending {
    color: var(--color-text-muted);
}

.state-value.processing::after {
    content: '';
    animation: dots var(--animation-dots) steps(4, end) infinite;
}

@keyframes dots {
    0%,
    20% {
        content: '';
    }
    40% {
        content: '.';
    }
    60% {
        content: '..';
    }
    80%,
    100% {
        content: '...';
    }
}

/* ============================================================================
   CONTENT AREA
   ============================================================================ */

#content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 5px;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

#content::-webkit-scrollbar {
    width: 8px;
}

#content::-webkit-scrollbar-track {
    background: var(--color-bg-secondary);
}

#content::-webkit-scrollbar-thumb {
    background: var(--color-green-dark);
    border: 1px solid var(--color-green-primary);
}

#content::-webkit-scrollbar-thumb:hover {
    background: #004400;
}

.section {
    margin: 20px 0;
    padding: 0;
    border: none;
    background: transparent;
}

.section-title {
    color: var(--color-green-primary);
    text-shadow: 0 0 5px var(--color-green-primary);
    font-weight: bold;
    margin-bottom: 15px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-green-dark);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 13px;
}

.section-title.step-title {
    color: var(--color-text-cyan);
}

.section-title.collapsible {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.section-title.collapsible:hover {
    color: var(--color-text-bright);
    text-shadow: 0 0 8px var(--color-text-bright);
}

.section-title.collapsible::after {
    content: '[-]';
    font-size: 11px;
    color: var(--color-text-cyan);
}

.section-title.collapsible.collapsed::after {
    content: '[+]';
}

.section-content {
    overflow: hidden;
    transition: max-height 0.3s ease-out, opacity 0.2s ease-out;
}

.section-content.collapsed {
    max-height: 0 !important;
    opacity: 0;
}

.step-indicator {
    margin: 20px 0 15px 0;
    padding: 10px 0;
    font-size: var(--font-size-large);
    color: var(--color-text-cyan);
    text-shadow: 0 0 5px var(--color-text-cyan);
    border-top: 1px solid var(--color-green-dark);
    border-bottom: 1px solid var(--color-green-dark);
}

.status-line {
    margin: 5px 0;
}

.info-box {
    background: transparent;
    border: none;
    border-left: 2px solid var(--color-green-dark);
    padding: 10px 0 10px 15px;
    margin: 10px 0;
    font-size: var(--font-size-small);
    line-height: var(--line-height-relaxed);
}

.key-display {
    font-size: var(--font-size-base);
    padding: 15px;
    background: rgba(0, 30, 0, 0.4);
    border-left: 3px solid var(--color-green-primary);
    margin: 10px 0;
    word-break: break-all;
    font-family: var(--font-mono);
}

/* ============================================================================
   TABLES
   ============================================================================ */

table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
}

th,
td {
    padding: 5px;
    text-align: center;
    border: 1px solid var(--color-green-primary);
}

th {
    background: var(--color-green-dark);
    font-weight: bold;
}

td {
    background: var(--color-bg-overlay);
}

td.reveal {
    animation: cellReveal 0.1s forwards;
}

/* ============================================================================
   BUTTONS
   ============================================================================ */

button {
    background: #004400;
    color: var(--color-green-primary);
    border: var(--border-width) solid var(--color-green-primary);
    padding: 10px 15px;
    font-family: var(--font-mono);
    font-size: 13px;
    cursor: pointer;
    text-shadow: 0 0 3px var(--color-green-primary);
    transition: all var(--transition-fast);
    white-space: nowrap;
    flex: 1;
}

button:hover {
    background: #005500;
    box-shadow: 0 0 10px var(--color-green-primary);
}

button:active {
    background: var(--color-green-dark);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#resetBtn {
    display: none;
}

#resetBtn.visible {
    display: block;
}

#startBtn {
    display: block;
}

.control-buttons {
    margin: 10px 0;
    display: none;
    gap: 10px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}

/* ============================================================================
   MODALS
   ============================================================================ */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--color-bg-secondary);
    border: var(--border-width-thick) solid var(--color-green-primary);
    padding: 20px;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 0 30px var(--color-green-glow);
}

.modal-content h3 {
    color: var(--color-green-primary);
    text-shadow: 0 0 5px var(--color-green-primary);
    margin-bottom: 15px;
    font-size: var(--font-size-large);
    border-bottom: var(--border-width) solid var(--color-green-primary);
    padding-bottom: 10px;
}

.modal-content p {
    color: var(--color-green-primary);
    line-height: var(--line-height-base);
    margin-bottom: 10px;
    font-size: 13px;
}

.modal-content strong {
    color: var(--color-text-bright);
    text-shadow: 0 0 3px var(--color-text-bright);
}

.modal-content ul {
    margin: 10px 0 10px 20px;
    color: var(--color-green-primary);
}

.modal-content li {
    margin-bottom: 5px;
    line-height: var(--line-height-relaxed);
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: var(--color-green-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: auto;
    line-height: 1;
}

.modal-close:hover {
    color: var(--color-breach-bright);
    text-shadow: 0 0 10px var(--color-breach-bright);
}

/* ============================================================================
   HELP ICON
   ============================================================================ */

.help-icon {
    display: inline-block;
    background: transparent;
    color: var(--color-text-yellow);
    border: var(--border-width) solid var(--color-text-yellow);
    border-radius: 0;
    width: 18px;
    height: 18px;
    text-align: center;
    line-height: 14px;
    font-size: var(--font-size-small);
    font-weight: bold;
    cursor: pointer;
    margin-left: 8px;
    box-shadow: 0 0 5px var(--color-text-yellow);
    transition: all var(--transition-fast);
}

.help-icon:hover {
    background: rgba(255, 204, 0, 0.2);
    box-shadow: 0 0 10px var(--color-text-yellow);
    transform: scale(1.1);
}

/* ============================================================================
   SECURITY BREACH STYLING
   ============================================================================ */

body.breach {
    background: var(--color-breach-bg);
}

.screen.breach {
    background: var(--color-breach-bg);
    box-shadow:
        inset 0 0 100px rgba(255, 0, 0, 0.15),
        inset 0 0 20px var(--color-breach-shadow);
}

.screen.breach::before {
    background: repeating-linear-gradient(
        0deg,
        var(--color-breach-overlay),
        var(--color-breach-overlay) 1px,
        transparent 1px,
        transparent 2px
    );
}

.chat-panel.breach {
    background: var(--color-breach-bg);
    border-left-color: var(--color-breach-primary);
}

.chat-panel.breach::before {
    background: repeating-linear-gradient(
        0deg,
        var(--color-breach-overlay),
        var(--color-breach-overlay) 1px,
        transparent 1px,
        transparent 2px
    );
}

.chat-window.breach {
    border-color: var(--color-breach-primary);
    background: var(--color-breach-bg-dark);
    box-shadow: 0 0 20px var(--color-breach-glow);
}

.chat-window.breach .chat-header {
    border-bottom-color: var(--color-breach-primary);
    background: var(--color-breach-bg-darker);
}

.chat-window.breach .chat-header h2 {
    color: var(--color-breach-primary);
    text-shadow: 0 0 10px var(--color-breach-primary);
}

.terminal.breach {
    color: var(--color-breach-light);
    text-shadow: 0 0 5px var(--color-breach-bright);
}

.status-window.breach,
.terminal-window.breach {
    border-color: var(--color-breach-primary);
    background: var(--color-breach-bg-dark);
    box-shadow: 0 0 20px var(--color-breach-glow);
}

.status-window.breach .window-header,
.terminal-window.breach .window-header {
    border-bottom-color: var(--color-breach-primary);
    background: var(--color-breach-bg-darker);
}

.status-window.breach .window-header h2,
.status-window.breach .window-header .window-subtitle,
.terminal-window.breach .window-header h2,
.terminal-window.breach .window-header .window-subtitle {
    color: var(--color-breach-primary);
    text-shadow: 0 0 10px var(--color-breach-primary);
}

.terminal.breach .state-display {
    border-color: var(--color-breach-primary);
    background: rgba(80, 0, 0, 0.3);
}

.control-panel.breach {
    border-color: var(--color-breach-primary);
    background: var(--color-breach-bg-dark);
    box-shadow: 0 0 20px var(--color-breach-glow);
}

.control-panel.breach .panel-header {
    border-bottom-color: var(--color-breach-primary);
    background: var(--color-breach-bg-darker);
}

.control-panel.breach .panel-header h3 {
    color: var(--color-breach-primary);
    text-shadow: 0 0 10px var(--color-breach-primary);
}

/* Breach Modal */
#breachModal .modal-content {
    background: var(--color-breach-bg-darker);
    border: var(--border-width-thick) solid var(--color-breach-primary);
    box-shadow: 0 0 50px var(--color-breach-glow-strong);
}

#breachModal .modal-content h3 {
    color: var(--color-breach-primary);
    text-shadow: 0 0 10px var(--color-breach-primary);
    border-bottom-color: var(--color-breach-primary);
    font-size: var(--font-size-xlarge);
}

#breachModal .modal-content p {
    color: var(--color-breach-light);
}

#breachModal .modal-content strong {
    color: var(--color-breach-bright);
    text-shadow: 0 0 5px var(--color-breach-primary);
}

.breach-acknowledge {
    width: 100%;
    padding: 15px;
    margin-top: 20px;
    background: var(--color-breach-bg-accent);
    color: var(--color-breach-primary);
    border: var(--border-width) solid var(--color-breach-primary);
    font-size: var(--font-size-base);
    font-weight: bold;
    cursor: pointer;
    animation: pulse var(--animation-pulse) infinite;
}

.breach-acknowledge:hover {
    background: var(--color-breach-bg-hover);
    box-shadow: 0 0 20px var(--color-breach-primary);
}

/* ============================================================================
   HIGHLIGHTING & EMPHASIS
   ============================================================================ */

.highlight-key {
    color: var(--color-text-orange);
    text-shadow: 0 0 3px var(--color-text-orange);
}

.highlight-important {
    color: var(--color-text-red);
    text-shadow: 0 0 3px var(--color-text-red);
}

.highlight-info {
    color: var(--color-text-blue-light);
    text-shadow: 0 0 3px var(--color-text-blue-light);
}

.match {
    color: var(--color-text-cyan);
    text-shadow: 0 0 5px var(--color-text-cyan);
}

.error {
    color: var(--color-breach-bright);
    text-shadow: 0 0 5px var(--color-breach-bright);
}

.highlight {
    background: rgba(0, 100, 0, 0.4) !important;
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

.blink {
    animation: blink var(--animation-blink) infinite;
}

.typing {
    opacity: 0;
    animation: fadeIn 0.3s forwards;
}

.processing {
    display: inline-block;
}

.processing::after {
    content: '';
    animation: dots var(--animation-dots) steps(4, end) infinite;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

@keyframes blink {
    0%,
    50% {
        opacity: 1;
    }
    51%,
    100% {
        opacity: 0;
    }
}

@keyframes dots {
    0%,
    20% {
        content: '';
    }
    40% {
        content: '.';
    }
    60% {
        content: '..';
    }
    80%,
    100% {
        content: '...';
    }
}

@keyframes pulse {
    0%,
    100% {
        box-shadow: 0 0 10px var(--color-breach-glow);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 0 25px rgba(255, 0, 0, 0.9);
        transform: scale(1.02);
    }
}

@keyframes cellReveal {
    from {
        background: rgba(0, 255, 0, 0.3);
        transform: scale(1.1);
    }
    to {
        background: var(--color-bg-overlay);
        transform: scale(1);
    }
}

/* ============================================================================
   LEGEND
   ============================================================================ */

.legend {
    display: flex;
    gap: 20px;
    margin: 10px 0;
    font-size: var(--font-size-small);
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
}
