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

body {
    font-family: 'Courier New', monospace;
    background: transparent;
    color: #e0e0e0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
    overflow-x: hidden;
    position: relative;
}

/* Background matching website */
#bg {
    -moz-transform: scale(1.0);
    -webkit-transform: scale(1.0);
    -ms-transform: scale(1.0);
    transform: scale(1.0);
    -webkit-backface-visibility: hidden;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 1;
}

#bg:before, #bg:after {
    content: '';
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#bg:before {
    -moz-transition: background-color 2.5s ease-in-out;
    -webkit-transition: background-color 2.5s ease-in-out;
    -ms-transition: background-color 2.5s ease-in-out;
    transition: background-color 2.5s ease-in-out;
    -moz-transition-delay: 0.75s;
    -webkit-transition-delay: 0.75s;
    -ms-transition-delay: 0.75s;
    transition-delay: 0.75s;
    background-image: linear-gradient(to top, rgba(19, 21, 25, 0.5), rgba(19, 21, 25, 0.5)), url("../images/overlay.png");
    background-size: auto, 256px 256px;
    background-position: center, center;
    background-repeat: no-repeat, repeat;
    z-index: 2;
}

#bg:after {
    -moz-transform: scale(1.125);
    -webkit-transform: scale(1.125);
    -ms-transform: scale(1.125);
    transform: scale(1.125);
    -moz-transition: -moz-transform 0.325s ease-in-out, -moz-filter 0.325s ease-in-out;
    -webkit-transition: -webkit-transform 0.325s ease-in-out, -webkit-filter 0.325s ease-in-out;
    -ms-transition: -ms-transform 0.325s ease-in-out, -ms-filter 0.325s ease-in-out;
    transition: transform 0.325s ease-in-out, filter 0.325s ease-in-out;
    background-image: url("../images/bg.jpg");
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    z-index: 1;
}

#app {
    width: 100%;
    max-width: 720px;
    position: relative;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.screen {
    width: 100%;
}

.hidden {
    display: none !important;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
    overflow-y: auto;
}

/* ASCII Box Styling */
.ascii-box {
    background: rgba(19, 21, 25, 0.85);
    border: 2px solid rgba(255, 255, 255, 0.2);
    padding: 20px;
    text-align: center;
    backdrop-filter: blur(4px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
    position: relative;
    width: 100%;
}

.ascii-box pre {
    margin: 0;
    color: #fff;
    font-size: 1.1em;
    white-space: pre;
}

.title {
    font-size: 1.2em;
    margin-bottom: 16px;
}

.content {
    margin-top: 16px;
    line-height: 1.7;
}

.instructions {
    text-align: left;
    margin: 18px auto;
    padding: 14px;
    background: rgba(19, 21, 25, 0.6);
    border-left: 3px solid #c9a86a;
    backdrop-filter: blur(2px);
    max-width: 520px;
}

.start-prompt {
    margin-top: 24px;
    font-size: 1.05em;
    color: #c9a86a;
}

.tap-start {
    margin-top: 12px;
    padding: 12px 32px;
    background: rgba(201, 168, 106, 0.12);
    color: #c9a86a;
    border: 2px solid #c9a86a;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 1.1em;
    letter-spacing: 0.2em;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.tap-start:hover {
    background: rgba(201, 168, 106, 0.25);
    color: #fff;
}

/* Close button */
.close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    line-height: 32px;
    text-align: center;
    font-size: 1.8em;
    color: #ffffff;
    text-decoration: none;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    background: rgba(19, 21, 25, 0.6);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(2px);
}

.close-button:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    color: #ff4444;
    transform: scale(1.1);
}

/* ============ Trainer screen ============ */

.trainer-box {
    padding: 14px 14px 22px;
    max-width: 640px;
    margin: 0 auto;
}

.trainer-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 18px;
    margin-bottom: 12px;
    color: #c9a86a;
    font-weight: bold;
    letter-spacing: 0.25em;
    font-size: 1.1em;
}

.hdr-word {
    text-shadow: 0 0 4px rgba(201, 168, 106, 0.4);
}

.hdr-sep {
    color: rgba(201, 168, 106, 0.5);
    font-size: 1.2em;
}

