/* /pages/puzzle/puzzle.css 
   BULDR.IO */

/*  BASE STYLES (all modes) */
:root {
  --tile-size: 0px;      /* JS sets this */
  --tile-scale: 1;       /* 1 for builder + landscape source, 1.3 for portrait source */
  --tile-space: 0px;     /* JS sets this: tile-size * space */
}

/* --- TILE --- */
.tile {
    width: calc(var(--tile-size) * var(--tile-scale));
    height: calc(var(--tile-size) * var(--tile-scale));
    display: grid;
    place-items: center;
    background: var(--button);
    border: calc(var(--tile-size) * var(--tile-scale) * 0.08) solid var(--line);
    border-radius: calc(var(--tile-size) * var(--tile-scale) * 0.1);
    box-sizing: border-box;
    font-family: "JetBrains Mono", monospace;
    font-weight: 700;
    font-size: calc(var(--tile-size) * var(--tile-scale) * 0.55);   
    margin-right: var(--tile-space);
} 

.tile.available {
    border-color: var(--highlight1);
    color: var(--highlight1);
}

.tile.taken {
    opacity: 0.55;
}

.tile.cursor {
    border-color: var(--highlight2);
    border-style: dashed;
}

.tile.kbd-selected {
    outline: calc(0.06 * var(--tile-size)) solid var(--highlight1);
    outline-offset: calc(0.06 * var(--tile-size));
    transform: scale(1.05);
}

.tile.kbd-selected::after {
    content: "⏎";
    position: absolute;
    top: calc(-0.16 * var(--tile-size));
    right: calc(-0.16 * var(--tile-size));
    background: var(--highlight1);
    color: black;
    font-size: calc(0.25 * var(--tile-size));
    padding: calc(0.08 * var(--tile-size));
    border-radius: calc(0.10 * var(--tile-size));
}

.source-row,
.builder-row {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: calc(var(--tile-size) * var(--tile-scale));
    column-gap: var(--tile-space);
    padding-left: var(--tile-space);
    padding-right: var(--tile-space);
}

.puzzle-btn {
    height: calc(1.2 * var(--tile-size));
    min-width: calc(1.5 * var(--tile-size));
    padding: 0 calc(0.2 * var(--tile-size));
    border-radius: 5%;
    border: calc(0.06 * var(--tile-size)) solid var(--line);
    background: var(--button);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease-in-out, filter 0.2s ease-in-out;
}

.puzzle-btn:disabled {
    cursor: default;
    opacity: 0.4;
    filter: grayscale(60%);
}

.builder-actions {
    display: flex;
    justify-content: center;
    gap: calc(0.3 * var(--tile-size));
    padding: calc(0.2 * var(--tile-size)) 0;
}

/* --- PUZZLE ICONS --- */
.game-title {
    position: relative;
    width: 100%;
    padding: calc(0.2 * var(--tile-size)) 0;
}

.game-title-text {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: calc(0.45 * var(--tile-size));
    white-space: nowrap;
    pointer-events: none;
}

.puzzle-icons {
    position: absolute;
    /* right: calc(0.5 * var(--tile-size)); */
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    gap: calc(0.25 * var(--tile-size));
    z-index: 200;
}

