:root {
    color-scheme: dark;
    --bg: #07111f;
    --panel: #101f32;
    --panel2: #142840;
    --text: #eef6ff;
    --muted: #a9bdd1;
    --line: #2d4966;
    --blue: #168bff;
    --cyan: #49d9ff;
    --gold: #b88700;
    --good: #43d17d;
    --bad: #ff626f;
    --board-fixed: #ffffff;
    --board-fixed-text: #142b3f;
    --board-empty: #fff7c4;
    --board-entry: #9a6a00;
    --key-bg: #f1f8fb;
    --key-text: #193045;
    --key-area: #193045;
    --shadow: 0 12px 35px #0005;

}

:root.light {
    color-scheme: light;
    --bg: #eaf5ff;
    --panel: #fff;
    --panel2: #f2f8ff;
    --text: #102b45;
    --muted: #5d7287;
    --line: #c4d7e8;
    --blue: #0879d8;
    --cyan: #008fb9;
    --gold: #9a6a00;
    --board-fixed: #f5f5f5;
    --board-fixed-text: #142b3f;
    --board-empty: #fff7c4;
    --board-entry: #9a6a00;
    --key-bg: #f1f8fb;
    --key-text: #193045;
    --key-area: #81C9E8;
    --shadow: 0 12px 35px #20405c18;

}

* {
    box-sizing: border-box;

}

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(ellipse at 15% 0%,#0d3960 0,transparent 42%),var(--bg);
    color: var(--text);
    font: 16px/1.45 Inter,system-ui,-apple-system,Segoe UI,sans-serif;

}

body:before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    opacity: .12;
    background-image: linear-gradient(#5acaff22 1px,transparent 1px),linear-gradient(90deg,#5acaff22 1px,transparent 1px);
    background-size: 36px 36px;

}

.app {
    position: relative;
    max-width: 1120px;
    margin: auto;
    padding: 18px 18px 38px;

}

.top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 22px;

}

.brand {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 0;

}

.brand-logo {
    display: block;
    width: clamp(220px,32vw,420px);
    height: auto;
    max-height: 100px;
    object-fit: contain;
    object-position: left center;
    flex: 0 1 auto;
    filter: drop-shadow(0 3px 10px #0003);

}

.mark {
    display: none;

}

.top-actions {
    display: flex;
    gap: 8px;
    align-items: center;

}

.view {
    display: none;
    animation: fade .18s ease;

}

.view.active {
    display: block;

}

@keyframes fade {
    from {
        opacity: .65;
        transform: translateY(3px);
    }
    to {
        opacity: 1;
        transform: none;
    }

}

.card {
    background: linear-gradient(150deg,var(--panel),var(--panel2));
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: clamp(16px,3vw,28px);
    box-shadow: var(--shadow);

}

h1,h2,h3,p {
    margin-top: 0;

}

h1 {
    font-size: clamp(1.8rem,5vw,3.2rem);
    line-height: 1.05;
    margin-bottom: 12px;

}

h2 {
    font-size: clamp(1.3rem,3vw,2rem);

}

.muted {
    color: var(--muted);

}

.eyebrow {
    color: var(--cyan);
    font-weight: 800;
    letter-spacing: .14em;
    font-size: .76rem;
    text-transform: uppercase;

}

.hero {
    text-align: center;
    padding: clamp(24px,7vw,70px) 18px;

}

.home-hero {
    padding: 12px 18px 16px;
    margin-bottom: 14px;

}

.home-hero .eyebrow {
    margin-bottom: 6px;

}

.home-hero .home-quote {
    font-size: clamp(1.2rem,3.1vw,2rem);
    line-height: 1.15;
    margin: 0 auto 9px;
    min-height: 1.2em;

}

.home-hero>p:not(.eyebrow) {
    margin-bottom: 12px;

}

.home-hero .actions {
    gap: 8px;

}

.hero h1 span {
    color: var(--cyan);

}

.hero p {
    max-width: 620px;
    margin: 0 auto 24px;
    color: var(--muted);

}

.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;

}

