@import url('https://fonts.googleapis.com/css2?family=Chakra+Petch:wght@400;600;700&display=swap');

:root {
    --green: #00FF59;
    --charcoal: #121212;
    --black: #000000;
    --white: #FFFFFF;

    --bg-dark: var(--black);
    --panel-bg: rgba(18, 18, 18, 0.96);
    --primary: var(--green);
    --primary-hover: var(--white);
    --success: var(--green);
    --danger: var(--white);
    --warning: var(--green);
    --text-main: var(--white);
    --text-muted: rgba(255, 255, 255, 0.72);
    --border-color: var(--green);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Chakra Petch', sans-serif;
    user-select: none;
}

body {
    background-color: var(--black);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    color: var(--text-main);
}

#game-container {
    position: relative;
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-direction: column;
    background-color: var(--charcoal);
    box-shadow: 0 0 32px rgba(0, 255, 89, 0.24);
    border: 2px solid var(--green);
    border-radius: 8px;
    overflow: hidden;
}

canvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 600px;
    aspect-ratio: 4/3;
    background: var(--charcoal);
}

.hidden { display: none !important; }
.active { display: flex !important; }
.highlight { color: var(--green); }
.highlight-alt { color: var(--white); text-shadow: 0 0 12px rgba(0, 255, 89, 0.55); }
.danger { color: var(--white); text-shadow: 0 0 10px rgba(0, 255, 89, 0.7); }

/* Modals */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--panel-bg);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(8px);
    padding: 20px;
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    color: var(--green);
    letter-spacing: 2px;
    margin-bottom: 5px;
    text-shadow: 0 0 14px rgba(0, 255, 89, 0.55);
}

h2 {
    font-size: 2rem;
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-bottom: 25px;
}

.input-group input {
    padding: 12px 20px;
    font-size: 1.2rem;
    background: var(--black);
    border: 2px solid var(--green);
    color: var(--white);
    border-radius: 6px;
    outline: none;
    transition: 0.3s;
    text-align: center;
    width: 280px;
}

.input-group input::placeholder { color: rgba(255, 255, 255, 0.58); }

.input-group input:focus {
    border-color: var(--white);
    box-shadow: 0 0 18px rgba(0, 255, 89, 0.35);
}

.instructions-box {
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--green);
    padding: 20px;
    border-radius: 8px;
    margin: 20px 0;
    text-align: left;
    max-width: 500px;
    box-shadow: inset 0 0 24px rgba(0, 255, 89, 0.08);
}

.instructions-box h3 {
    margin-bottom: 10px;
    color: var(--green);
}

.instructions-box ul { list-style: none; }

.instructions-box li {
    margin-bottom: 8px;
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--white);
}

.instructions-box b { color: var(--green); }

button {
    padding: 12px 25px;
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 6px;
    text-transform: uppercase;
    transition: all 0.2s;
    border: none;
    pointer-events: auto;
}

.btn-primary {
    background: var(--green);
    color: var(--black);
    box-shadow: 0 0 18px rgba(0, 255, 89, 0.4);
}

.btn-primary:hover {
    background: var(--white);
    color: var(--black);
    transform: translateY(-2px);
}

.btn-secondary {
    background: var(--black);
    color: var(--white);
    border: 2px solid var(--green);
}

.btn-secondary:hover {
    background: var(--charcoal);
    border-color: var(--white);
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.8rem;
    background: var(--black);
    color: var(--white);
    border: 1px solid var(--green);
    min-width: 132px;
}

.system-buttons {
    flex-direction: column;
    gap: 10px;
}

.action-wrapper {
    min-width: 300px;
}

.btn-small:hover {
    background: var(--green);
    color: var(--black);
}

.btn-group {
    display: flex;
    gap: 15px;
    margin-top: 15px;
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 50;
    pointer-events: none;
}

.hud-top {
    display: flex;
    justify-content: space-between;
    padding: 15px;
    background: linear-gradient(rgba(0, 0, 0, 0.94), rgba(18, 18, 18, 0.3), rgba(18, 18, 18, 0));
}

.panel-info,
.panel-error {
    font-size: 1.1rem;
    font-weight: 600;
    text-shadow: 1px 1px 2px var(--black);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.panel-error { align-items: flex-end; }

/* Timer Display */
.timer-display {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--green);
    text-shadow: 0 0 12px rgba(0, 255, 89, 0.55);
    margin-bottom: 5px;
}

