/* ══════════════════════════════════════════════════════════════
   SCHOOL BBS - Terminal Stylesheet
   Emulating a 1980s BBS on an amber/green phosphor CRT
   ══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=VT323&family=Share+Tech+Mono&display=swap');

:root {
    --phosphor: #33ff33;
    --phosphor-dim: #1a8c1a;
    --phosphor-bright: #66ff66;
    --phosphor-glow: rgba(51, 255, 51, 0.15);
    --amber: #ffb000;
    --amber-dim: #8c6000;
    --amber-bright: #ffc933;
    --bg: #0a0a0a;
    --bg-light: #111411;
    --bg-lighter: #1a1e1a;
    --bg-highlight: #1f2b1f;
    --border: #2a3a2a;
    --text: var(--phosphor);
    --text-dim: var(--phosphor-dim);
    --text-bright: var(--phosphor-bright);
    --error: #ff3333;
    --font-main: 'VT323', 'Courier New', monospace;
    --font-alt: 'Share Tech Mono', 'Courier New', monospace;
    --msg-speed: 20ms;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-main);
    font-size: 18px;
    line-height: 1.4;
}

/* ── CRT Effects ─────────────────────────────────────────── */

.crt {
    animation: flicker 0.15s infinite;
}

.crt::before {
    content: '';
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(ellipse at center, transparent 60%, rgba(0,0,0,0.4) 100%);
    pointer-events: none;
    z-index: 9998;
}

.scanlines {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 3px
    );
    pointer-events: none;
    z-index: 9999;
}

.crt-off .scanlines,
.crt-off::before {
    display: none;
}

.crt-off {
    animation: none;
}

@keyframes flicker {
    0% { opacity: 0.97; }
    50% { opacity: 1; }
    100% { opacity: 0.98; }
}

/* ── Modem Connection Overlay ────────────────────────────── */

.modem-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modem-text {
    font-family: var(--font-main);
    font-size: 16px;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-all;
    max-width: 600px;
    width: 100%;
    text-shadow: 0 0 8px var(--phosphor-glow);
}

/* ── Terminal Container ──────────────────────────────────── */

.terminal {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
}

.terminal-content {
    width: 100%;
    max-width: 600px;
}

/* ── ASCII Art Header ────────────────────────────────────── */

.ascii-header {
    font-family: var(--font-main);
    font-size: 14px;
    color: var(--text-bright);
    text-align: center;
    margin-bottom: 24px;
    text-shadow: 0 0 10px var(--phosphor-glow);
    line-height: 1.2;
    overflow-x: auto;
    white-space: pre;
}

.ascii-art {
    font-family: var(--font-main);
    font-size: 16px;
    color: var(--text-dim);
    text-align: center;
    text-shadow: 0 0 5px var(--phosphor-glow);
    white-space: pre;
}

/* ── BBS Box ─────────────────────────────────────────────── */

.bbs-box {
    border: 2px solid var(--border);
    padding: 20px;
    background: var(--bg-light);
    box-shadow: 0 0 20px rgba(51, 255, 51, 0.05), inset 0 0 30px rgba(0,0,0,0.5);
}

.bbs-box-title {
    text-align: center;
    color: var(--text-bright);
    margin-bottom: 16px;
    font-size: 20px;
    text-shadow: 0 0 10px var(--phosphor-glow);
}

/* ── Form Elements ───────────────────────────────────────── */

.form-row {
    margin-bottom: 12px;
}

.prompt {
    display: block;
    color: var(--text-bright);
    margin-bottom: 4px;
    font-size: 18px;
}

.bbs-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-main);
    font-size: 18px;
    padding: 8px 12px;
    outline: none;
    caret-color: var(--text-bright);
}

.bbs-input:focus {
    border-color: var(--text);
    box-shadow: 0 0 8px var(--phosphor-glow);
}

.bbs-input::placeholder {
    color: var(--text-dim);
    opacity: 0.5;
}

.bbs-select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-main);
    font-size: 18px;
    padding: 8px 12px;
    outline: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.bbs-select:focus {
    border-color: var(--text);
    box-shadow: 0 0 8px var(--phosphor-glow);
}

.bbs-select option {
    background: var(--bg);
    color: var(--text);
}