.btn {
    appearance: none;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 11px 16px;
    background: var(--panel2);
    color: var(--text);
    font: inherit;
    font-weight: 750;
    cursor: pointer;
    transition: .15s;
    min-height: 44px;

}

.btn:hover {
    border-color: var(--cyan);
    transform: translateY(-1px);

}

.btn.primary {
    background: linear-gradient(120deg,var(--blue),#0871c8);
    border-color: transparent;
    color: #fff;

}

.btn.gold {
    background: var(--gold);
    color: #17202b;
    border-color: transparent;

}

.btn.danger {
    border-color: #a64250;
    color: var(--bad);

}

.btn:disabled {
    opacity: .4;
    cursor: not-allowed;
    transform: none;

}

.gridmenu {
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(190px,1fr));
    gap: 12px;
    margin-top: 20px;

}

.tile {
    min-height: 115px;
    text-align: left;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;

}

.tile b {
    font-size: 1.05rem;

}

.tile span {
    font-size: .88rem;
    color: var(--muted);

}

.row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;

}

.between {
    justify-content: space-between;

}

.status {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--panel2);
    border: 1px solid var(--line);
    color: var(--muted);
    margin: 12px 0;

}

.status.error {
    color: var(--bad);
    border-color: #a64250;

}

.status.good {
    color: var(--good);
    border-color: #258852;

}

.game-layout {
    display: grid;
    grid-template-columns: minmax(0,1.2fr) minmax(230px,.8fr);
    gap: 18px;
    align-items: start;

}

.gamehead {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;

}

.pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;

}

.pill {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 99px;
    color: var(--muted);
    font-size: .9rem;

}

:root.light .pill {
    color: #34495e;
}

.board-and-keys {
    display: grid;
    grid-template-columns: minmax(0,1fr) minmax(190px,.55fr);
    gap: 14px;
    align-items: start;

}

.keypanel {
    min-width: 0;
    background: var(--key-area);
    padding: 10px;
    border-radius: 10px;

}

.keypanel h3 {
    margin: 0 0 8px;
    color: #fff;

}

.boardwrap {
    width: 100%;
    overflow: visible;
    padding: 6px;
    margin: -6px;
    min-width: 0;

}

.board {
    display: grid;
    grid-template-columns: repeat(7,minmax(0,1fr));
    gap: 5px;
    min-width: 310px;
    max-width: 620px;
    margin: auto;

}

.cell {
    font-family: Arial, Helvetica, sans-serif;
}

.cell,.sum {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel2);
    font-size: clamp(.95rem,3vw,1.4rem);
    font-weight: 850;
    position: relative;
    user-select: none;

}

.cell {
    cursor: pointer;

}

.cell.fixed {
    cursor: default;
    background: var(--board-fixed);
    color: var(--board-fixed-text);
    border-color: #d5e0e8;

}

:root.light .cell.fixed {
    border-color: #cccccc;
}

.cell.empty {
    background: var(--board-empty);
    color: #193045;
    border: 2px solid #e4dcae;
    box-shadow: inset 0 0 0 1px #ffffff88;

}

.cell.empty:after {
    display: none;
}

.cell.empty.selected:after {
    display: none;

}

.cell.selected {
    outline: none;
    outline-offset: 0;
    box-shadow: inset 0 0 0 3px var(--cyan),inset 0 0 18px #39d9ff90,inset 0 0 5px 2px #39d9ff55;
    z-index: 1;

}

.cell.filled {
    background: var(--board-empty);
    color: var(--board-entry);
    border-color: #dcbe50;
    box-shadow: inset 0 0 12px #ffc83d19;

}

.cell.wrong {
    border-color: var(--bad);
    color: var(--bad);

}

.cell small {
    position: absolute;
    right: 3px;
    bottom: 0;
    font-size: .5rem;
    color: var(--muted);
    font-weight: 500;

}

.sum {
    background: #0d3855;
    color: #8ee7ff;
    font-size: clamp(.75rem,2.5vw,1rem);
    border-color: #1a668a;

}