/* Card / PCB */
.card {
    background:
        radial-gradient(ellipse at top, rgba(201, 168, 106, 0.08), transparent 60%),
        linear-gradient(180deg, #0a0a0a 0%, #161616 50%, #1a1a1a 100%);
    border: 3px solid #c9a86a;
    border-radius: 14px;
    padding: 18px 8px 22px;
    margin: 0 auto;
    width: 100%;
    max-width: 560px;
    box-shadow:
        inset 0 0 24px rgba(201, 168, 106, 0.10),
        0 4px 14px rgba(0, 0, 0, 0.5);
    position: relative;
}

.card::before {
    /* Subtle solder-mask noise via dots */
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 10px;
    background-image:
        radial-gradient(circle at 20% 30%, rgba(201, 168, 106, 0.06) 0 1px, transparent 1px),
        radial-gradient(circle at 80% 70%, rgba(201, 168, 106, 0.05) 0 1px, transparent 1px),
        radial-gradient(circle at 60% 20%, rgba(201, 168, 106, 0.04) 0 1px, transparent 1px);
    background-size: 40px 40px, 60px 60px, 50px 50px;
    pointer-events: none;
    opacity: 0.6;
}

/* Tree */
.tree {
    display: grid;
    grid-template-columns: repeat(31, 1fr);
    grid-auto-rows: minmax(34px, auto);
    row-gap: 26px;
    align-items: start;
    justify-items: center;
    position: relative;
    z-index: 1;
}

/* SVG layer drawn UNDER the nodes; carries the actual chain lines */
.tree-traces {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: visible;
}

.tree-traces .trace {
    fill: none;
    stroke: #c9a86a;
    stroke-width: 1.6;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: 0.85;
    transition: stroke 0.08s ease, opacity 0.08s ease, filter 0.08s ease;
}

.tree-traces .trace.lit-trace {
    stroke: #5cff5c;
    stroke-width: 2.2;
    opacity: 1;
    filter: drop-shadow(0 0 4px rgba(92, 255, 92, 0.9));
}

.tree-node {
    position: relative;
    z-index: 2;
    color: #c9a86a;
    font-family: 'Courier New', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 2px;
    line-height: 1;
}

/* Antenna sits at the top center of the card, the visible chain root */
.tree-antenna {
    margin-bottom: 2px;
}

.antenna-glyph {
    font-family: 'Courier New', monospace;
    font-size: 1.3em;
    line-height: 1;
    color: #c9a86a;
    transition: color 0.08s ease, text-shadow 0.08s ease;
}

.tree-antenna.active .antenna-glyph,
.tree-antenna.on-path .antenna-glyph {
    color: #5cff5c;
    text-shadow: 0 0 8px #5cff5c, 0 0 18px rgba(92, 255, 92, 0.7);
}

.node-shape {
    display: inline-block;
    background: #1c1c1c;
    border: 1.5px solid #c9a86a;
    box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.6);
    transition: background 0.08s ease, box-shadow 0.08s ease, border-color 0.08s ease;
}

.node-shape.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.node-shape.dash {
    width: 22px;
    height: 11px;
    border-radius: 5px;
}

.node-letter {
    color: #e0d4ad;
    font-weight: bold;
    font-size: 0.72em;
    letter-spacing: 0;
}

/* Nodes that lie ON the in-progress path get a subtle highlight */
.tree-node.on-path .node-shape {
    border-color: #ffd98a;
    box-shadow: 0 0 4px rgba(255, 217, 138, 0.5), inset 0 0 3px rgba(0, 0, 0, 0.5);
}

.tree-node.on-path .node-letter {
    color: #ffffff;
}

/* The terminal node (matches the current buffer exactly) lights brightest */
.tree-node.lit .node-shape.dot {
    background: #5cff5c;
    border-color: #5cff5c;
    box-shadow:
        0 0 8px #5cff5c,
        0 0 16px rgba(92, 255, 92, 0.7),
        inset 0 0 4px rgba(0, 0, 0, 0.3);
}

.tree-node.lit .node-shape.dash {
    background: #ffaa3c;
    border-color: #ffaa3c;
    box-shadow:
        0 0 8px #ffaa3c,
        0 0 16px rgba(255, 170, 60, 0.7),
        inset 0 0 4px rgba(0, 0, 0, 0.3);
}

.tree-node.lit .node-letter {
    color: #ffffff;
    text-shadow: 0 0 4px rgba(255, 255, 255, 0.6);
}

/* Stream and decoded strips */
.stream-wrap,
.decoded-wrap {
    margin-top: 14px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(201, 168, 106, 0.4);
    border-radius: 4px;
    padding: 6px 10px;
    max-width: 560px;
    margin-left: auto;
    margin-right: auto;
}

.stream-label {
    font-size: 0.65em;
    color: #c9a86a;
    letter-spacing: 0.22em;
    text-align: left;
    margin-bottom: 4px;
}

.stream {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    height: 22px;
    scrollbar-width: thin;
    scrollbar-color: #c9a86a transparent;
}

.stream::-webkit-scrollbar {
    height: 4px;
}

