:root
{
    --color-blue: #2F6AB5;
    --color-blue-light: #B8CCE4;
    --color-blue-dark: color-mix(in srgb, var(--color-blue) 75%, black);
    --color-orange: #CA4B0C;
    --color-orange-light: #EDC1AA;
    --color-orange-dark: color-mix(in srgb, var(--color-orange) 75%, black);
    --color-background: #FFFFFC;
}
*,
*::before,
*::after
{
    box-sizing: border-box;
}
body
{
    font-family: "Jura", sans-serif;
    color: black;
    background-color: var(--color-background);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    margin: 0;
}
.visually-hidden
{
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
#game-over-screen[open]
{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 52px 64px;
    background: white;
    border-radius: 0;
}
#start-screen
{
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 32px;
    margin-top: 96px;
    padding: clamp(24px, 6vw, 72px) clamp(16px, 6vw, 96px);
}
#start-screen h1
{
    align-self: center;
    margin: 0;
    font-family: "Jura", sans-serif;
    font-weight: 300;
    letter-spacing: 0.15em;
    font-size: clamp(1.8em, 10vw, 6em);
    white-space: nowrap;
    text-align: center;
}
.title-underline
{
    align-self: center;
    display: block;
    width: min(90%, 600px);
    height: auto;
    margin: 0 0 6px;
}
.title-hex,
.title-tri
{
    display: inline-block;
    width: 0.85em;
    height: 0.85em;
    vertical-align: middle;
    margin: 0 0.02em;
    position: relative;
    top: -0.22em;
}
.title-hex
{
    width: 0.85em;
    height: calc(0.85em * 0.866);
    background: var(--color-blue);
    clip-path: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
    transform: rotate(90deg);
}
.title-tri
{
    background: var(--color-orange);
    clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
.menu
{
    align-self: center;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 32px;
    width: min(80vw, 480px);
}
.mode-buttons
{
    display: flex;
    gap: 16px;
    width: 100%;
}
.mode-buttons button
{
    flex: 1;
    min-height: 44px;
    padding: 16px 28px;
    border-radius: 0;
    background: transparent;
    cursor: pointer;
    font-size: 1.15em;
    font-weight: bold;
    font-family: inherit;
    transition: background-color 0.2s, color 0.2s;
}
#btn-friend
{
    border: 2px solid var(--color-blue);
    color: var(--color-blue);
}
#btn-ai
{
    border: 2px solid var(--color-orange);
    color: var(--color-orange);
}
#btn-friend.selected
{
    background: var(--color-blue);
    color: white;
}
#btn-ai.selected
{
    background: var(--color-orange);
    color: white;
}
.difficulty-buttons button
{
    min-height: 44px;
    padding: 12px 24px;
    border: 2px solid var(--color-orange);
    border-radius: 0;
    background: transparent;
    color: var(--color-orange);
    cursor: pointer;
    font-size: 1.1em;
    font-family: inherit;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
#difficulty-section
{
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    font-size: 1.1em;
}
#difficulty-section.visible
{
    display: flex;
}
#difficulty-section p
{
    margin: 0;
    color: black;
}
.difficulty-buttons
{
    display: flex;
    gap: 12px;
}
.difficulty-buttons button.selected
{
    background: var(--color-orange);
    border-color: var(--color-orange);
    color: white;
}
#btn-play-again
{
    min-height: 44px;
    padding: 12px 36px;
    font-size: 1.1em;
    font-weight: bold;
    font-family: inherit;
    border: 2px solid black;
    border-radius: 0;
    background: transparent;
    color: black;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
#btn-play-again:hover
{
    background: black;
    color: white;
}
#btn-back-menu,
#btn-restart
{
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    box-sizing: border-box;
    width: 160px;
    height: 76px;
    padding: 12px 8px;
    font-size: 1.1em;
    font-weight: bold;
    font-family: inherit;
    background: transparent;
    color: black;
    border: 2px solid black;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
#btn-back-menu:hover,
#btn-restart:hover
{
    background: black;
    color: white;
}
#btn-close-rules
{
    display: block;
    margin: 24px auto 0;
    padding: 18px 44px;
    font-size: 1.35em;
    font-weight: bold;
    font-family: inherit;
    background: transparent;
    color: black;
    border: 2px solid black;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
#btn-close-rules:hover
{
    background: black;
    color: white;
}
#start-screen #btn-start,
#start-screen #btn-rules
{
    width: 100%;
    box-sizing: border-box;
    padding: 18px 44px;
    font-size: 1.35em;
    font-weight: bold;
    font-family: inherit;
    background: transparent;
    color: black;
    border: 2px solid black;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
#start-screen #btn-start:not(:disabled):hover,
#start-screen #btn-start:not(:disabled):active,
#start-screen #btn-rules:hover
{
    background: black;
    color: white;
}
#start-screen #btn-start:disabled
{
    background: transparent;
    color: #999;
    border-color: #999;
    cursor: not-allowed;
}
#winner-message
{
    font-size: 2em;
    font-weight: bold;
    margin: 0;
}
#game-container
{
    display: flex;
    align-items: flex-start;
    justify-content: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 150px;
}
#board-wrapper
{
    position: relative;
}
#board-grid
{
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}
#board-grid [role="gridcell"]
{
    position: absolute;
    margin: 0;
    padding: 0;
    background: none;
    border: none;
}
#board-grid [role="gridcell"]:focus
{
    outline: 3px solid #1a1a1a;
    outline-offset: -3px;
}
#board-grid.wall-mode [role="gridcell"]:focus
{
    outline: none;
}
.panel-column
{
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    gap: 8px;
}
#player1-panel,
#player2-panel
{
    width: 160px;
    flex-shrink: 0;
    background-color: #d8d8d8;
    border-radius: 0;
    padding: 16px;
    box-sizing: border-box;
    transition: background-color 0.3s ease;
}
#player1-panel.active
{
    background-color: var(--color-blue-light);
}
#player2-panel.active
{
    background-color: var(--color-orange-light);
}
#status
{
    margin-top: 12px;
    font-size: 1em;
    width: 100%;
    text-align: center;
}
#status-underline
{
    margin: 0 auto 6px;
}
#wall-error
{
    margin-top: 6px;
    font-size: 0.9em;
    color: #cc3333;
    opacity: 0;
    transition: opacity 0.3s ease;
    min-height: 1.2em;
}
#wall-error.visible
{
    opacity: 1;
}
.player-shape-canvas
{
    display: block;
    margin: 4px auto 8px;
}
.wall-count-number
{
    font-size: 6em;
    font-weight: normal;
    text-align: center;
    margin: 4px 0 0;
}
.wall-count-label
{
    font-size: 1em;
    text-align: center;
    color: black;
    margin: 0 0 6px;
}
.wall-btn-group
{
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 24px;
}
.wall-btn-group button
{
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
    padding: 14px 4px;
    border-width: 2px;
    border-style: solid;
    border-radius: 0;
    background: white;
    cursor: pointer;
    font-size: 1.1em;
    font-weight: bold;
    font-family: inherit;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
#player1-panel .wall-btn-group button
{
    border-color: var(--color-blue);
    color: var(--color-blue);
}
#player2-panel .wall-btn-group button
{
    border-color: var(--color-orange);
    color: var(--color-orange);
}
.wall-btn-group button:disabled
{
    opacity: 0.4;
    cursor: not-allowed;
}
.wall-icon
{
    display: block;
    background: currentColor;
    border-radius: 0;
}
.wall-h-btn .wall-icon
{
    width: 34px;
    height: 6px;
}
.wall-v-btn .wall-icon
{
    width: 6px;
    height: 34px;
}
#player1-panel .wall-btn-group button.active-mode
{
    background: var(--color-blue);
    color: white;
}
#player2-panel .wall-btn-group button.active-mode
{
    background: var(--color-orange);
    color: white;
}
.moves-to-win-number
{
    font-size: 4em;
    font-weight: normal;
    text-align: center;
    margin: 24px 0 0;
}
.moves-to-win-label
{
    font-size: 1em;
    text-align: center;
    color: black;
    margin: 0 0 2px;
}
.trophy-icon
{
    display: block;
    width: 60px;
    height: 60px;
    margin: 28px auto 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.trophy-icon.visible
{
    opacity: 1;
}
#rules-modal
{
    border-radius: 0;
    text-align: left;
    width: 90vw;
    max-width: 480px;
}
#rules-modal section p
{
    font-size: 1.15em;
}
#rules-title
{
    text-align: center;
    text-transform: uppercase;
    font-size: 2.2em;
}

/* Mobile breakpoint: reflow only - stack the panels above/below the board
   (matching DOM order: player1 panel, board, player2 panel) instead of
   squeezing a 3-column layout into a narrow viewport. Every element keeps
   its normal fixed size here; only its position in the layout changes. */
@media (max-width: 600px)
{
    #game-container
    {
        flex-direction: column;
        align-items: center;
    }
    .mode-buttons
    {
        flex-direction: column;
    }
}