.light .sum {
    background: #dff5ff;
    color: #075477;

}

.sum.bottom {
    aspect-ratio: 1;

}

.sum.blank {
    opacity: 0;

}

.keyboard {
    display: grid;
    grid-template-columns: repeat(5,minmax(0,1fr));
    gap: 6px;
    margin-top: 0;
    max-height: 540px;
    overflow-y: auto;
    align-content: start;
    padding: 2px;

}

.key {
    min-height: 54px;
    padding: 5px;
    border-radius: 9px;
    border: 1px solid #d1e0e8;
    background: var(--key-bg);
    color: var(--key-text);
    font-weight: 800;
    font-size: 1.05rem;
    cursor: pointer;
    box-shadow: 0 2px 4px #0001;

}

.key[data-letter="Z"] {
    grid-column: 3;

}

.key.used {
    opacity: 1;

}

.key.selected {
    border: 2px solid var(--gold);
    color: #9a6a00;
    box-shadow: 0 0 10px #ffc83d45;

}

.side {
    display: grid;
    gap: 14px;

}

.side .card {
    padding: 18px;

}

.side h3 {
    margin-bottom: 8px;

}

.helptext {
    font-size: .9rem;
    color: var(--muted);

}

.statgrid {
    display: grid;
    grid-template-columns: repeat(2,1fr);
    gap: 10px;

}

.stat {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;

}

.stat strong {
    display: block;
    font-size: 1.45rem;
    color: var(--cyan);

}

label {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 12px 0;

}

input[type=text],input[type=number],select {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    font: inherit;

}

input[type=checkbox] {
    width: 18px;
    height: 18px;
    accent-color: var(--blue);

}

.hidden {
    display: none!important;

}

.list {
    display: grid;
    gap: 8px;

}

.player {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    gap: 12px;

}

.footer {
    text-align: center;
    color: var(--muted);
    font-size: .8rem;
    margin-top: 22px;

}

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: 12px;
    padding: 12px 16px;
    max-width: 90vw;

}

.mp-result {
    text-align: center;
    padding: clamp(28px,7vw,64px) 18px;

}

.mp-result .result-symbol {
    font-size: clamp(4rem,14vw,7rem);
    line-height: 1;
    margin: 8px 0 20px;
    text-shadow: 0 0 28px currentColor;

}

.mp-result.win {
    border-color: var(--good);
    box-shadow: 0 0 34px #43d17d25,var(--shadow);

}

.mp-result.win .result-symbol,.mp-result.win h1 {
    color: var(--good);

}

.mp-result.lose {
    border-color: var(--bad);
    box-shadow: 0 0 34px #ff626f20,var(--shadow);

}

.mp-result.lose .result-symbol,.mp-result.lose h1 {
    color: var(--bad);

}

.glow .board {
    filter: none;

}

.glow .boardwrap {
    overflow: visible;

}

.glow .cell,.glow .key {
    box-shadow: inset 0 0 0 1px #159cff22;

}

.glow .cell.selected {
    box-shadow: inset 0 0 0 3px var(--cyan),inset 0 0 20px #49d9ffbb,inset 0 0 6px 2px #49d9ff66;

}

