/* Color Palette - Fantasy Tech Theme */
:root {
    /* Backgrounds */
    --color-bg-dark: #303635;
    --color-bg-light: #4B5852;
    
    /* Accents */
    --color-highlight: #5C998C;
    --color-accent: #CCA78F;
    
    /* Text */
    --color-text-normal: #E0E0E0;
    --color-text-title: #FFFFFF;
    --color-text-description: #C0C0C0;
    
    /* UI Specific */
    --color-border: rgba(92, 153, 140, 0.4);
    --color-border-active: #5C998C;
    --color-overlay: rgba(48, 54, 53, 0.95);
    --color-overlay-light: rgba(48, 54, 53, 0.5);
    
    /* Status Colors */
    --color-health: #5C998C;
    --color-health-low: #CCA78F;
    --color-health-critical: #d9534f;
    --color-mana: #5C998C;
    --color-exp: #CCA78F;
    
    /* UI Metrics */
    --border-radius-sharp: 2px;
    --border-radius-medium: 4px;
    
    /* Cursor Images */
    /* (scripts/sprite-gen/cursors.py emblem_cel_notch; earlier: cel_*.png, dart_*.png, and the
       first ones cursor.png, cursorPointer.png) */
    --cursor-default: url('../img/cursor/cel_notch_cursor.png') 1 1, auto;
    --cursor-pointer: url('../img/cursor/cel_notch_pointer.png') 1 1, pointer;
    --cursor-text: url('../img/cursor/text_cursor.png') 16 16, text;
}

/* The game's own cursors on every page element: the text one in fields typed into */
html, body {
    cursor: var(--cursor-default);
}

input:not([type="color"]):not([type="checkbox"]):not([type="range"]), textarea {
    cursor: var(--cursor-text);
}

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

body, html {
    width: 100%;
    height: 100%;
    font-family: var(--font-primary, 'Arial', sans-serif);
    font-weight: 450;
    background-color: var(--color-bg-dark);
    color: var(--color-text-normal);
    overflow: hidden;
}

.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1;
}

.hidden {
    display: none !important;
}

#login-screen {
    z-index: 100;
}

/* The game's own cursors on the landing screen too (a pointer on what's clicked; the moon or sun
   on its canvas, landing.js), the text one in its fields */
#login-screen, #login-screen * {
    cursor: var(--cursor-default);
}

#login-screen button, #login-screen button * {
    cursor: var(--cursor-pointer);
}

#login-screen input {
    cursor: var(--cursor-text);
}

/* Landing (the login screen): the lobby's night scene behind the title and the auth panel */
.landing {
    flex-direction: column;
    justify-content: flex-start;   /* (centred by .landing-content's margin, scrolling from the top when too short) */
    overflow-y: auto;
    background-color: #262c2b;
}

#landing-bg {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    animation: landing-fade 1.6s ease-out both;
}

.landing-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 440px;
    margin: auto;
    padding: 4vh 16px;
}

.landing-hero {
    text-align: center;
    margin-bottom: 2.25rem;
}

.landing-title {
    font-family: 'Expletus Sans', var(--font-primary, sans-serif);
    font-weight: 600;
    font-size: clamp(3.2rem, 9vw, 5.5rem);
    line-height: 1;
    letter-spacing: 0.06em;
    color: #f2eee4;
    text-shadow:
        0 0 28px rgba(230, 222, 196, 0.25),
        0 4px 18px rgba(0, 0, 0, 0.55);
    animation: landing-title 1.6s cubic-bezier(0.2, 0.7, 0.2, 1) 0.15s both;
}

/* The emblem under the title (img/logo/emblem.png, in the accent colour), a thin line running
   out from either side of it at the height of its wings */
.landing-rule {
    --emblem-w: 21.6px;
    --emblem-h: 19.2px;
    position: relative;
    width: min(420px, 86vw);
    height: var(--emblem-h);
    margin: 1rem auto 0;
    animation: landing-fade 1s ease-out 0.7s both;
}