.stream::-webkit-scrollbar-thumb {
    background: #c9a86a;
    border-radius: 2px;
}

.stream .dot {
    flex: 0 0 auto;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #5cff5c;
    box-shadow: 0 0 6px rgba(92, 255, 92, 0.6);
}

.stream .dash {
    flex: 0 0 auto;
    width: 22px;
    height: 12px;
    border-radius: 5px;
    background: #ffaa3c;
    box-shadow: 0 0 6px rgba(255, 170, 60, 0.6);
}

.stream .gap {
    flex: 0 0 auto;
    width: 10px;
    height: 12px;
    opacity: 0.3;
}

.decoded {
    font-family: 'Courier New', monospace;
    font-size: 1.4em;
    color: #e0d4ad;
    min-height: 28px;
    text-align: left;
    letter-spacing: 0.15em;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.2;
}

/* Key button */
.key-button {
    margin: 16px auto 0;
    display: block;
    width: 100%;
    max-width: 560px;
    padding: 20px;
    font-family: 'Courier New', monospace;
    font-size: 1.15em;
    font-weight: bold;
    letter-spacing: 0.2em;
    color: #c9a86a;
    background: linear-gradient(180deg, #2a2520 0%, #1a1612 100%);
    border: 2px solid #c9a86a;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    transition: transform 0.05s ease, background 80ms ease, color 80ms ease, box-shadow 80ms ease;
    box-shadow:
        0 3px 0 #6a5a30,
        0 4px 10px rgba(0, 0, 0, 0.45);
}

.key-button:hover {
    background: linear-gradient(180deg, #332e26 0%, #221d16 100%);
}

.key-button:active,
.key-button.pressed {
    background: linear-gradient(180deg, #5cff5c 0%, #3cc03c 100%);
    color: #082000;
    transform: translateY(3px);
    box-shadow:
        0 0 0 #6a5a30,
        0 2px 6px rgba(92, 255, 92, 0.5),
        inset 0 0 14px rgba(255, 255, 255, 0.25);
}

/* Held past the dot/dash threshold: cascade wins over the green rule above. */
.key-button.pressed.dash {
    background: linear-gradient(180deg, #ffaa3c 0%, #c07d2c 100%);
    color: #2a1500;
    box-shadow:
        0 0 0 #6a5a30,
        0 2px 6px rgba(255, 170, 60, 0.6),
        inset 0 0 14px rgba(255, 255, 255, 0.25);
}

/* Controls row */
.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 14px auto 0;
    align-items: center;
    justify-content: center;
    max-width: 560px;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: #c9a86a;
    font-size: 0.85em;
    align-items: center;
}

.control-item input[type='range'] {
    width: 180px;
    accent-color: #c9a86a;
}

.control-btn {
    font-family: 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.45);
    color: #c9a86a;
    border: 1px solid #c9a86a;
    padding: 8px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.15s ease, color 0.15s ease;
}

.control-btn:hover {
    background: rgba(201, 168, 106, 0.18);
}

.control-btn.muted {
    color: #888;
    border-color: #555;
}

.control-btn.streak-on {
    background: rgba(92, 255, 92, 0.18);
    color: #5cff5c;
    border-color: #5cff5c;
}

/* Streak banner */
.streak-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin: 0 auto 10px;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(201, 168, 106, 0.5);
    border-radius: 6px;
    max-width: 560px;
}

.streak-target {
    display: flex;
    align-items: center;
}

.streak-letter {
    font-size: 2em;
    font-weight: bold;
    color: #5cff5c;
    text-shadow: 0 0 8px rgba(92, 255, 92, 0.6);
}

.streak-label {
    font-size: 0.65em;
    letter-spacing: 0.22em;
    color: #c9a86a;
    margin-right: 6px;
}

.streak-stats {
    display: flex;
    gap: 18px;
    font-size: 1.1em;
    color: #e0d4ad;
}

/* Responsive */
@media (max-width: 540px) {
    body {
        padding: 10px;
    }

    .trainer-box {
        padding: 10px 6px 16px;
    }

    .card {
        padding: 14px 2px 18px;
    }

    .tree {
        row-gap: 20px;
    }

    .node-shape.dot {
        width: 9px;
        height: 9px;
    }

    .node-shape.dash {
        width: 14px;
        height: 8px;
    }

    .node-letter {
        font-size: 0.6em;
    }

    .antenna-glyph {
        font-size: 1.1em;
    }

    .tree-traces .trace {
        stroke-width: 1.3;
    }

    .tree-traces .trace.lit-trace {
        stroke-width: 1.8;
    }

    .decoded {
        font-size: 1.15em;
    }

    .control-item input[type='range'] {
        width: 140px;
    }
}