@media(max-width:760px) {
    .brand-logo {
        width: clamp(160px,48vw,280px);
        max-height: 72px;
    }
    .top {
        gap: 8px;
    }
    .top-actions {
        gap: 5px;
    }
    .top-actions .btn {
        padding: 8px 9px;
        min-height: 38px;
    }
    .app {
        padding: 12px;
    }
    .game-layout {
        grid-template-columns: minmax(0,1fr);
    }
    .side {
        grid-template-columns: repeat(auto-fit,minmax(190px,1fr));
    }
    /* Phone layout: board gets the full row and the letter keyboard moves underneath. */
    .board-and-keys {
        display: grid;
        grid-template-columns: minmax(0,1fr)!important;
        gap: 12px;
        width: 100%;
    }
    .boardwrap {
        width: 100%;
        min-width: 0;
        overflow: visible;
    }
    .board {
        width: 100%;
        max-width: none;
        min-width: 0;
        grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
        gap: clamp(2px,.7vw,5px);
    }
    .cell,.sum {
        aspect-ratio: 1;
        min-width: 0;
        padding: 0;
        display: grid;
        place-items: center;
        font-size: clamp(1.15rem,4.2vw,1.55rem);
        line-height: 1;
        border-radius: 6px;
    }
    .sum {
        font-size: clamp(.85rem,3vw,1.15rem);
    }
    .cell small {
        font-size: clamp(.48rem,1.8vw,.64rem);
        right: 2px;
    }
    .keypanel {
        width: 100%;
        min-width: 0;
        padding: 10px;
    }
    .keyboard {
        width: 100%;
        grid-template-columns: repeat(5,minmax(0,1fr));
        max-height: none;
        overflow: visible;
        gap: clamp(5px,1.4vw,9px);
        padding: 2px;
    }
    .key {
        width: 100%;
        min-width: 0;
        min-height: clamp(37px,7.5vw,50px);
        aspect-ratio: auto;
        padding: 4px 2px;
        font-size: clamp(1.15rem,4.2vw,1.45rem);
        line-height: 1.1;
        border-radius: 9px;
        white-space: normal;
    }
    .key small {
        font-size: clamp(.58rem,2vw,.72rem)!important;
    }
    /* Smartphone: la selezione non deve modificare le dimensioni del tasto. */
    .key.selected {
        border: 1px solid var(--gold);
        box-shadow: inset 0 0 0 1px var(--gold), 0 0 10px #ffc83d45;
    }
    .top {
        margin-bottom: 14px;
    }

}

@media(max-width:380px) {
    .app {
        padding: 8px;
    }
    .board {
        grid-template-columns: repeat(7, minmax(0, 1fr)) !important;
        gap: 2px;
    }
    .cell,.sum {
        font-size: clamp(1rem,4.5vw,1.25rem);
    }
    .sum {
        font-size: clamp(.78rem,3.5vw,.95rem);
    }
    .key {
        min-height: 37px;
        font-size: 1.15rem;
    }
    .keypanel {
        padding: 8px;
    }

}

@media(prefers-reduced-motion:reduce) {
    * {
        animation: none!important;
        transition: none!important;
    }

}

.tutorial-board-wrap {
    display: grid;
    grid-template-columns: minmax(0,1fr);
    gap: 12px;
    margin: 18px auto;
    max-width: 310px;

}

.tutorial-board {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(6,minmax(0,1fr)) 24px;
    gap: 2px;

}

.tutorial-board .cell,.tutorial-board .sum {
    min-width: 0;
    font-size: clamp(.72rem,2.7vw,1.15rem);
    border-radius: 6px;

}

.tutorial-board .cell.tutorial-target {
    outline: 3px solid var(--cyan);
    outline-offset: 1px;
    z-index: 2;

}

.tutorial-board .cell.tutorial-done {
    border-color: #e1bd46;
    box-shadow: inset 0 0 0 2px #e1bd4688;

}

.tutorial-keyboard {
    display: grid;
    grid-template-columns: repeat(13,minmax(0,1fr));
    gap: 4px;

}

.tutorial-key {
    padding: 5px 0;
    min-width: 0;
    font-weight: 800;
    text-align: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel2);
    color: var(--text);
    font-size: clamp(.65rem,2.5vw,.9rem);

}

.tutorial-key.tutorial-key-active {
    border-color: var(--cyan);
    outline: 2px solid var(--cyan);
    background: var(--panel);
    color: var(--cyan);

}

@media(max-width:600px) {
    .tutorial-board-wrap {
        width: min(50%,310px);
    }
    .tutorial-board {
        grid-template-columns: repeat(6,minmax(0,1fr)) 20px;
        gap: 2px;
    }
    .tutorial-board .cell,.tutorial-board .sum {
        font-size: clamp(.68rem,3vw,.95rem);
        border-radius: 5px;
    }
    .tutorial-keyboard {
        grid-template-columns: repeat(7,minmax(0,1fr));
    }
    .tutorial-key {
        padding: 7px 0;
    }

}