.landing-rule::before,
.landing-rule::after {
    content: '';
    position: absolute;
    top: 46.7%;
    width: calc(50% - var(--emblem-w) / 2 - 6px);
    height: 1px;
    animation: landing-line 1.2s cubic-bezier(0.2, 0.7, 0.2, 1) 0.7s both;
}

.landing-rule::before {
    left: 0;
    background: linear-gradient(90deg, transparent, rgba(204, 167, 143, 0.75));
    transform-origin: right;
}

.landing-rule::after {
    right: 0;
    background: linear-gradient(270deg, transparent, rgba(204, 167, 143, 0.75));
    transform-origin: left;
}

.landing-rule span {
    position: absolute;
    left: 50%;
    top: 0;
    width: var(--emblem-w);
    height: var(--emblem-h);
    margin-left: calc(var(--emblem-w) / -2);
    filter: drop-shadow(0 0 10px rgba(204, 167, 143, 0.35));
    animation: landing-emblem 1.1s cubic-bezier(0.2, 0.7, 0.2, 1) 0.6s both;
}

.landing-rule span::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--color-accent);
    -webkit-mask: url('../img/logo/emblem.png') center / contain no-repeat;
    mask: url('../img/logo/emblem.png') center / contain no-repeat;
}

.login-container {
    --pad: 2rem;
    width: 100%;
    padding: 0 var(--pad) 1.75rem;
    background-color: rgba(38, 44, 43, 0.82);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-medium);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    animation: landing-panel 0.9s cubic-bezier(0.2, 0.7, 0.2, 1) 0.9s both;
}

.auth-tabs {
    display: flex;
    margin: 0 calc(-1 * var(--pad)) 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.auth-tab {
    flex: 1;
    min-width: 0;
    padding: 1rem 0.5rem 0.9rem;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: var(--color-text-description);
    font-family: var(--font-primary, sans-serif);
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: var(--cursor-pointer);
    transition: color 0.2s, border-color 0.2s, background-color 0.2s;
}

.auth-tab:hover {
    color: var(--color-text-title);
    background-color: rgba(92, 153, 140, 0.08);
}

.auth-tab.active {
    color: var(--color-text-title);
    border-bottom-color: var(--color-highlight);
}

/* Forgot and reset password: no tabs, a heading instead */
.login-container.no-tabs {
    padding-top: 1.75rem;
}

.login-container.no-tabs .auth-tabs {
    display: none;
}

.auth-heading {
    margin-bottom: 0.6rem;
    color: var(--color-text-title);
    font-size: 1.15rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.auth-note {
    margin-bottom: 1.2rem;
    color: var(--color-text-description);
    font-size: 0.9rem;
    line-height: 1.45;
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--color-accent);
    font-family: var(--font-primary, sans-serif);
    font-size: 0.85rem;
    cursor: var(--cursor-pointer);
}

.link-btn:hover {
    color: #e2c3ae;
    text-decoration: underline;
}

.link-back {
    display: block;
    margin: 0.75rem auto 0;
}

.auth-form .btn {
    margin-top: 0.75rem;
}

/* The version at the bottom left, who made it at the bottom right */
.landing-footer {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 12px;
    z-index: 1;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    color: rgba(224, 224, 224, 0.4);
    font-size: 0.75rem;
    letter-spacing: 1px;
}

@keyframes landing-fade {
    from { opacity: 0; }
}

@keyframes landing-title {
    from { opacity: 0; transform: translateY(18px); }
}

@keyframes landing-line {
    from { opacity: 0; transform: scaleX(0); }
}

@keyframes landing-emblem {
    from { opacity: 0; transform: translateY(6px) scale(0.85); }
}

@keyframes landing-panel {
    from { opacity: 0; transform: translateY(16px); }
}

/* The intro waits, held at its start, till the page has loaded and settled (landing.js: intro) */
#landing-bg, .landing-title, .landing-rule, .landing-rule span, .login-container {
    will-change: transform, opacity;
}