.icon {
    position: relative;
    width: calc(0.7 * var(--tile-size));
    height: calc(0.7 * var(--tile-size));
    border-radius: 15%;
    border: calc(0.06 * var(--tile-size)) solid var(--line);
    background: var(--button);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.icon:hover {
    opacity: 1;
}

.tooltip {
    position: absolute;
    top: calc(100% + 0.1 * var(--tile-size));
    right: 0;
    background: var(--panel);
    border: calc(0.06 * var(--tile-size)) solid var(--line);
    padding: calc(0.2 * var(--tile-size)) calc(0.3 * var(--tile-size));
    border-radius: calc(0.15 * var(--tile-size));
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.icon:hover .tooltip {
    opacity: 1;
}

/* Shake main score */
@keyframes scoreshake-kf {
  0%   { transform: translate(-50%, -50%) scale(1); }
  20%  { transform: translate(-50%, -50%) scale(1.3); }
  40%  { transform: translate(-50%, -50%) scale(1); }
  50%  { transform: translate(-50%, -50%) scale(1.2); }
  60%  { transform: translate(-50%, -50%) scale(1); }
  80%  { transform: translate(-50%, -50%) scale(1.1); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

.score-shake {
  animation: scoreshake-kf 1.5s ease-out;
}

/* Float +N above score */
@keyframes scorefloat-kf {
  0%   { opacity: 1; 
         transform: translateY(0%); }

  100% { opacity: 0; 
         transform: translateY(-15vh); }
}

#score-float {
  position: fixed;
  pointer-events: none;
  aspect-ratio: 1;
  width: calc( var(--tile-size) * 0.5 );
  opacity: 0;
  font-size: calc( var(--tile-size) * 0.3 );
  font-weight: 700;
  color: var(--text);
  background: #b0b000;
  border-radius: 50%;
  display: flex;
    align-items: center;
    justify-content: center;

}

#score-float.active {
  opacity: 1;
  animation: scorefloat-kf 2s ease-out;
}

#animation-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999; /* above everything */
}

/* ================================================
   PORTRAIT (max-aspect-ratio: 3/4)
   Header / Game-panel / Score-bar / Footer
============================================== */
.PORTRAIT .source-row {
        --tile-scale: 1.3;
    }

.PORTRAIT html, .PORTRAIT body {
        height: 100%;
        overflow: hidden;
        overscroll-behavior: none;
    }

.PORTRAIT #client-area {
        container-type: inline-size;
        display: grid;
        grid-template-rows: 10vh 1fr;
        grid-template-areas:
            "header"
            "content";
    }

.PORTRAIT #b-bottom-bar {
        display: none;
    }

.PORTRAIT .theme-icon {
        width: 5cqw;
        height: 5cqw;
    }

.PORTRAIT .puzzle-container {
        display: grid;
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }

    /* Game panel — full width */
.PORTRAIT .game-panel {
        order:-1;
        container-type: inline-size;
        display: flex;
        flex-direction: column;
        align-items: center;
        min-height: 0;
        padding: 4cqw;
        gap: 4cqw;
    }
    
.PORTRAIT .icon-kbd {
        display: none;
    }

.PORTRAIT .icon.active {
        opacity: 1;
        z-index: 30;
    }

.PORTRAIT .icon.active .tooltip {
    display: block;
}

/* ================================================
   LANDSCAPE SHARED (aspect >= 3/4)
   4:3 camera area — internals use cqw from camera
============================================== */

.LANDSCAPE #client-area {
    display: grid;
    grid-template-rows: 20% 75% 5%;
    grid-template-areas:
        "header"
        "content"
        "footer";
    position: relative;
}

.LANDSCAPE .puzzle-container {
        display: grid;
        grid-template-columns: 30% 1fr;
        gap: 1cqw;
        width: 100%;
        max-width: none;
    }

.LANDSCAPE .game-panel {
        container-type: inline-size;
        display: flex;
        flex-direction: column;
        align-items: center;
        box-sizing: border-box;
        border-radius: 1cqw;
        border: 0.3vw solid var(--line, magenta);
        min-height: 0;
        padding: 2cqw;
        gap: 3cqw;
        height: 100%;
        background: var(--panel);
    }

.LANDSCAPE .puzzle-btn {
        cursor: pointer;
    }

.LANDSCAPE .puzzle-btn:hover:not(:disabled) {
        filter: brightness(1.15);
    }

.LANDSCAPE .tile.available {
        cursor: pointer;
        position: relative;
        transition: transform 0.12s ease, filter 0.12s ease;
    }

.LANDSCAPE .tile.available:hover {
    transform: translateY(calc(-0.06 * var(--tile-size)));
    filter: brightness(1.15);
}
/* css for #score-panel */

/* --- BASE DEFINITIONS --- */

#score-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--panel); 
    box-sizing: border-box;
}

#score-panel .score-inner {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#score-panel .score-header {
    font-weight: 700;
    text-transform: uppercase;
}

