/* ============================================
   NO RULEZ — Terminal/Hacker Aesthetic
   Dracula-inspired palette + graffiti branding
   ============================================ */

/* --- Reset & Base --- */

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

body {
    background: #0a0a0a;
    color: #e0e0e0;
    font-family: 'Courier New', Courier, monospace;
    padding: 20px;
    touch-action: manipulation;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Single centered column — everything lives inside this */
#game-container {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
}

/* --- Logo --- */

#logo {
    text-align: center;
    margin-bottom: 30px;
    user-select: none;
    -webkit-user-select: none;
}

.in-game #logo { margin-bottom: 6px; }

.logo-img {
    width: clamp(200px, 50vw, 500px);
    display: block;
    margin: 0 auto;
    filter: drop-shadow(0 0 10px rgba(255, 85, 85, 0.4));
    transition: width 0.3s ease;
}

.in-game .logo-img { width: clamp(120px, 30vw, 220px); }
.in-game .subtitle { display: none; }

.subtitle {
    color: #f1fa8c;
    text-align: center;
    letter-spacing: 0.3em;
    font-size: 0.8rem;
    margin-top: 8px;
}

/* --- Setup / Menu --- */

.explainer {
    color: #bd93f9;
    text-align: center;
    margin: 20px auto;
    max-width: 420px;
    font-style: italic;
    line-height: 1.5;
}

#mode-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.mode-btn {
    background: #2a2a4e;
    border: 2px solid #50fa7b;
    color: #50fa7b;
    padding: 14px 28px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 4px;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.mode-btn:hover { background: #50fa7b; color: #0a0a0a; border-color: #f1fa8c; }
.mode-btn:active { transform: scale(0.97); }
.mode-btn:disabled { opacity: 0.4; cursor: not-allowed; }

input[type="text"],
textarea {
    background: #111;
    border: 1px solid #444;
    color: #e0e0e0;
    padding: 10px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 16px;
    width: 100%;
    border-radius: 4px;
}

input[type="text"]:focus,
textarea:focus { border-color: #50fa7b; outline: none; }

#name-inputs {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 20px;
}

#name-inputs input[type="text"] {
    width: 100%;
    max-width: 300px;
    text-align: center;
    padding: 14px 28px;
}

#name-inputs .mode-btn {
    width: 100%;
    max-width: 300px;
}

/* --- Game Area ---
   KEY PRINCIPLE: Everything is left-aligned and fills the
   full container width. No per-section max-widths that fight
   each other. Centered items use text-align on themselves.
*/

#game-area {
    width: 100%;
    padding: 0 2px;
}

/* --- Turn Badge --- */

#turn-badge {
    color: #f1fa8c;
    font-size: 0.75rem;
    background: #1a1a2e;
    display: block;
    padding: 2px 12px;
    border-radius: 4px;
    margin: 0 auto 4px;
    width: fit-content;
    text-align: center;
}

/* --- Separator --- */

.separator {
    color: #f1fa8c;
    text-align: center;
    margin: 8px 0;
    overflow: hidden;
    font-size: 0.8rem;
    opacity: 0.6;
}

/* --- Narrative --- */

#narrative-box {
    color: #e0e0e0;
    font-size: 1.05rem;
    line-height: 1.5;
    margin: 10px 0;
    min-height: 30px;
    padding: 8px 0 8px 10px;
    border-left: 3px solid #bd93f9;
    font-weight: bold;
    cursor: pointer;
}

/* --- ASCII / Image --- */

#scene-ascii {
    color: #8be9fd;
    font-size: 0.7rem;
    line-height: 1.2;
    overflow-x: auto;
    margin: 8px 0;
    text-align: center;
    white-space: pre;
    max-height: 210px;
    overflow-y: auto;
}

#scene-image-wrapper {
    text-align: center;
    margin: 8px 0;
}

#scene-image {
    max-width: 100%;
    max-height: 280px;
    border-radius: 8px;
    border: 2px solid #333;
    object-fit: contain;
}

#image-loading {
    color: #666;
    font-style: italic;
    padding: 20px;
    text-align: center;
}

/* --- Actions Display --- */

#actions-display {
    margin: 8px 0;
    font-size: 0.85rem;
}

.action-line { margin: 4px 0; padding: 4px 0; }
.action-line .player-label { font-weight: bold; }
.action-line.p1 .player-label { color: #ff5555; }
.action-line.p2 .player-label { color: #6272a4; }

/* --- Battle Log --- */

#battle-log-toggle { text-align: center; margin: 5px 0; }

#log-toggle-btn {
    background: none;
    border: 1px solid #6272a4;
    color: #6272a4;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.75rem;
    padding: 4px 12px;
    cursor: pointer;
    border-radius: 4px;
}

#log-toggle-btn:hover { color: #8be9fd; border-color: #8be9fd; }

#battle-log {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #333;
    border-radius: 4px;
    background: #111;
    margin: 8px 0;
    padding: 8px;
}