.toast {
    display: flex;
    flex-direction: column;
    gap: 4px;

}

.toast strong {
    font-size: .82em;
    letter-spacing: .02em;

}

.toast span {
    display: block;

}

/* Solo PC: sei schede sulla stessa riga */

@media (min-width: 761px) {
    .gridmenu {
        display: grid !important;
        grid-template-columns: repeat(6, minmax(0, 1fr)) !important;
        gap: 8px;
        width: 100%;
    }
    .gridmenu > .tile {
        width: 100%;
        min-width: 0;
        margin: 0;
        padding: 12px 8px;
        box-sizing: border-box;
    }

}

/* PC e tablet in orizzontale: più spazio alla griglia e alla tastiera,
   meno spazio ai riquadri laterali Stato partita e Legenda. */
@media (min-width: 761px) and (orientation: landscape) {
    .game-layout {
        grid-template-columns: minmax(0, 1.65fr) minmax(170px, 0.55fr);
        gap: 14px;
    }

    .side {
        min-width: 0;
        gap: 10px;
    }

    .side .card {
        min-width: 0;
        padding: 12px;
    }

    .board-and-keys {
        grid-template-columns: minmax(0, 1fr) minmax(0, 0.62fr);
        gap: 10px;
    }

    .keypanel {
        padding: 8px;
    }

    .keyboard {
        gap: 7px;
    }
}

/* Correzione mirata: tablet/iPad in verticale; PC e smartphone non modificati. */

@media (min-width: 761px) and (max-width: 1024px) and (orientation: portrait) {
    .board-and-keys {
        grid-template-columns: minmax(0, 1fr) !important;
    }
    .boardwrap {
        min-width: 0;
        width: 100%;
    }
    .board {
        width: 100%;
        max-width: 620px;
        min-width: 0;
    }
    .keyboard {
        max-height: none;
        overflow: visible;
    }

}


/* iPad/tablet in portrait: taller home tiles so all Italian/English text fits. */
@media (min-width: 761px) and (max-width: 1024px) and (orientation: portrait) {
    #home .gridmenu > .tile {
        min-height: 175px;
        height: auto;
        padding: 14px 8px;
        justify-content: flex-start;
        gap: 10px;
        overflow-wrap: anywhere;
    }

    #home .gridmenu > .tile b,
    #home .gridmenu > .tile span {
        line-height: 1.3;
        overflow-wrap: anywhere;
    }
}


/* iPad/tablet in verticale: menu disposto su 3 colonne e 2 righe */
@media (min-width: 761px) and (max-width: 1024px) and (orientation: portrait) {
    #home .gridmenu {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
        gap: 12px;
    }
    #home .gridmenu > .tile {
        min-height: 175px;
        height: auto;
        padding: 14px 10px;
        box-sizing: border-box;
        justify-content: flex-start;
        gap: 10px;
        overflow-wrap: anywhere;
    }
    #home .gridmenu > .tile b,
    #home .gridmenu > .tile span {
        line-height: 1.3;
        overflow-wrap: anywhere;
    }
}

/* Solo smartphone in verticale: menu disposto su 2 colonne e 3 righe.
   Le regole specifiche per iPad (da 761px in su) restano invariate. */
@media (max-width: 760px) and (orientation: portrait) {
    #home .gridmenu {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 10px;
    }

    #home .gridmenu > .tile {
        min-width: 0;
        height: auto;
        min-height: 135px;
        padding: 12px 10px;
        box-sizing: border-box;
        justify-content: flex-start;
        gap: 8px;
        overflow-wrap: anywhere;
    }

    #home .gridmenu > .tile b,
    #home .gridmenu > .tile span {
        line-height: 1.3;
        overflow-wrap: anywhere;
    }
}
