/* =================== TICTAKTIKER =================== */
/* TicTaktiker (c) Volker Heitz 2026
 * Game look only. Page layout (panel size, board sizing) lives in the host CSS.
 * Colour tokens (--orange, --dark, ...) must be defined by the host page.
 */

.tt-game {
    position: relative;            /* anchor for .tt-menu */
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--off-white);
    font-family: var(--font-mono);
}

.tt-status,
.tt-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    width: 100%;
    max-width: 800px;
    min-height: 2.4rem;
    font-size: clamp(0.65rem, 1.5vh, 0.9rem);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.tt-target            { color: var(--grey); }
.tt-msg               { color: var(--orange-light); }
.tt-controls .tt-msg  { flex: 1; }

/* Stage: wrapper the host can size; centres the square board. */
.tt-stage {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}

/* --tt-n (board edge length) is set by the script. */
.tt-board {
    container-type: inline-size;   /* lets cells size glyphs via cqw */
    display: grid;
    grid-template-columns: repeat(var(--tt-n, 3), 1fr);
    grid-template-rows: repeat(var(--tt-n, 3), 1fr);
    gap: 3px;
    width: 100%;
    max-width: 560px;
    aspect-ratio: 1;
    padding: 3px;
    background: var(--mid);
    border: 1px solid var(--orange);
}

.tt-cell {
    min-width: 0;
    min-height: 0;
    padding: 0;
    border: 0;
    background: var(--dark);
    color: var(--off-white);
    font-family: var(--font-mono);
    font-size: calc(55cqw / var(--tt-n, 3));
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
}

.tt-cell:not(:disabled):hover,
.tt-cell:focus-visible {
    background: var(--dark3);
    outline: 1px solid var(--orange-light);
}

.tt-cell:disabled { cursor: default; }

.tt-p0 { color: var(--orange); }
.tt-p1 { color: var(--white); }

/* Image pieces (option `pieces`): host CSS sets background per .tt-p0/.tt-p1 */
.tt-piece {
    display: block;
    width: 86%;
    aspect-ratio: 1;
    margin: auto;
    background-repeat: no-repeat;
    pointer-events: none;
}

.tt-cell.tt-line {
    background: rgba(232, 97, 10, 0.18);
    box-shadow: inset 0 0 0 1px var(--orange);
}

.tt-cell.tt-ring { animation: tt-ring-in 0.5s ease-out; }

/* Last placed mark: blinks 3x, then keeps two faint corner brackets */
.tt-cell.tt-last {
    position: relative;
    animation: tt-last-blink 0.32s step-end 3;
}

.tt-cell.tt-last::before,
.tt-cell.tt-last::after {
    content: '';
    position: absolute;
    width: 22%;
    height: 22%;
    border: 0 solid var(--orange-light);
    opacity: 0.55;
    pointer-events: none;
}
.tt-cell.tt-last::before { top: 4px;    left: 4px;  border-top-width: 2px;    border-left-width: 2px; }
.tt-cell.tt-last::after  { bottom: 4px; right: 4px; border-bottom-width: 2px; border-right-width: 2px; }

@keyframes tt-last-blink {
    50% { opacity: 0.15; }
}

@keyframes tt-ring-in {
    from { background: var(--orange-dim); }
    to   { background: var(--dark); }
}

/* CPU is thinking: block input */
.tt-busy .tt-board { cursor: progress; }
.tt-busy .tt-cell  { pointer-events: none; }

.tt-new,
.tt-cpu {
    padding: 0.45rem clamp(0.55rem, 1.4vw, 1rem);
    border: 1px solid var(--orange);
    background: transparent;
    color: var(--orange);
    font-family: var(--font-mono);
    font-size: clamp(0.62rem, 1.4vh, 0.82rem);
    letter-spacing: 0.08em;
    cursor: pointer;
}

.tt-new:hover,
.tt-cpu:hover,
.tt-new:focus-visible,
.tt-cpu:focus-visible {
    background: var(--orange);
    color: var(--black);
    outline: none;
}

/* Game over: overlay on the board with restart button (fades in after the winning row is shown) */
.tt-stage { position: relative; }

.tt-over-box {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.82);
    backdrop-filter: blur(2px);
    text-align: center;
    animation: tt-over-in 0.6s ease-out 0.9s both;
}

.tt-over-box[hidden] { display: none; }

.tt-over-title {
    color: var(--orange);
    font-size: clamp(1.6rem, 5vh, 3rem);
    font-weight: 700;
    letter-spacing: 0.18em;
    text-shadow: 0 0 18px rgba(232, 97, 10, 0.6);
}

.tt-over-winner {
    font-size: clamp(0.8rem, 2vh, 1.1rem);
    letter-spacing: 0.12em;
}

.tt-over-box .tt-restart {
    padding: 0.7rem 1.6rem;
    font-size: clamp(0.8rem, 1.8vh, 1rem);
}

@keyframes tt-over-in {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

/* Context menu (option `contextMenu`); positioned by the script inside .tt-game */
.tt-menu {
    position: absolute;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.4rem;
    background: var(--dark);
    border: 1px solid var(--orange);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.7);
}

.tt-menu[hidden] { display: none; }
.tt-menu button  { width: 100%; text-align: left; }

@media (max-width: 520px) {
    .tt-status,
    .tt-controls { gap: 0.45rem; font-size: 0.62rem; }
}

@media (prefers-reduced-motion: reduce) {
    .tt-cell.tt-ring { animation: none; }
}
