@font-face {
    font-family: 'C059';
    src: url('https://braindrop.dev/C059-Roman.woff2') format('woff2'),
         url('https://braindrop.dev/C059-Roman.woff') format('woff');
    font-weight: normal;
    font-style: normal;
    font-display: swap;
}

:root {
    --accent:       #61dafb;
    --dark:         #282c34;
    --bg:           #f5f5f5;
    --white:        #ffffff;
    --text:         #333;
    --text-muted:   #666;
    --text-light:   #999;
    --border:       #ddd;
    --pad-size:     300px;
}

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

body {
    font-family: 'C059', Georgia, 'Times New Roman', serif;
    font-size: 18px;
    line-height: 1.6;
    background-color: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
    padding-top: 60px;
    padding-bottom: 77px;
}

html {
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

/* ============================================================
   HEADER
   ============================================================ */

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--dark);
    padding: 15px;
    z-index: 1000;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1100px;
    margin: 0 auto;
}

.site-title {
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: white;
    text-decoration: none;
    letter-spacing: 0.02em;
}

.site-title span {
    color: var(--accent);
}

nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 0;
}

nav ul li {
    font-family: 'Courier New', monospace;
    font-size: 1rem;
    color: white;
    margin: 0 20px;
    cursor: pointer;
}

nav ul li a {
    color: white;
    text-decoration: none;
    transition: color 0.2s;
}

nav ul li a:hover { color: var(--accent); }

.connect-btn {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    padding: 6px 16px;
    border: 1px solid white;
    background: transparent;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}

