/* Le arene: elenco (/maps) ed editor (/maps/edit). Globale perché la miniatura è HexGrid, un altro
   componente, e il CSS isolato non lo attraverserebbe. I colori del terreno sono gli stessi di
   HexGrid.Faccia: tienili allineati. */

.mp {
    --t0: #2f405a;
    --t1: #4a7d83;
    --t2: #c99a54;
    --mp-max: 1280px;
    overflow-x: clip;
    padding-bottom: 5rem;
}

.mp .visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- testata ---------- */
.mp-hero {
    position: relative;
    width: min(var(--mp-max), 100%);
    margin: 0 auto;
    padding: 6.5rem clamp(1rem, 4vw, 3rem) 2rem;
}

.mp-hero::before {
    content: "";
    position: absolute;
    inset: 0 -30vw;
    z-index: -1;
    background:
        radial-gradient(ellipse 45% 70% at 15% 30%, rgba(201, 154, 84, 0.16), transparent 70%),
        radial-gradient(ellipse 35% 55% at 85% 20%, rgba(74, 125, 131, 0.18), transparent 70%);
}

.mp-hero h1 {
    margin: 0 0 1rem;
    font: 700 clamp(3rem, 8vw, 6rem)/0.92 'Rajdhani', 'Inter', sans-serif;
    text-transform: uppercase;
}

.mp-hero .lead { max-width: 46rem; }

.mp-hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem 2rem; margin-top: 2rem; }
.mp-hero-actions .btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }

.mp-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.9rem; color: var(--muted); font-size: 0.82rem; }
.mp-legend i, .me-tool .sw {
    display: inline-block;
    width: 14px;
    height: 16px;
    margin-inline-end: 0.35rem;
    vertical-align: -3px;
    clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}
