/* Focused real-device presentation fixes tracked in GitHub Issue #13. */

#rotate-notice {
    pointer-events: none;
}

.start-mode-card-bot:hover,
.start-mode-card-bot:focus-within {
    border-color: rgba(247, 214, 142, 0.68);
    outline: 2px solid rgba(245, 206, 129, 0.62);
    outline-offset: 2px;
    transform: translateY(-1px);
}

.start-mode-card-action:hover,
.start-mode-card-action:focus-visible {
    border-color: transparent;
    outline: none;
    transform: none;
}

#fullscreen-container {
    display: grid;
    grid-template-columns: repeat(3, minmax(44px, 1fr));
    gap: 8px;
}

#fullscreen-toggle,
#point-numbers-toggle,
#haptic-toggle {
    width: 100%;
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid rgba(222, 177, 95, 0.46);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(86, 35, 34, 0.95) 0%, rgba(57, 21, 20, 0.96) 100%);
    color: #f8e8c8;
    box-shadow: inset 0 1px 0 rgba(255, 224, 198, 0.2), 0 6px 12px rgba(0, 0, 0, 0.28);
    cursor: pointer;
    font-weight: 700;
    line-height: 1.1;
}

#fullscreen-toggle:hover,
#fullscreen-toggle:focus-visible,
#point-numbers-toggle:hover,
#point-numbers-toggle:focus-visible,
#haptic-toggle:hover,
#haptic-toggle:focus-visible {
    border-color: rgba(248, 208, 121, 0.7);
    background: linear-gradient(180deg, rgba(107, 47, 45, 0.95) 0%, rgba(70, 29, 28, 0.96) 100%);
    outline: 2px solid rgba(248, 208, 121, 0.68);
    outline-offset: 2px;
}

#fullscreen-toggle.is-active,
#point-numbers-toggle.is-active,
#haptic-toggle.is-active {
    border-color: rgba(223, 203, 132, 0.68);
    background: linear-gradient(180deg, rgba(66, 84, 34, 0.96) 0%, rgba(42, 52, 24, 0.97) 100%);
}

.fullscreen-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.point-numbers-toggle-icon {
    min-width: 25px;
    font-size: 0.76rem;
    font-weight: 900;
    letter-spacing: -0.08em;
    line-height: 1;
}

.haptic-toggle-icon {
    font-size: 1rem;
    line-height: 1;
}

#auto-bearoff-container {
    position: relative;
    display: block;
    min-height: 44px;
}

#auto-bearoff-container:has(#auto-turn-confirm-toggle:checked) {
    min-height: 60px;
}

#auto-bearoff-container:has(#auto-bearoff-help[open]) {
    grid-column: 1 / -1;
    min-height: 146px;
    padding-bottom: 86px;
}

#auto-bearoff-heading {
    min-height: 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

#auto-bearoff-container:has(#auto-bearoff-help[open]) #auto-bearoff-heading,
#auto-bearoff-container:has(#auto-turn-confirm-toggle:checked) #auto-bearoff-heading {
    min-height: 42px;
}

#auto-bearoff-help {
    position: static;
    flex: 0 0 auto;
}

#auto-bearoff-help summary {
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(236, 189, 97, 0.45);
    border-radius: 50%;
    background: rgba(73, 42, 22, 0.86);
    color: #ffe1a0;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 900;
    list-style: none;
}

#auto-bearoff-help summary::-webkit-details-marker {
    display: none;
}

#auto-bearoff-help summary:hover,
#auto-bearoff-help summary:focus-visible {
    border-color: #ffd575;
    outline: 2px solid rgba(248, 208, 121, 0.6);
    outline-offset: 2px;
}

#auto-bearoff-hint {
    position: absolute;
    z-index: 40;
    right: 0;
    left: 0;
    top: 56px;
    width: auto;
    box-sizing: border-box;
    min-height: 0;
    margin: 0;
    padding: 9px 10px;
    border: 1px solid rgba(236, 189, 97, 0.48);
    border-radius: 9px;
    background: rgba(35, 18, 10, 0.98);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.4);
    color: rgba(244, 220, 164, 0.92);
    font-size: 0.72rem;
    line-height: 1.3;
}

@media (width: 430px) and (height: 932px) and (orientation: portrait) {
    #auto-bearoff-container {
        min-height: 46px;
    }

    #auto-bearoff-container:has(#auto-turn-confirm-toggle:checked) {
        min-height: 62px;
    }
}

