/* R.U.R. CTF — Minimal dark theme with industrial / retro feel */

:root {
    --bg: #0a0a0f;
    --bg-card: #12121a;
    --bg-input: #1a1a25;
    --text: #c8c8d0;
    --text-dim: #6a6a78;
    --accent: #d4a843;
    --accent-dim: #8a6e2c;
    --danger: #c44;
    --border: #2a2a38;
    --msg-user-bg: #1e2a3a;
    --msg-bot-bg: #1a1a25;
    --radius: 6px;
}

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

body {
    font-family: 'IBM Plex Mono', monospace;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

h1 {
    font-family: 'Bebas Neue', sans-serif;
    font-weight: 400;
    letter-spacing: 0.05rem;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- Navbar --- */

.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

@media (max-width: 768px) {
    .navbar {
        padding: 0.75rem 1rem;
    }
    .nav-links {
        gap: 0.5rem;
    }
    .nav-links a:not(.lang-switch):not(.nav-home) {
        display: none;
    }
}

.nav-brand a {
    font-size: 1.25rem;
    font-weight: bold;
    color: var(--accent);
}

.nav-links {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.nav-links a {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.nav-links a:hover {
    color: var(--accent);
}

.lang-switch {
    padding: 0.2rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* --- Container --- */

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* No padding when wrapping the chat page — chat manages its own layout */
.container:has(.chat-container) {
    padding: 0;
    max-width: none;
}

@media (max-width: 768px) {
    .container {
        padding: 1.5rem 1rem;
    }
}

/* --- Page content --- */

.page-content h1 {
    color: var(--accent);
    margin-bottom: 1rem;
    font-size: 1.6rem;
}

@media (max-width: 768px) {
    .page-content h1 {
        font-size: 1.4rem;
    }
}

.page-content h2 {
    color: var(--accent-dim);
    margin: 1.5rem 0 0.75rem;
    font-size: 1.2rem;
}

@media (max-width: 768px) {
    .page-content h2 {
        font-size: 1.1rem;
    }
}

.page-content p {
    margin-bottom: 1rem;
}

.intro {
    font-size: 1.05rem;
}

.rules {
    list-style: none;
    padding: 0;
}

.rules li {
    padding: 0.4rem 0;
    padding-left: 1.5rem;
    position: relative;
}

.rules li::before {
    content: "▸";
    position: absolute;
    left: 0;
    color: var(--accent);
}

code {
    background: var(--bg-input);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.9em;
    color: var(--accent);
}

/* --- Cards --- */

.level-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

@media (max-width: 600px) {
    .level-cards {
        grid-template-columns: 1fr;
    }
}

.card {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: border-color 0.2s;
}

@media (max-width: 600px) {
    .card {
        padding: 1rem;
    }
    .card h3 {
        font-size: 0.95rem;
    }
    .card p {
        font-size: 0.8rem;
    }
}

.card:hover {
    border-color: var(--accent);
    text-decoration: none;
}

.card h3 {
    color: var(--accent);
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

.card p {
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* --- Buttons --- */

.btn {
    display: inline-block;
    padding: 0.6rem 1.5rem;
    background: var(--accent-dim);
    color: var(--text);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--accent);
    color: var(--bg);
    text-decoration: none;
}

.btn-secondary {
    background: transparent;
    border-color: var(--border);
}

.btn-secondary:hover {
    background: var(--bg-card);
    border-color: var(--accent);
    color: var(--text);
}

.cta {
    margin-top: 2rem;
    text-align: center;
}

/* --- Error page --- */

.error-page {
    text-align: center;
    padding-top: 4rem;
}

.error-page h1 {
    font-size: 4rem;
    margin-bottom: 0.5rem;
}

/* --- Chat --- */

.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 60px);
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1.5rem;
    position: relative;
}

@media (max-width: 768px) {
    .chat-container {
        padding: 0 1rem;
        height: calc(100dvh - 54px);
    }
}

/* Persona portrait — ghostly presence adhering to the sides of the screen */
.persona-backdrop {
    position: fixed;
    top: 60px;
    bottom: 0;
    width: 45vw; /* Spans from the edge to near the center */
    max-width: 800px;
    z-index: 0;
    pointer-events: none;
    overflow: hidden;
    display: flex;
    align-items: center;
}

.persona-backdrop.persona-right {
    right: 0; /* Anchor strictly to the right side of the screen */
    justify-content: flex-start; /* Image will start from the inner side */
}

.persona-backdrop.persona-left {
    left: 0; /* Anchor strictly to the left side of the screen */
    justify-content: flex-end; /* Image will start from the inner side */
}

.persona-backdrop img {
    height: 100%;
    width: 100%;
    object-fit: cover;
    opacity: 0;
    filter: brightness(0.6) contrast(1.15) grayscale(0.85);
    animation: fadeInGhost 3s ease-out forwards, breatheGhost 12s ease-in-out 3s infinite alternate;
}

@keyframes fadeInGhost {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 0.7; transform: translateY(0); }
}

@keyframes breatheGhost {
    from { opacity: 0.7; transform: translateY(0) scale(1); filter: brightness(0.6) contrast(1.15) grayscale(0.85); }
    to { opacity: 0.85; transform: translateY(-15px) scale(1.03); filter: brightness(0.65) contrast(1.2) grayscale(0.8); }
}

#ash-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1; /* Above image */
    mix-blend-mode: screen;
}

/* 
   Gradient: 
   Transparent/invisible at the inner edge (towards center of screen/chat),
   Opaque at the outer edge (side of screen).
*/
.persona-backdrop.persona-right img {
    object-position: left center;
    mask-image: linear-gradient(to right, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%);
    -webkit-mask-image: linear-gradient(to right, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%);
}

.persona-backdrop.persona-left img {
    object-position: right center;
    mask-image: linear-gradient(to left, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%);
    -webkit-mask-image: linear-gradient(to left, rgba(0,0,0,0) 0%, rgba(0,0,0,1) 100%);
}

/* Hide if the screen is too narrow to have meaningful gutters - but show as background on mobile */
@media (max-width: 1100px) {
    .persona-backdrop {
        width: 100vw;
        left: 0 !important;
        right: 0 !important;
    }
    .persona-backdrop img {
        opacity: 0.15 !important; /* Extremely ghostly on mobile background */
        filter: brightness(0.5) contrast(1) grayscale(1);
        mask-image: radial-gradient(circle at center, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 80%);
        -webkit-mask-image: radial-gradient(circle at center, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 80%);
        object-position: center 20%;
    }
}

/* Ensure chat content stays above with a glow for legibility */
.chat-header,
.chat-messages,
.chat-input-area {
    position: relative;
    z-index: 2;
    text-shadow: 0 0 15px rgba(0,0,0,1);
}

.chat-header {
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

@media (max-width: 768px) {
    .chat-header {
        padding: 0.75rem 0;
    }
    .chat-header .description {
        display: none;
    }
}

.chat-header h1 {
    color: var(--accent);
    font-size: 1.3rem;
    margin: 0.5rem 0 0.25rem;
}

@media (max-width: 768px) {
    .chat-header h1 {
        font-size: 1.1rem;
    }
}

.chat-header .subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.chat-header .description {
    font-size: 0.85rem;
    color: var(--text-dim);
}

.back-link {
    font-size: 0.85rem;
    color: var(--text-dim);
}

/* Messages area */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.5;
}

@media (max-width: 768px) {
    .message {
        max-width: 90%;
        padding: 0.6rem 0.8rem;
        font-size: 0.85rem;
    }
}

.message.user {
    align-self: flex-end;
    background: var(--msg-user-bg);
    border: 1px solid #2a3a5a;
}

.message.assistant {
    align-self: flex-start;
    background: var(--msg-bot-bg);
    border: 1px solid var(--border);
}

.message-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Stage directions / narration — *asterisk text* and (parenthetical) */
.message-content .narration {
    color: var(--accent-dim);
    font-style: italic;
    font-size: 0.85em;
    margin: 0.4em 0;
    padding-left: 0.5em;
    border-left: 2px solid var(--border);
}

/* Flag found highlight */
.flag-found {
    display: inline-block;
    color: #1a1a1a;
    background: #3ddc6e;
    border-radius: 3px;
    padding: 0.05em 0.35em;
    font-weight: bold;
    box-shadow: 0 0 0 rgba(61, 220, 110, 0);
    animation: flagBurst 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97) forwards,
               flagGlow 1.8s ease-in-out 0.6s infinite alternate;
}

@keyframes flagBurst {
    0%   { transform: scale(1);    box-shadow: 0 0 0px rgba(61,220,110,0); }
    30%  { transform: scale(1.35); box-shadow: 0 0 24px rgba(61,220,110,0.9); }
    55%  { transform: scale(0.95); box-shadow: 0 0 10px rgba(61,220,110,0.5); }
    75%  { transform: scale(1.08); }
    100% { transform: scale(1);    box-shadow: 0 0 12px rgba(61,220,110,0.4); }
}

@keyframes flagGlow {
    from { box-shadow: 0 0 8px  rgba(61,220,110,0.3); }
    to   { box-shadow: 0 0 20px rgba(61,220,110,0.7); }
}

.message.thinking .message-content {
    color: var(--text-dim);
    font-style: italic;
}

/* Input area */

.chat-input-area {
    padding: 1rem 0;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

@media (max-width: 768px) {
    .chat-input-area {
        flex-direction: column;
        align-items: stretch;
        padding: 0.75rem 0;
        gap: 0.5rem;
    }
}

#chat-input {
    flex: 1;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.6rem 0.75rem;
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    outline: none;
    min-height: 44px;
}

@media (max-width: 768px) {
    #chat-input {
        padding: 0.6rem;
        font-size: 16px; /* Prevents iOS zoom */
        width: 100%;
    }
}

#chat-input:focus {
    border-color: var(--accent-dim);
}

.chat-buttons {
    display: flex;
    gap: 0.5rem;
}

@media (max-width: 768px) {
    .chat-buttons {
        width: 100%;
    }
    .chat-buttons button {
        flex: 1;
    }
}

/* --- Story --- */

.story p {
    margin-bottom: 1.25rem;
}

/* --- Scrollbar --- */

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* --- Full-page Backdrop (Home & Story) --- */

.page-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none;
    overflow: hidden;
    background: var(--bg);
}

.page-backdrop img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    filter: brightness(0.5) contrast(1.1) grayscale(0.7) sepia(0.1);
    mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 100%);
    -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1) 0%, rgba(0,0,0,0) 100%);
    animation: fadeInPage 4s ease-out forwards, breathePage 15s ease-in-out 4s infinite alternate;
}

@keyframes fadeInPage {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 0.25; transform: translateY(0); }
}

@keyframes breathePage {
    from { opacity: 0.25; transform: scale(1); }
    to { opacity: 0.35; transform: scale(1.05); }
}

/* Ensure content stays above the backdrop */
.page-content {
    position: relative;
    z-index: 1;
    text-shadow: 0 0 10px rgba(0,0,0,1);
}