.landing:not(.intro) :is(#landing-bg, .landing-title, .landing-rule, .landing-rule span, .login-container),
.landing:not(.intro) .landing-rule::before,
.landing:not(.intro) .landing-rule::after {
    animation-play-state: paused;
}

@media (prefers-reduced-motion: reduce) {
    #landing-bg, .landing-title, .landing-rule, .landing-rule span, .landing-rule::before, .landing-rule::after, .login-container {
        animation: none;
    }
}

@media (max-width: 420px) {
    .login-container { --pad: 1.25rem; }
    .auth-tab { font-size: 0.8rem; letter-spacing: 0.5px; }
}

@media (max-height: 640px) {
    .landing-hero { margin-bottom: 1.25rem; }
    .landing-title { font-size: clamp(2.6rem, 8vw, 3.6rem); }
}

.form-group {
    margin-bottom: 1rem;
    text-align: left;
}

.input-field {
    width: 100%;
    padding: 0.9rem;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-sharp);
    background-color: var(--color-bg-dark);
    color: var(--color-text-normal);
    font-family: var(--font-primary, 'Arial', sans-serif);
    font-weight: 450;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-field:focus {
    outline: none;
    border-color: var(--color-highlight);
    box-shadow: 0 0 0 3px rgba(92, 153, 140, 0.2);
}

.input-field.error {
    border-color: #d9534f;
    box-shadow: 0 0 0 3px rgba(217, 83, 79, 0.2);
}

.input-field.success {
    border-color: var(--color-highlight);
    box-shadow: 0 0 0 3px rgba(92, 153, 140, 0.2);
}

/* Override browser autofill styling to maintain dark theme */
.input-field:-webkit-autofill,
.input-field:-webkit-autofill:hover,
.input-field:-webkit-autofill:focus,
.input-field:-webkit-autofill:active {
    -webkit-box-shadow: 0 0 0 30px var(--color-bg-dark) inset !important;
    -webkit-text-fill-color: var(--color-text-normal) !important;
    background-color: var(--color-bg-dark) !important;
    background-image: none !important;
    transition: background-color 5000s ease-in-out 0s;
}

.input-field:-internal-autofill-selected,
.input-field:autofill {
    background-color: var(--color-bg-dark) !important;
    background-image: none !important;
    color: var(--color-text-normal) !important;
}

.validation-message {
    font-size: 13px;
    margin-top: 4px;
    color: #d9534f;
    opacity: 0;
    transition: opacity 0.2s;
    max-height: 9px;
}

.validation-message.show {
    opacity: 1;
}

.validation-message.success {
    color: var(--color-highlight);
}

.btn {
    width: 100%;
    padding: 0.9rem;
    margin: 0.5rem 0;
    border: 2px solid transparent;
    border-radius: var(--border-radius-sharp);
    background-color: var(--color-highlight);
    color: var(--color-text-title);
    font-size: 0.95rem;
    cursor: var(--cursor-pointer);
    transition: all 0.2s;
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 1px;
}

.btn:hover {
    background-color: #4d8577;
    border-color: var(--color-highlight);
    box-shadow: 0 2px 8px rgba(92, 153, 140, 0.3);
}

.btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 4px rgba(92, 153, 140, 0.3);
}

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

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

.color-picker {
    width: 100%;
    height: 40px;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-sharp);
    cursor: var(--cursor-pointer);
    background-color: var(--color-bg-dark);
}

.message {
    margin-top: 15px;
    padding: 12px;
    border-radius: var(--border-radius-sharp);
    text-align: center;
    font-size: 14px;
    min-height: 20px;
    border: 2px solid transparent;
    opacity: 0;
    transition: opacity 0.2s;
    display: none;
}

.message.show {
    opacity: 1;
    display: block;
}

.message.error {
    background-color: rgba(217, 83, 79, 0.15);
    color: #d9534f;
    border-color: rgba(217, 83, 79, 0.4);
}

.message.success {
    background-color: rgba(92, 153, 140, 0.15);
    color: var(--color-highlight);
    border-color: rgba(92, 153, 140, 0.4);
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--color-text-description);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

/* Game Screen */
#game-screen {
    position: fixed;
    top: 0;
    left: 0;
    background-color: #000000;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: center;
}

#game-container {
    position: relative;
    display: block;
}