.connect-btn:hover { border-color: var(--accent); color: var(--accent); }
.connect-btn.connected { border-color: #22c55e; color: #22c55e; }
.connect-btn.connected::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    margin-right: 6px;
    animation: pulse 2s infinite;
    vertical-align: middle;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.mobile-nav-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

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

.main {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px;
}

.panel {
    background: var(--white);
    border: 1px solid var(--border);
    padding: 24px;
    margin: 10px;
}

.panel-title {
    font-family: 'Courier New', monospace;
    font-size: 0.72rem;
    font-weight: normal;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 18px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

/* ============================================================
   XY PAD
   ============================================================ */

.pad-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.xy-pad {
    width: var(--pad-size);
    height: var(--pad-size);
    background: var(--white);
    border: 1px solid var(--border);
    position: relative;
    cursor: crosshair;
    touch-action: none;
    overflow: hidden;
}

/* Grid lines */
.xy-pad::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(var(--border) 1px, transparent 1px),
        linear-gradient(90deg, var(--border) 1px, transparent 1px);
    background-size: calc(var(--pad-size) / 4) calc(var(--pad-size) / 4);
}

/* Crosshair centre lines */
.xy-pad::after {
    content: '';
    position: absolute;
    inset: 0;
    background:
        linear-gradient(0deg, transparent calc(50% - 0.5px), #bbb calc(50% - 0.5px), #bbb calc(50% + 0.5px), transparent calc(50% + 0.5px)),
        linear-gradient(90deg, transparent calc(50% - 0.5px), #bbb calc(50% - 0.5px), #bbb calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.pad-cursor {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--dark);
    position: absolute;
    transform: translate(-50%, -50%);
    left: 50%;
    top: 50%;
    z-index: 2;
    box-shadow: 0 0 10px rgba(97, 218, 251, 0.5);
    transition: left 0.05s, top 0.05s;
    pointer-events: none;
}

.axis-labels {
    position: absolute;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    color: var(--text-muted);
    z-index: 3;
    pointer-events: none;
}

.label-left  { left: 4px;  top: 50%;  transform: translateY(-50%); }
.label-right { right: 4px; top: 50%;  transform: translateY(-50%); }
.label-top   { top: 4px;   left: 50%; transform: translateX(-50%); }
.label-bottom{ bottom: 4px;left: 50%; transform: translateX(-50%); }

.pad-labels {
    width: var(--pad-size);
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-family: 'Courier New', monospace;
    font-size: 10px;
    color: var(--text-muted);
}

.readout {
    font-family: 'Courier New', monospace;
    font-size: 28px;
    font-weight: bold;
    text-align: center;
    margin-top: 14px;
    color: var(--text);
}

.readout small {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    font-weight: normal;
    color: var(--text-muted);
    display: block;
    margin-top: 4px;
}

/* ============================================================
   CONTROLS
   ============================================================ */

.control-group {
    margin-bottom: 18px;
}

.control-label {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
}

.control-label .value {
    color: var(--text);
    font-weight: bold;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--dark);
    cursor: pointer;
    border: 2px solid var(--bg);
    box-shadow: 0 0 0 1px var(--dark);
}

input[type="number"],
input[type="text"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text);
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    outline: none;
}

input[type="number"]:focus,
input[type="text"]:focus {
    border-color: var(--accent);
    outline: 1px solid var(--accent);
}

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.btn {
    font-family: 'Courier New', monospace;
    font-size: 0.78rem;
    padding: 8px 16px;
    border: 1px solid var(--border);
    background: var(--white);
    color: var(--text);
    cursor: pointer;
    transition: all 0.15s;
    flex: 1;
    text-align: center;
}

.btn:hover { border-color: var(--dark); color: var(--dark); }
.btn.primary { background: var(--dark); color: white; border-color: var(--dark); }
.btn.primary:hover { background: #1a1d23; }
.btn.danger { border-color: #c0392b; color: #c0392b; }
.btn.danger:hover { background: #c0392b; color: white; }

/* ============================================================
   SERIAL LOG
   ============================================================ */

.log-panel {
    grid-column: 1 / -1;
}

.log {
    font-family: 'Courier New', monospace;
    font-size: 11px;
    background: var(--dark);
    border: 1px solid #1a1d23;
    padding: 12px;
    height: 140px;
    overflow-y: auto;
    color: #aaa;
    line-height: 1.7;
}

.log .rx  { color: #22c55e; }
.log .tx  { color: var(--accent); }
.log .err { color: #c0392b; }

/* ============================================================
   FOOTER (loaded from braindrop.dev)
   ============================================================ */

footer {
    text-align: center;
    padding: 0 10px;
    background-color: var(--dark);
    color: white;
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 77px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.footer-content { width: 100%; }
.footer-column { display: flex; justify-content: center; }
.social-links { display: flex; align-items: center; padding-top: 5px; }
.footer-content p { margin: 0 0 10px 0; font-size: 0.9rem; font-family: 'Courier New', monospace; }

.social-link,
.has-popover {
    display: inline-block;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
    padding: 10px;
}

.icon-fa { font-size: 1.8rem; color: white; transition: color 0.3s ease; line-height: 1; }
.social-link:hover .icon-fa,
.has-popover:hover .icon-fa { color: var(--accent); }

.has-popover { position: relative; }

.popover-text {
    visibility: hidden;
    opacity: 0;
    width: 200px;
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 8px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    transition: opacity 0.3s ease, visibility 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
}

.popover-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #333 transparent transparent transparent;
}

.has-popover:hover .popover-text { visibility: visible; opacity: 1; bottom: 130%; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 768px) {
    .main { grid-template-columns: 1fr; padding: 16px; }
    :root { --pad-size: 260px; }

    .header-content { justify-content: space-between; }
    nav ul { display: none; flex-direction: column; position: absolute; top: 100%; left: 0;
             width: 100%; background-color: var(--dark); padding: 0 0 1rem; }
    nav ul.active { display: flex; }
    nav ul li { margin: 0; padding: 0.5rem 1rem; text-align: center; }
    .mobile-nav-toggle { display: block; }
}

@media (min-width: 769px) {
    .mobile-nav-toggle { display: none; }
}