#hud-time { transition: color 0.3s; }

.panel-instruction {
    background: rgba(0, 255, 89, 0.08);
    border: 1px solid var(--green);
    padding: 10px 20px;
    border-radius: 6px;
    text-align: center;
    box-shadow: 0 0 18px rgba(0, 255, 89, 0.24);
    min-width: 270px;
}

.inst-label {
    font-size: 0.7rem;
    color: var(--green);
    letter-spacing: 1px;
}

#hud-instruction {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--white);
    margin-top: 3px;
    white-space: pre-line;
    line-height: 1.35;
}

#feedback-text {
    position: absolute;
    top: 100px;
    width: 100%;
    text-align: center;
    font-size: 1.5rem;
    font-weight: bold;
    text-transform: uppercase;
    text-shadow: 2px 2px 4px var(--black);
    opacity: 0;
    transition: opacity 0.3s;
    white-space: pre-line;
}

.feedback-anim.success,
.feedback-anim.highlight,
.feedback-anim.warning {
    color: var(--green);
}

.feedback-anim.danger {
    color: var(--white);
}

/* EXTERNAL CONTROLS */
#external-controls {
    display: flex;
    justify-content: space-around;
    align-items: center;
    gap: 18px;
    background: var(--black);
    padding: 18px 20px;
    border-top: 2px solid var(--green);
    z-index: 40;
}

.control-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.joystick-zone {
    width: 80px;
    height: 80px;
    background: rgba(0, 255, 89, 0.06);
    border: 2px solid var(--green);
    border-radius: 50%;
    position: relative;
    touch-action: none;
}

.joystick-knob {
    width: 36px;
    height: 36px;
    background: var(--green);
    border-radius: 50%;
    position: absolute;
    top: 20px;
    left: 20px;
    box-shadow: 0 0 18px rgba(0, 255, 89, 0.55);
    pointer-events: none;
    transition: transform 0.05s linear;
}

.joystick-hint {
    font-size: 0.8rem;
    color: var(--white);
}

.btn-big {
    padding: 15px 40px;
    font-size: 1.2rem;
    border-radius: 8px;
    background: rgba(0, 255, 89, 0.08);
    border: 2px solid var(--green);
    color: var(--green);
    box-shadow: 0 0 14px rgba(0, 255, 89, 0.25);
    letter-spacing: 1px;
}

.btn-big:active {
    transform: scale(0.95);
    background: var(--green);
    color: var(--black);
}

.btn-big span {
    font-size: 0.8rem;
    opacity: 0.85;
    font-weight: normal;
}

/* Stats Card */
.stats-card {
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid var(--green);
    padding: 20px;
    border-radius: 8px;
    width: 100%;
    max-width: 360px;
    margin-bottom: 20px;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(0, 255, 89, 0.22);
    padding-bottom: 5px;
}

@media (max-width: 600px) {
    h1 { font-size: 1.8rem; }
    .hud-top { padding: 10px; gap: 8px; }
    .panel-instruction { min-width: 180px; padding: 8px 10px; }
    #hud-instruction { font-size: 0.95rem; }
    .panel-info, .panel-error { font-size: 0.85rem; }
    .timer-display { font-size: 1.1rem; }
    .btn-big { padding: 12px 22px; font-size: 0.95rem; }
}


/* Keep all gameplay buttons outside the canvas frame */
.system-buttons {
    flex-direction: column;
    gap: 10px;
}

.system-buttons .btn-small {
    min-width: 140px;
}

.action-wrapper {
    min-width: 300px;
}

@media (max-width: 600px) {
    #external-controls { gap: 10px; padding: 14px 10px; }
    .action-wrapper { min-width: 0; }
    .system-buttons .btn-small { min-width: 112px; font-size: 0.68rem; padding: 8px 10px; }
}

/* Compact start modal so the full SOP fits inside the 600px gameplay frame */
#start-screen {
    justify-content: flex-start;
    padding-top: 14px;
    overflow-y: auto;
}

#start-screen h1 {
    font-size: 2rem;
    line-height: 1.05;
}

#start-screen .subtitle {
    margin-bottom: 14px;
}

#start-screen .input-group input {
    padding: 10px 18px;
}

#start-screen .instructions-box {
    margin: 14px 0;
    padding: 16px 20px;
}

#start-screen .instructions-box li {
    margin-bottom: 6px;
    font-size: 0.88rem;
    line-height: 1.32;
}