/* ── Buttons ─────────────────────────────────────────────── */

.bbs-btn {
    display: inline-block;
    background: var(--bg);
    border: 1px solid var(--text);
    color: var(--text-bright);
    font-family: var(--font-main);
    font-size: 18px;
    padding: 8px 16px;
    cursor: pointer;
    text-transform: uppercase;
    transition: all 0.1s;
    margin: 4px;
}

.bbs-btn:hover, .bbs-btn:focus {
    background: var(--text);
    color: var(--bg);
    text-shadow: none;
    box-shadow: 0 0 10px var(--phosphor-glow);
}

.bbs-btn:active {
    transform: scale(0.98);
}

.bbs-btn-small {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-main);
    font-size: 14px;
    padding: 4px 8px;
    cursor: pointer;
    transition: all 0.1s;
}

.bbs-btn-small:hover, .bbs-btn-small:focus {
    background: var(--text);
    color: var(--bg);
    text-shadow: none;
}

.form-actions {
    margin-top: 16px;
    text-align: center;
}

/* ── Error / Help Text ───────────────────────────────────── */

.error-msg {
    color: var(--error);
    text-align: center;
    padding: 8px;
    border: 1px solid var(--error);
    margin-bottom: 12px;
    background: rgba(255, 0, 0, 0.05);
}

.help-text {
    color: var(--text-dim);
    text-align: center;
    margin-top: 16px;
    font-size: 16px;
}

/* ── Status Bar ──────────────────────────────────────────── */

.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    background: var(--text);
    color: var(--bg);
    font-size: 14px;
    font-weight: bold;
    z-index: 100;
    flex-shrink: 0;
    min-height: 32px;
}

.status-bar .bbs-btn-small {
    color: var(--bg);
    border-color: var(--bg);
    font-size: 16px;
    padding: 2px 8px;
}

.status-bar .bbs-btn-small:hover {
    background: var(--bg);
    color: var(--text);
}

.status-center {
    display: none;
}

/* ── Chat Layout ─────────────────────────────────────────── */

.chat-layout {
    display: flex;
    height: calc(100vh - 32px);
    overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
    width: 300px;
    min-width: 300px;
    border-right: 2px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg-light);
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    color: var(--text-bright);
    font-size: 16px;
}

.sidebar-footer {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    border-top: 1px solid var(--border);
}

/* ── Conversation List ───────────────────────────────────── */

.convo-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) var(--bg);
}

.convo-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
}

.convo-item:hover {
    background: var(--bg-highlight);
}

.convo-item.active {
    background: var(--bg-highlight);
    border-left: 3px solid var(--text-bright);
}

.convo-item-name {
    color: var(--text-bright);
    font-size: 18px;
    margin-bottom: 2px;
}

.convo-item-preview {
    color: var(--text-dim);
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.convo-item-time {
    color: var(--text-dim);
    font-size: 12px;
    float: right;
}

.convo-item-unread .convo-item-name::before {
    content: '● ';
    color: var(--text-bright);
}

.loading-text {
    padding: 20px;
    text-align: center;
    color: var(--text-dim);
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* ── Chat Area ───────────────────────────────────────────── */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.no-convo {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.active-convo {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.convo-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-lighter);
    flex-shrink: 0;
}

.convo-title {
    color: var(--text-bright);
    font-size: 18px;
    flex: 1;
}

.typing-indicator {
    color: var(--text-dim);
    font-size: 14px;
    font-style: italic;
}

.back-btn {
    display: none;
}

/* ── Messages ────────────────────────────────────────────── */

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) var(--bg);
}