.log-entry {
    padding: 6px 0;
    border-bottom: 1px solid #222;
    font-size: 0.8rem;
    line-height: 1.4;
}
.log-entry:last-child { border-bottom: none; }
.log-turn-num { color: #f1fa8c; font-weight: bold; font-size: 0.7rem; }
.log-action { color: #8be9fd; font-style: italic; }
.log-damage { color: #ff5555; font-weight: bold; }
.log-narrative { color: #aaa; margin-top: 2px; }

/* --- Creativity Badge --- */

#creativity-badge {
    font-size: 1.1rem;
    margin: 4px 0;
    padding: 4px;
    border-radius: 20px;
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.3s;
    text-align: center;
}

#creativity-badge.show { opacity: 1; }
#creativity-badge.creative { color: #ff9900; text-shadow: 0 0 10px rgba(255,153,0,0.5); }
#creativity-badge.exceptional { color: #f1fa8c; text-shadow: 0 0 15px rgba(241,250,140,0.5); }
#creativity-badge.decent { color: #aaa; }

/* --- HP Section ---
   Grid layout: fixed name | flex bar | fixed value.
   Grid ensures both rows share identical column widths.
*/

#hp-section { margin: 8px 0; }

.hp-row {
    display: grid;
    grid-template-columns: 70px 1fr 30px;
    align-items: center;
    margin: 5px 0;
    gap: 8px;
    position: relative;
}

.hp-name {
    font-size: 0.85rem;
    font-weight: bold;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#hp-row-p1 .hp-name { color: #ff5555; }
#hp-row-p2 .hp-name { color: #6272a4; }

.hp-bar-bg {
    height: 18px;
    background: #1a1a2e;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid #333;
}

.hp-bar-fill {
    height: 100%;
    transition: width 0.6s ease-in-out;
    border-radius: 3px;
}

#p1-hp-fill { background: #ff5555; }
#p2-hp-fill { background: #6272a4; }
.hp-bar-fill.low { background: #8b2020; }
#p2-hp-fill.low { background: #3a4560; }

.hp-value {
    text-align: right;
    font-weight: bold;
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
}

/* --- HP Popups --- */

.hp-popup {
    position: absolute;
    right: -8px;
    top: -6px;
    font-weight: 900;
    font-size: 1.4rem;
    opacity: 0;
    pointer-events: none;
}

.hp-popup.damage { color: #ff5555; }
.hp-popup.heal { color: #50fa7b; }

@keyframes float-up {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-42px); }
}

.hp-popup.animate { animation: float-up 1.8s ease-out forwards; }

/* --- Status --- */

#status-msg {
    color: #666;
    font-size: 0.75rem;
    min-height: 0;
    margin: 2px 0;
    text-align: center;
}

/* --- Input Area ---
   Full width. Textarea stretches across. Counter + GO sit below.
   GO is right-aligned and compact. Counter stays fixed width.
*/

#input-area { margin-top: 8px; }

#turn-indicator {
    color: #f1fa8c;
    text-align: center;
    margin-bottom: 6px;
    font-weight: bold;
    font-size: 0.9rem;
}

#action-input {
    resize: none;
    min-height: 42px;
    max-height: 120px;
    font-size: 16px;
    width: 100%;
}

#input-row-bottom {
    margin-top: 6px;
}

#char-counter {
    color: #555;
    font-size: 0.7rem;
    text-align: right;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

#char-counter.warn { color: #ff5555; }

#go-btn {
    width: 100%;
    background: #50fa7b;
    color: #0a0a0a;
    border: none;
    padding: 12px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

#go-btn:hover { background: #3ad968; }
#go-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* --- Inline Loading --- */

#loading-inline { text-align: center; padding: 20px 0; }

#loading-inline .loading-emoji {
    font-size: 2.4rem;
    margin-bottom: 12px;
    animation: bounce 1.2s ease-in-out infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-18px); }
}

#loading-text {
    color: #f1fa8c;
    font-weight: bold;
    font-size: 0.95rem;
    letter-spacing: 0.15em;
}

#loading-subtext {
    color: #666;
    font-size: 0.8rem;
    margin-top: 4px;
    min-height: 1.2em;
}

/* --- Continue Button --- */

#continue-area { text-align: center; margin-top: 15px; }

#continue-btn { animation: pulse-glow 2s ease-in-out infinite; }

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 5px rgba(80, 250, 123, 0.2); }
    50% { box-shadow: 0 0 20px rgba(80, 250, 123, 0.5); }
}

/* --- Waiting Overlay --- */

#waiting-overlay {
    text-align: center;
    padding: 30px;
    color: #666;
    animation: pulse-bg 2s infinite;
}

.waiting-text { font-size: 1.1rem; }