#game-canvas {
    display: block;
    background-color: var(--color-bg-dark);
}

#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}


/* Chat System */
/* Lined up with the chat drawn on the canvas (chat-canvas.js): the channel button across its 42 px
   button column and over the input's left border (one border between them), the input under its
   messages (340 px) */
#chat-container {
    position: absolute;
    bottom: 12px;
    left: 0;
    width: 382px;
    pointer-events: none;
    transform-origin: bottom left;
    /* Scale will be set dynamically via JavaScript */
}

#chat-input-container {
    pointer-events: auto;
    display: flex;
    align-items: stretch;
}

#chat-channel {
    position: relative;
    z-index: 1;
    flex: 0 0 44px;
    margin-right: -2px;
}

#chat-channel-button {
    width: 100%;
    height: 100%;
    padding: 0;
    /* Say: the focused input's border colour (the other channels set theirs, as on the input) */
    border: 2px solid var(--chat-channel-color, var(--color-border-active));
    border-radius: var(--border-radius-sharp);
    background-color: var(--color-bg-dark);
    color: var(--chat-channel-color, var(--color-text-normal));
    font-family: var(--font-primary, 'Arial', sans-serif);
    font-size: 9px;
    font-weight: 700;
    line-height: 1.15;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    cursor: var(--cursor-pointer, pointer);
}

#chat-channel-button:hover,
#chat-channel-button.open {
    background-color: var(--color-bg-light);
}

/* The channels, opening upward over the chat */
#chat-channel-menu {
    position: absolute;
    left: 0;
    bottom: calc(100% + 4px);
    min-width: 170px;
    padding: 4px 0;
    border: 2px solid var(--color-border-active);
    border-radius: var(--border-radius-sharp);
    background-color: var(--color-bg-dark);
    font-family: var(--font-primary, 'Arial', sans-serif);
    font-size: 13px;
}

#chat-channel-menu .chat-channel-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: 0;
    background: none;
    color: var(--chat-channel-color, var(--color-text-normal));
    font: inherit;
    text-align: left;
    white-space: nowrap;
    cursor: var(--cursor-pointer, pointer);
}

#chat-channel-menu .chat-channel-item:hover:not(:disabled),
#chat-channel-menu .chat-channel-item.current {
    background-color: var(--color-bg-light);
}

#chat-channel-menu .chat-channel-item:disabled {
    opacity: 0.45;
    cursor: var(--cursor-default);
}

#chat-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    padding: 8px 10px;
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-sharp);
    background-color: var(--color-bg-dark);
    color: var(--color-text-normal);
    font-family: var(--font-primary, 'Arial', sans-serif);
    font-weight: 450;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

/* (no glow round it: it made the input look taller than the channel button beside it) */
#chat-input:focus {
    border-color: var(--color-highlight);
}

/* Mobile Touch Support */
body {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#game-canvas {
    touch-action: none;
    cursor: var(--cursor-default);
}

/* Aiming in the world: the reticle drawn by the game instead (cursor-distance.js) */
#game-canvas.reticle-cursor {
    cursor: none !important;
}

/* Fullscreen Button (Mobile) */
.fullscreen-btn {
    position: fixed;
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    padding: 10px;
    background: rgba(92, 153, 140, 0.9);
    color: var(--color-text-normal);
    border: 2px solid var(--color-border);
    border-radius: var(--border-radius-medium);
    cursor: var(--cursor-pointer);
    z-index: 10000;
    transition: all 0.2s;
    pointer-events: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.fullscreen-btn svg {
    width: 20px;
    height: 20px;
}

.fullscreen-btn:hover {
    background: rgba(92, 153, 140, 1);
    border-color: var(--color-border-active);
}

.fullscreen-btn:active {
    transform: scale(0.95);
    background: rgba(92, 153, 140, 1);
}

/* Responsive Design */
@media (max-width: 768px) {
    .login-container {
        --pad: 1.5rem;
    }

    #game-canvas {
        width: 100%;
        height: auto;
    }
    
    /* Adjust chat for mobile */
    #chat-container {
        width: 300px;
        bottom: 120px;
    }
}