#score-panel .score-scroll {
    flex: 1 1 0;
    height: 0;
    min-height: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    scrollbar-width: auto;
    scrollbar-color: var(--line, magenta) var(--panel, #1a1a1a);
    padding: 1cqw;
    border: 0.3cqw solid var(--line);
    background: var(--button);
    position: relative;
}

#score-panel .score-words {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5cqw;
    align-content: start;
}

#score-panel .score-word {
    text-transform: uppercase; 
}

#score-panel .score-footer {
    margin-top: auto;
    padding-top: 0.5cqw;
    border-top: 0.2cqw solid var(--line, magenta);
}

#score-panel .score-scroll-nav {
        position: relative;
        flex: 1 1 0;
        min-height: 0;
        display: flex;
        flex-direction: column;
}

/* --- PROGRESS BAR --- */

#score-panel .progress-wrapper {
    position: relative;
    width: 100%;
    padding: 0.8cqw 0;
    box-sizing: border-box;
}

#score-panel .progress-bg {
    width: 100%;
    background: #3cb371;
    border-radius: 999px;
    position: relative;
}

#score-panel .progress-fg {
    position: absolute;
    top: 50%;
    left: 0.5cqw;
    background:  #b0b000;
    border-radius: 999px;
    transform: translateY(-50%);
    width: 0%;
    max-width: calc(100% - 1cqw);
    transition: width 0.4s ease;
}

#score-panel .progress-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    white-space: nowrap;
    font-weight: 700;
}
/* END BASE DEFINITIONS */

/* ================================================
          PORTRAIT (max-aspect-ratio: 3/4)
   ============================================== */

@media (max-aspect-ratio: 3/4) {
    #score-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 55vh;
        padding: 2cqw;
        border: 0.4cqw solid var(--line);
        border-radius: 1cqw 1cqw 0 0;
        z-index: 50;
        --peek: 13vh;
        transform: translateY(calc(100% - var(--peek)));
        transition: transform 0.3s ease;
        cursor: pointer;
    }
    
    #score-panel.open {
        transform: translateY(0);
    }

    #score-panel .score-inner {
        display: flex;
        flex-direction: column;
        gap: 0.5cqw;
        height: 100%;
    }

    #score-panel .score-scroll {
        position: relative;
        transform: none;
        pointer-events: auto;
        flex: 1 1 0;
        min-height: 0;
        overflow-y: auto;
        background: var(--button);
        border: 0.4cqw solid var(--line);
        border-radius: 1cqw;
        padding: 0.5cqw;
        scrollbar-width: none;
        overscroll-behavior: contain;
    }

    #score-panel .scroll-hint {
        position: absolute;
        inset-block-end: 0; /* logical bottom */
        left: 0;
        right: 0;

        height: 6vw;
        line-height: 6vw;
        font-size: 4vw;

        text-align: center;
        color: rgba(255,255,255,0.85);

        background: linear-gradient(
            to bottom,
            transparent,
            rgba(0,0,0,0.35)
        );

        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    #score-panel .score-header {
        white-space: nowrap;
    }

    #score-panel .score-footer {
        white-space: nowrap;
    }

    #score-panel .score-word {
        padding: 1vw 1.5vw;
    }

    #score-panel .progress-wrapper {
        width: 100%;
        padding: 0.5cqw 0;
    }

    #score-panel .progress-bg {
        height: 8cqw;
    }

    #score-panel .progress-fg {
        height: 4cqw;
        left: 1cqw;
        max-width: calc(100% - 2cqw);
    }

} /* END PORTRAIT (max-aspect-ratio: 3/4) */

/* ================================================
          LANDSCAPE (min-aspect-ratio: 4/3)
   ============================================== */
@media (min-aspect-ratio: 3/4) {
    #score-panel {
        height: 100%;
        min-height: 0;
        padding: 2cqw;
        border: 0.4cqw solid var(--line, magenta);
        border-radius: 1cqw;
        gap: 1.5cqw;
    }

    #score-panel .score-inner {
        gap: 1cqw;
    }

    #score-panel .progress-bg {
        height: 2cqw;
    }

    #score-panel .progress-fg {
        height: 1.1cqw;
    }
}