.dots span { animation: pulse-dots 1.5s infinite; opacity: 0.2; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse-dots {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

@keyframes pulse-bg {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* --- PVP Handoff Screen --- */

#handoff-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: #0a0a0a;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

#handoff-inner { padding: 40px; }

#handoff-text {
    color: #f1fa8c;
    font-size: 2rem;
    font-weight: bold;
    letter-spacing: 0.3em;
    margin-bottom: 20px;
    animation: pulse-glow 2s ease-in-out infinite;
}

#handoff-player {
    color: #50fa7b;
    font-size: 1.4rem;
    margin-bottom: 30px;
}

/* --- Mute Toggle --- */

#mute-toggle {
    position: fixed;
    top: 10px;
    left: 10px;
    background: #1a1a2e;
    border: 1px solid #444;
    color: #e0e0e0;
    font-size: 1.2rem;
    padding: 4px 8px;
    cursor: pointer;
    border-radius: 4px;
    z-index: 50;
    font-family: 'Courier New', Courier, monospace;
}

#mute-toggle:hover { border-color: #50fa7b; }

/* --- Game Over --- */

#game-over { text-align: center; padding: 40px 20px; }

#game-over-inner {
    border: 2px solid #bd93f9;
    border-radius: 8px;
    padding: 30px 20px;
    background: rgba(189, 147, 249, 0.05);
    animation: game-over-entrance 0.8s ease-out;
}

@keyframes game-over-entrance {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

#ko-ascii {
    color: #ff5555;
    font-size: 0.8rem;
    line-height: 1.1;
    text-align: center;
    margin-bottom: 15px;
    animation: ko-flash 0.5s ease-out 3;
}

@keyframes ko-flash {
    0% { opacity: 1; color: #ff5555; }
    50% { opacity: 0.3; color: #f1fa8c; }
    100% { opacity: 1; color: #ff5555; }
}

#game-over h2 { color: #f1fa8c; font-size: 1rem; letter-spacing: 0.3em; margin-bottom: 10px; }

#winner-text {
    color: #50fa7b;
    font-size: 2rem;
    font-weight: bold;
    text-shadow: 0 0 30px rgba(80, 250, 123, 0.4);
    margin-bottom: 15px;
}

#final-image {
    max-width: 100%;
    max-height: 250px;
    border-radius: 8px;
    border: 2px solid #ff5555;
    margin: 15px auto;
    display: block;
    box-shadow: 0 0 30px rgba(255, 85, 85, 0.3);
}

#final-narrative { color: #e0e0e0; margin-bottom: 25px; font-style: italic; line-height: 1.5; }
#final-stats { color: #6272a4; font-size: 0.85rem; margin-top: 10px; }

/* --- Code Badge (online) --- */

#code-badge {
    position: fixed;
    top: 10px; right: 10px;
    background: #1a1a2e;
    border: 1px solid #f1fa8c;
    color: #f1fa8c;
    padding: 4px 10px;
    font-size: 0.75rem;
    border-radius: 4px;
    z-index: 50;
}

/* --- Retry --- */

#retry-area { text-align: center; margin-top: 20px; }
#error-msg { color: #ff5555; margin-bottom: 10px; }

/* --- Online Lobby --- */

#online-lobby { text-align: center; }

.code-display {
    font-size: clamp(2rem, 8vw, 4rem);
    color: #50fa7b;
    letter-spacing: 0.5em;
    text-shadow: 0 0 20px rgba(80, 250, 123, 0.3);
    margin: 20px 0;
    font-weight: bold;
}

.share-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    margin: 15px 0;
}

.code-input {
    text-align: center;
    font-size: 1.5rem !important;
    letter-spacing: 0.3em;
    max-width: 250px;
    margin: 10px auto;
}

/* --- Screen Shake --- */

@keyframes shake {
    0%, 100% { transform: translate(0); }
    10% { transform: translate(-4px, 2px); }
    30% { transform: translate(4px, -3px); }
    50% { transform: translate(-3px, -2px); }
    70% { transform: translate(3px, 3px); }
    90% { transform: translate(-2px, -1px); }
}

.shake { animation: shake 0.3s ease-in-out; }

/* --- Mobile --- */

@media (max-width: 600px) {
    body { padding: 12px 16px; }

    .logo-img { width: 70vw; }
    .in-game .logo-img { width: 35vw; max-width: 180px; }
    .in-game #logo { margin-bottom: 4px; }

    .hp-row { grid-template-columns: 65px 1fr 28px; gap: 6px; }
    .hp-name { font-size: 0.75rem; }
    .hp-value { font-size: 0.85rem; }

    #mode-buttons { flex-direction: column; align-items: center; }
    .mode-btn { width: 100%; max-width: 300px; }

    #narrative-box { font-size: 0.9rem; padding: 6px 8px; margin: 6px 0; }
    #scene-ascii { font-size: 0.55rem; margin: 6px 0; }
    #scene-image { max-height: 220px; }

    .separator { margin: 4px 0; }
    #hp-section { margin: 4px 0; }
    #creativity-badge { margin: 2px 0; }
    #loading-inline { padding: 15px 0; }
}
