:root {
    --light: #f0d9b5;
    --dark: #b58863;
    --sel: #f6f669;
    --size: min(80vw, 560px);
}

/* Temas de tablero — se aplican como clase en #board */
#board.theme-classic { --light: #f0d9b5; --dark: #b58863; --sel: #f6f669; }
#board.theme-green   { --light: #eeeed2; --dark: #769656; --sel: #f6f669; }
#board.theme-blue    { --light: #dee3e6; --dark: #8ca2ad; --sel: #f7e07a; }
#board.theme-gray    { --light: #dcdcdc; --dark: #999999; --sel: #f6f669; }
#board.theme-wood    { --light: #e8c99b; --dark: #9b5a2c; --sel: #f6d860; }
#board.theme-coral   { --light: #f1dcd2; --dark: #c57b66; --sel: #f6f669; }
#board.theme-purple  { --light: #e9e2f3; --dark: #8769b0; --sel: #f6f669; }
#board.theme-midnight { --light: #6f7d93; --dark: #2e3a4f; --sel: #c9b458; }

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: #2b2b2b;
    color: #eee;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

header {
    text-align: center;
    margin: 24px 0 8px;
}

header h1 { margin: 0; font-size: 2rem; }
.subtitle { margin: 4px 0 0; color: #aaa; }

main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 16px;
}

#board {
    width: var(--size);
    height: var(--size);
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-template-rows: repeat(8, 1fr);
    border: 4px solid #1a1a1a;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    user-select: none;
}

.square {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(var(--size) / 10);
    cursor: grab;
    position: relative;
}

.square.light { background: var(--light); }
.square.dark { background: var(--dark); }
.square.selected { background: var(--sel); }

.piece { line-height: 1; }
.piece.glyph.white { color: #fff; text-shadow: 0 0 2px #000, 0 1px 2px rgba(0,0,0,.6); }
.piece.glyph.black { color: #111; text-shadow: 0 0 2px #999; }
.piece.img {
    width: 88%;
    height: 88%;
    pointer-events: auto;
    -webkit-user-drag: element;
}

.square.dragover { outline: 3px solid #4a90d9; outline-offset: -3px; }

.panel {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 1.1rem;
    flex-wrap: wrap;
    justify-content: center;
}

.themes {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}
.themes h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #bbb;
    margin: 0;
}
.sel-label {
    color: #4a90d9;
    font-weight: 700;
}
.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    max-width: var(--size);
}
.swatch {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 2px solid transparent;
    cursor: pointer;
    padding: 0;
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    transition: transform .1s, border-color .1s;
}
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: #4a90d9; box-shadow: 0 0 0 2px rgba(74,144,217,.4); }
.swatch span { display: block; }
.swatch .l { background: var(--sw-light); }
.swatch .d { background: var(--sw-dark); }

/* Botones de set de piezas */
.pset {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 2px solid transparent;
    background: #e9e3d6;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .1s, border-color .1s;
}
.pset:hover { transform: scale(1.08); }
.pset.active { border-color: #4a90d9; box-shadow: 0 0 0 2px rgba(74,144,217,.4); }
.pset img { width: 100%; height: 100%; }
.pset-glyph { font-size: 1.6rem; color: #111; }

.credits {
    margin: 8px 0 24px;
    color: #888;
    font-size: 0.85rem;
    text-align: center;
}
.credits a { color: #6aa9e0; }

button {
    background: #4a90d9;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
}
button:hover { background: #3a7ec0; }

/* ===================== Auth / UI general ===================== */
a { color: #6aa9e0; }
.brand { color: #eee; text-decoration: none; }

.topnav {
    display: flex;
    gap: 14px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 6px;
    font-size: 0.95rem;
}
.topnav .hi { color: #aaa; }
.inline { display: inline; margin: 0; }
.linkbtn {
    background: none;
    border: none;
    color: #6aa9e0;
    cursor: pointer;
    font-size: 0.95rem;
    padding: 0;
}
.linkbtn:hover { text-decoration: underline; }

.flashes { list-style: none; padding: 0; margin: 12px auto; max-width: 420px; }
.flash {
    padding: 10px 14px;
    border-radius: 8px;
    margin: 6px 0;
    font-size: 0.95rem;
}
.flash-success { background: #1f3d2b; color: #b6f0c6; border: 1px solid #2f6b46; }
.flash-error   { background: #41232a; color: #f3b6c0; border: 1px solid #7a3340; }

.card {
    background: #3a3a3a;
    border-radius: 12px;
    padding: 24px;
    max-width: 420px;
    margin: 16px auto;
    box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.card h2 { margin-top: 0; }

.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.9rem; color: #ccc; }
.field input[type="text"],
.field input[type="email"],
.field input[type="password"] {
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #555;
    background: #2b2b2b;
    color: #eee;
    font-size: 1rem;
}
.field input:focus { outline: 2px solid #4a90d9; border-color: #4a90d9; }
.field-check { margin: 10px 0; color: #ccc; font-size: 0.9rem; }
.field-errors { color: #f3b6c0; font-size: 0.85rem; margin: 2px 0 0; padding-left: 18px; }

.hint { color: #999; font-size: 0.82rem; margin: 4px 0 14px; }
.muted { color: #999; font-size: 0.9rem; margin-top: 16px; }
.warn { color: #f3b6c0; }

.btn-primary, .btn-danger, .btn {
    display: inline-block;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    color: #fff;
}
.btn-primary { background: #4a90d9; }
.btn-primary:hover { background: #3a7ec0; }
.btn { background: #555; }
.btn:hover { background: #666; }
.btn-danger { background: #a23a4a; }
.btn-danger:hover { background: #8a2f3e; }

.profile { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; margin: 16px 0; }
.profile dt { color: #999; }
.profile dd { margin: 0; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }

/* ===================== Workspace: navbar superior ===================== */
body.workspace { align-items: stretch; }

.navbar {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 0 20px;
    height: 56px;
    background: #1f1f1f;
    border-bottom: 1px solid #333;
    box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.navbar .brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: #eee;
    text-decoration: none;
    white-space: nowrap;
}
.navbar .menu {
    list-style: none;
    display: flex;
    gap: 6px;
    margin: 0;
    padding: 0;
}
.navbar .menu a {
    display: block;
    padding: 8px 14px;
    border-radius: 8px;
    color: #cfcfcf;
    text-decoration: none;
    font-size: 0.95rem;
}
.navbar .menu a:hover { background: #2e2e2e; color: #fff; }
.navbar .menu a.active { background: #4a90d9; color: #fff; }

.navuser {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}
.navuser-name { color: #9ec5ef; text-decoration: none; font-weight: 600; }
.navuser-name:hover { text-decoration: underline; }

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #eee;
    font-size: 1.4rem;
    cursor: pointer;
}

/* Marca centrada en login/registro */
body.auth { justify-content: flex-start; }
.auth-brand {
    font-size: 2rem;
    font-weight: 700;
    color: #eee;
    text-align: center;
    margin: 40px 0 4px;
}

/* Responsive: menú colapsable en móvil */
@media (max-width: 720px) {
    .nav-toggle { display: block; order: 3; margin-left: auto; }
    .navuser { order: 2; margin-left: auto; }
    .navbar { flex-wrap: wrap; height: auto; padding: 10px 16px; }
    .navbar .menu {
        order: 4;
        flex-basis: 100%;
        flex-direction: column;
        display: none;
        padding-top: 8px;
    }
    .navbar.open .menu { display: flex; }
}