@media (max-width: 600px) and (orientation: portrait) {
    body {
        height: auto;
        min-height: 100dvh;
        overflow-y: auto;
    }

    #game-container {
        grid-template-rows: auto auto;
        max-height: none;
    }

    #info-panel {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto;
        align-content: start;
    }

    #info-panel > #turn-indicator {
        grid-area: auto;
        order: 0;
    }

    #panel-controls {
        order: 1;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas:
            "timer dice"
            "bearoff bearoff"
            "bot language"
            "theme theme"
            "display display";
        gap: 6px;
    }

    #panel-controls:has(#auto-bearoff-help[open]) {
        grid-template-areas:
            "timer dice"
            "bearoff bearoff"
            "bot language"
            "theme theme"
            "display display";
    }

    #timer-container {
        grid-area: timer;
    }

    #dice-container {
        grid-area: dice;
        justify-self: stretch;
        align-self: stretch;
        margin-left: 0;
    }

    #difficulty-container {
        grid-area: bot;
    }

    #language-container {
        grid-area: language;
    }

    #theme-container {
        grid-area: theme;
    }

    #auto-bearoff-container {
        grid-area: bearoff;
        min-width: 0;
        padding: 6px 8px;
    }

    #auto-bearoff-container:has(#auto-bearoff-help[open]) {
        min-height: 146px;
        padding-bottom: 86px;
    }

    #auto-bearoff-heading {
        position: relative;
        min-width: 0;
        padding-right: 0;
    }

    #auto-bearoff-label {
        flex: 1 1 auto;
        min-width: 0;
        gap: 6px;
        font-size: 0.78rem;
        line-height: 1.15;
    }

    #auto-turn-confirm-label {
        min-width: 0;
        gap: 6px;
        font-size: 0.78rem;
        line-height: 1.15;
    }

    #auto-bearoff-help {
        position: static;
        transform: none;
    }

    #auto-bearoff-help summary {
        position: static;
        z-index: 3;
        transform: none;
        width: 24px;
        height: 24px;
    }

    #auto-bearoff-hint {
        right: 0;
        left: 0;
        top: 54px;
    }

    #fullscreen-container {
        grid-area: display;
        min-height: 44px;
        padding: 4px;
    }

    #difficulty-container,
    #language-container,
    #theme-container {
        padding: 4px 6px;
    }

    #bot-difficulty,
    #language-select,
    #theme-select {
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        max-width: 100%;
    }
}

/* Physical iPhone Safari: keep the board and controls adjacent in the
   reduced visual viewport left by browser chrome. */
@media (max-height: 600px) and (orientation: landscape) {
    html,
    body {
        width: 100%;
        height: 100dvh;
        min-height: 100dvh;
        overflow: hidden;
    }

    body {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    #game-container {
        --mobile-panel-width: clamp(190px, 39vw, 300px);
        display: grid;
        grid-template-columns: minmax(0, 1fr) var(--mobile-panel-width);
        grid-template-rows: minmax(0, 1fr);
        grid-template-areas: "board info";
        width: min(
            100%,
            calc(
                133.333dvh -
                16px +
                var(--mobile-panel-width) +
                6px
            )
        );
        height: calc(100dvh - 8px);
        max-height: calc(100dvh - 8px);
        padding: 4px;
        gap: 6px;
        align-items: stretch;
    }

    #board-wrapper {
        grid-area: board;
        width: 100%;
        max-width: 100%;
        max-height: 100%;
        align-self: center;
        justify-self: end;
    }

    #game-canvas {
        width: 100%;
        max-width: 100%;
        max-height: calc(100dvh - 16px);
        object-fit: contain;
    }

    #info-panel {
        grid-area: info;
        width: 100%;
        height: 100%;
        min-width: 0;
        padding: 6px;
        gap: 5px;
        align-content: start;
        overflow: hidden;
    }

    #info-panel:has(#auto-bearoff-help[open]) {
        overflow-y: auto;
    }

    #info-panel > #turn-indicator {
        grid-area: auto;
        min-height: 30px;
    }

    #panel-controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-areas:
            "bot language"
            "theme theme"
            "bearoff bearoff"
            "display display"
            "timer dice";
        gap: 5px;
        align-content: start;
    }

    #difficulty-container {
        grid-area: bot;
    }

    #language-container {
        grid-area: language;
    }

    #theme-container {
        grid-area: theme;
    }

    #auto-bearoff-container {
        grid-area: bearoff;
    }

    #fullscreen-container {
        grid-area: display;
    }

    #timer-container {
        grid-area: timer;
    }

    #dice-container {
        grid-area: dice;
        justify-self: stretch;
        align-self: stretch;
        margin-left: 0;
    }

    #difficulty-container,
    #language-container,
    #theme-container,
    #auto-bearoff-container,
    #fullscreen-container,
    #timer-container,
    #dice-container {
        width: 100%;
        min-width: 0;
        min-height: 38px;
        padding: 4px 6px;
    }

    #bot-difficulty,
    #language-select,
    #theme-select {
        flex: 1 1 auto;
        width: auto;
        min-width: 0;
        max-width: 100%;
        min-height: 34px;
        padding: 3px 5px;
        font-size: 0.72rem;
    }

    #auto-bearoff-label,
    #auto-turn-confirm-label {
        min-width: 0;
        font-size: 0.76rem;
    }

    #fullscreen-toggle,
    #point-numbers-toggle,
    #haptic-toggle {
        min-height: 36px;
        padding: 5px 8px;
    }

    #timer-container .timer-title {
        margin-bottom: 3px;
        font-size: 0.62rem;
    }

    .die {
        width: 34px;
        height: 34px;
        min-width: 34px;
    }
}

@media (min-width: 901px) and (max-height: 900px) {
    #auto-bearoff-container {
        min-height: 44px;
    }

    #auto-bearoff-container:has(#auto-turn-confirm-toggle:checked) {
        min-height: 60px;
    }
}