.message {
    padding: 4px 0;
    animation: fadeIn 0.3s ease-out;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message .msg-author {
    color: var(--text-bright);
    font-weight: bold;
}

.message .msg-time {
    color: var(--text-dim);
    font-size: 14px;
}

.message .msg-body {
    color: var(--text);
    margin-left: 2ch;
}

.message.msg-self .msg-author {
    color: var(--amber);
}

.message.msg-self .msg-body {
    color: var(--amber-bright);
}

.message.msg-system {
    color: var(--text-dim);
    text-align: center;
    font-style: italic;
    font-size: 14px;
}

.msg-date-divider {
    text-align: center;
    color: var(--text-dim);
    font-size: 14px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--border);
    margin-bottom: 4px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Message Input ───────────────────────────────────────── */

.message-input-area {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding: 8px 12px;
    border-top: 2px solid var(--border);
    background: var(--bg-lighter);
    flex-shrink: 0;
}

.input-prompt {
    color: var(--text-bright);
    font-size: 20px;
    line-height: 36px;
}

.msg-input {
    flex: 1;
    resize: none;
    min-height: 36px;
    max-height: 120px;
    line-height: 1.4;
}

/* ── Modal ───────────────────────────────────────────────── */

.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-box {
    width: 100%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-actions {
    margin-top: 16px;
    text-align: center;
}

/* ── User List (new convo modal) ─────────────────────────── */

.user-list {
    max-height: 200px;
    overflow-y: auto;
    margin: 8px 0;
    border: 1px solid var(--border);
}

.user-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.user-item:hover {
    background: var(--bg-highlight);
}

.user-item .online-dot {
    color: var(--text-bright);
}

.user-item .offline-dot {
    color: var(--text-dim);
}

.selected-users {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 8px 0;
}

.selected-tag {
    background: var(--bg-highlight);
    border: 1px solid var(--text);
    padding: 2px 8px;
    font-size: 14px;
    cursor: pointer;
}

.selected-tag:hover {
    background: var(--error);
    border-color: var(--error);
    color: var(--bg);
}

/* ── Settings ────────────────────────────────────────────── */

.settings-content {
    padding: 8px 0;
}

.settings-header {
    font-size: 14px;
    color: var(--text-dim);
    margin-bottom: 16px;
    white-space: pre;
    line-height: 1.3;
}

.ntfy-help {
    color: var(--text-dim);
    font-size: 14px;
    margin: 4px 0 16px 0;
}

.highlight {
    color: var(--text-bright);
}

/* ── Scrollbar Styling ───────────────────────────────────── */

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

::-webkit-scrollbar-track {
    background: var(--bg);
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border: 1px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-dim);
}

/* ── Text cursor blink ───────────────────────────────────── */

.cursor-blink::after {
    content: '█';
    animation: blink 0.7s step-end infinite;
}

/* ── Modem text crawl animation ──────────────────────────── */

.text-crawl {
    overflow: hidden;
}

.text-crawl .char {
    opacity: 0;
    animation: charAppear 0.01s forwards;
}

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

/* ══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    body {
        font-size: 16px;
    }

    .ascii-header {
        font-size: 9px;
        line-height: 1.1;
    }

    .status-bar {
        font-size: 12px;
        padding: 4px 8px;
    }

    .status-center {
        display: none;
    }

    /* Mobile: sidebar takes full width, chat takes full width */
    .chat-layout {
        position: relative;
    }

    .sidebar {
        width: 100%;
        min-width: 100%;
        position: absolute;
        top: 0; left: 0; bottom: 0;
        z-index: 50;
        transition: transform 0.2s ease;
    }

    .sidebar.hidden {
        transform: translateX(-100%);
    }

    .chat-area {
        width: 100%;
    }

    .back-btn {
        display: inline-block;
    }

    .bbs-box {
        padding: 12px;
    }

    .form-actions {
        display: flex;
        flex-direction: column;
    }

    .ascii-art {
        font-size: 12px;
    }

    .no-convo {
        padding: 20px;
    }

    .messages-container {
        padding: 8px;
    }

    .message-input-area {
        padding: 6px 8px;
    }

    .convo-header {
        padding: 6px 8px;
    }
}

@media (max-width: 400px) {
    .ascii-header {
        font-size: 7px;
    }

    body {
        font-size: 14px;
    }

    .bbs-btn {
        font-size: 16px;
        padding: 6px 12px;
    }
}

/* ── Selection color ─────────────────────────────────────── */

::selection {
    background: var(--text);
    color: var(--bg);
}

/* ── Focus visible for accessibility ─────────────────────── */

*:focus-visible {
    outline: 2px solid var(--text-bright);
    outline-offset: 2px;
}

/* ── Text shadow glow on all text ────────────────────────── */

body {
    text-shadow: 0 0 6px var(--phosphor-glow);
}