.mp-legend .l0, .me-tool .l0 { background: linear-gradient(135deg, var(--t0), #1d2738); }
.mp-legend .l1, .me-tool .l1 { background: linear-gradient(135deg, var(--t1), #2b4e57); }
.mp-legend .l2, .me-tool .l2 { background: linear-gradient(135deg, var(--t2), #8a6233); }
.mp-legend .lx, .me-tool .lx { background: repeating-linear-gradient(45deg, #0a0d13 0 3px, rgba(255, 159, 67, 0.35) 3px 5px); }

.mp-loading { width: min(var(--mp-max), 100%); margin: 0 auto; padding: 0 clamp(1rem, 4vw, 3rem); color: var(--muted); }

/* ---------- sezioni e schede ---------- */
.mp-section {
    width: min(var(--mp-max), 100%);
    margin: 0 auto;
    padding: clamp(2rem, 5vw, 3.5rem) clamp(1rem, 4vw, 3rem) 0;
}

.mp-head { margin-bottom: 1.4rem; padding-bottom: 1rem; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.mp-head h2 { margin: 0 0 0.3rem; font: 700 1.8rem/1 'Rajdhani', 'Inter', sans-serif; text-transform: uppercase; letter-spacing: 0.05em; }
.mp-head p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.mp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1.1rem; }

.mp-card {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.04), rgba(13, 17, 24, 0.94) 55%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.mp-card:hover { transform: translateY(-4px); border-color: rgba(201, 154, 84, 0.5); box-shadow: 0 26px 50px -26px rgba(201, 154, 84, 0.55); }
.mp-card.official::after { content: ""; position: absolute; inset-inline: 0; top: 0; height: 3px; background: linear-gradient(90deg, #c99a54, #ffd166, #c99a54); }
.mp-card.mine { border-style: dashed; border-color: rgba(94, 234, 212, 0.35); }
.mp-card.mine:hover { border-color: #5eead4; box-shadow: 0 26px 50px -26px rgba(94, 234, 212, 0.5); }

.mp-thumb {
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 10;
    padding: 1rem 1.2rem;
    background:
        radial-gradient(ellipse 70% 70% at 50% 40%, rgba(77, 142, 247, 0.1), transparent 70%),
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px) 0 0 / 18px 18px,
        linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px) 0 0 / 18px 18px,
        #0a0d13;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

/* La miniatura si adatta al riquadro: l'SVG prende tutto lo spazio e «meet» lo fa stare intero,
   qualunque sia il rapporto fra larghezza e altezza della mappa. */
.mp-thumb { position: relative; }
.mp-thumb .hex-grid-wrapper { position: absolute; inset: 1rem 1.2rem; }
.mp-thumb .hex-grid { width: 100%; height: 100%; transition: transform 0.4s ease; filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.6)); }
.mp-card:hover .mp-thumb .hex-grid { transform: scale(1.04) rotateX(6deg); }

.mp-body { display: grid; gap: 0.7rem; padding: 1.1rem 1.2rem 1.2rem; }
.mp-title { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.mp-title h3 { margin: 0; font: 700 1.45rem/1 'Rajdhani', 'Inter', sans-serif; text-transform: uppercase; }

.mp-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.25rem 0.55rem;
    border: 1px solid rgba(255, 209, 102, 0.6);
    border-radius: 999px;
    color: var(--accent);
    font: 700 0.66rem/1 'Rajdhani', sans-serif;
    text-transform: uppercase;
    letter-spacing: 0.16em;
}

.mp-badge svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 2.2; }
.mp-desc { margin: 0; color: #b6c3d7; font-size: 0.88rem; line-height: 1.5; }

.mp-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.4rem; margin: 0; }
.mp-stats > div { padding: 0.5rem 0.4rem; text-align: center; background: rgba(255, 255, 255, 0.03); border-radius: 8px; }
.mp-stats dt { color: var(--muted); font-size: 0.62rem; text-transform: uppercase; letter-spacing: 0.1em; }
.mp-stats dd { margin: 0.25rem 0 0; font: 700 1.15rem/1 'Rajdhani', sans-serif; }

.mp-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.45rem; }
.mp-confirm { color: #ffb3b3; font-size: 0.85rem; }

.mp-btn {
    display: inline-flex;
    align-items: center;
    padding: 0.45rem 0.85rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 8px;
    color: #d6deea;
    font: 600 0.82rem/1 'Inter', sans-serif;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.mp-btn:hover, .mp-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.3); color: #fff; }
.mp-btn.primary, .mp-btn.primary:hover:not(:disabled) { background: rgba(255, 209, 102, 0.14); border-color: rgba(255, 209, 102, 0.6); color: var(--accent); }
.mp-btn.danger-soft { color: #ff9a9a; }
.mp-btn.danger, .mp-btn.danger:hover:not(:disabled) { border-color: rgba(255, 107, 107, 0.7); color: #ff8a8a; background: rgba(255, 107, 107, 0.1); }

.mp-new {
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 0.5rem;
    min-height: 320px;
    padding: 1.5rem;
    border: 1px dashed rgba(94, 234, 212, 0.4);
    border-radius: 16px;
    color: inherit;
    text-align: center;
    text-decoration: none;
    background: radial-gradient(ellipse at center, rgba(94, 234, 212, 0.06), transparent 70%);
    transition: border-color 0.2s, background 0.2s;
}

.mp-new:hover { border-color: #5eead4; background: radial-gradient(ellipse at center, rgba(94, 234, 212, 0.12), transparent 70%); }
.mp-new strong { font: 700 1.3rem/1 'Rajdhani', sans-serif; text-transform: uppercase; letter-spacing: 0.08em; color: #5eead4; }
.mp-new span:last-child { color: var(--muted); font-size: 0.85rem; max-width: 22rem; }
.mp-new-hex { display: grid; place-items: center; width: 64px; height: 72px; background: rgba(94, 234, 212, 0.14); clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); color: #5eead4; }
.mp-new-hex svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }

/* ---------- editor ---------- */
.me-hero { padding-bottom: 1.5rem; }
.me-back { display: inline-flex; gap: 0.4rem; margin-bottom: 1.2rem; color: var(--muted); text-decoration: none; font: 600 0.85rem/1 'Rajdhani', sans-serif; text-transform: uppercase; letter-spacing: 0.15em; }
.me-back:hover { color: var(--accent); }
:root[dir="rtl"] .me-back span { transform: scaleX(-1); }

.me-name input {
    width: 100%;
    margin-bottom: 0.6rem;
    padding: 0.1rem 0 0.4rem;
    background: none;
    border: 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 0;
    color: #f4f7fc;
    font: 700 clamp(2.4rem, 7vw, 4.6rem)/1 'Rajdhani', 'Inter', sans-serif;
    text-transform: uppercase;
}

.me-name input:focus { outline: none; box-shadow: none; border-bottom-color: var(--accent); }

.me-setup, .me-layout {
    display: grid;
    gap: 1.4rem;
    align-items: start;
    width: min(var(--mp-max), 100%);
    margin: 0 auto;
    padding: 0 clamp(1rem, 4vw, 3rem);
}

.me-setup { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); }
.me-layout { grid-template-columns: minmax(0, 1fr) 320px; }

.me-card {
    display: grid;
    gap: 0.9rem;
    margin: 0;
    padding: 1.2rem;
    background: linear-gradient(160deg, rgba(255, 255, 255, 0.035), rgba(13, 17, 24, 0.92) 60%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
}

.me-label, .me-field > span { color: var(--muted); font: 600 0.72rem/1 'Inter', sans-serif; text-transform: uppercase; letter-spacing: 0.12em; }
.me-field { display: grid; gap: 0.4rem; }
.me-field input { padding: 0.65rem 0.8rem; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.12); border-radius: 8px; color: var(--text); }
.me-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255, 209, 102, 0.15); }
.me-custom { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; }

.me-sizes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; }
.me-size { display: grid; gap: 0.2rem; padding: 0.75rem; background: rgba(255, 255, 255, 0.03); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 10px; color: var(--text); text-align: start; cursor: pointer; }
.me-size strong { font: 700 1rem/1 'Rajdhani', sans-serif; text-transform: uppercase; letter-spacing: 0.08em; }
.me-size span { color: var(--muted); font-size: 0.8rem; }
.me-size:hover:not(:disabled) { background: rgba(255, 255, 255, 0.06); border-color: rgba(255, 209, 102, 0.4); }
.me-size.on, .me-size.on:hover:not(:disabled) { background: rgba(255, 209, 102, 0.12); border-color: var(--accent); }
.me-size.on strong { color: var(--accent); }

.me-preview .hex-grid-wrapper { min-height: 320px; display: grid; place-items: center; }
.me-preview .hex-grid { width: 100%; height: auto; max-height: 440px; }

/* Nell'editor la mappa intera sta nello schermo: l'SVG scala sul viewBox invece di traboccare,
   e i clic restano sulle caselle giuste perché il ridimensionamento è dell'SVG stesso. */
.me-canvas { min-width: 0; }
.me-canvas .hex-grid { width: 100%; height: auto; max-height: 76vh; }

.me-dock { position: sticky; top: 4.5rem; display: grid; gap: 0.8rem; }

.me-tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.4rem; }

.me-tool {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.6rem 0.7rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: #d6deea;
    font: 600 0.85rem/1 'Inter', sans-serif;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.me-tool .sw { width: 18px; height: 20px; flex-shrink: 0; }
.me-tool .eraser { background: rgba(255, 255, 255, 0.15); clip-path: none; border-radius: 4px; transform: rotate(-20deg) scale(0.8); }
.me-tool:hover:not(:disabled) { background: rgba(255, 255, 255, 0.07); border-color: rgba(255, 255, 255, 0.25); }
.me-tool.on, .me-tool.on:hover:not(:disabled) { background: rgba(255, 209, 102, 0.12); border-color: var(--accent); color: #fff; }

.me-sym {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    padding: 0.7rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    color: var(--text);
    text-align: start;
    cursor: pointer;
}

.me-sym:hover:not(:disabled) { background: rgba(255, 255, 255, 0.05); border-color: rgba(255, 255, 255, 0.15); }
.me-sym strong { display: block; font-size: 0.9rem; }
.me-sym small { color: var(--muted); font-size: 0.76rem; }
.me-sym-switch { position: relative; flex-shrink: 0; width: 42px; height: 24px; background: rgba(255, 255, 255, 0.12); border-radius: 999px; transition: background 0.2s; }
.me-sym-switch i { position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; background: #b6c3d7; border-radius: 50%; transition: transform 0.2s; }
.me-sym.on .me-sym-switch { background: linear-gradient(135deg, #ffd166, #ff9f43); }
.me-sym.on .me-sym-switch i { background: #1b1405; transform: translateX(18px); }
:root[dir="rtl"] .me-sym.on .me-sym-switch i { transform: translateX(-18px); }

.me-dock .mp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.me-save .btn { width: 100%; }
.me-note { margin: 0; color: var(--muted); font-size: 0.8rem; line-height: 1.5; }
.me-msg { margin: 0; font-size: 0.86rem; }
.me-msg.ok { color: #5eea8c; }
.me-msg.error { color: #ff8a8a; }

.me-locked { justify-items: start; border-color: rgba(255, 209, 102, 0.35); }
.me-locked svg { width: 28px; height: 28px; fill: none; stroke: var(--accent); stroke-width: 1.8; }
.me-locked p { margin: 0; color: #c4cfe0; font-size: 0.9rem; line-height: 1.5; }

@media (max-width: 1000px) {
    .me-setup, .me-layout { grid-template-columns: minmax(0, 1fr); }
    .me-dock { position: static; }
}

@media (max-width: 560px) {
    .mp-grid { grid-template-columns: 1fr; }
    .mp-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    .mp-card, .mp-thumb .hex-grid { transition: none; }
}
.me-tourney { margin-top: 0.5rem; display: block; text-align: center; }
.me-tool .sw.swap { display: grid; place-items: center; font-style: normal; color: #ffd166; border: 1px dashed #ffd166; }
