/* ============================================================
   Geometry Puzzle WebApp – Styles
   ============================================================ */

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --clr-bg:        #0f1117;
    --clr-surface:   #1a1d2e;
    --clr-surface2:  #22263a;
    --clr-border:    #2e3352;
    --clr-accent:    #6c63ff;
    --clr-accent2:   #00c9a7;
    --clr-danger:    #ff4757;
    --clr-warn:      #ffa502;
    --clr-success:   #2ed573;
    --clr-text:      #e8eaf6;
    --clr-text-muted:#8b90b4;
    --radius-lg:     16px;
    --radius-md:     10px;
    --radius-sm:     6px;
    --shadow-glow:   0 0 24px rgba(108,99,255,0.3);
    --transition:    0.22s cubic-bezier(0.4,0,0.2,1);
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--clr-bg);
    color: var(--clr-text);
    overflow: hidden;
}

/* ── App shell ──────────────────────────────────────────── */

.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 12px 8px;
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────── */

.app-header {
    width: 100%;
    max-width: 1100px;
    flex-shrink: 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 0 12px;
    border-bottom: 1px solid var(--clr-border);
    margin-bottom: 12px;
}

.header-title-group {
    flex: 1;
    min-width: 0;
}

.puzzle-title {
    font-size: clamp(1.3rem, 3vw, 2rem);
    font-weight: 700;
    background: linear-gradient(135deg, #a78bfa, var(--clr-accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.puzzle-description {
    margin-top: 6px;
    font-size: 0.9rem;
    color: var(--clr-text-muted);
    line-height: 1.5;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* ── Timer ──────────────────────────────────────────────── */

.timer-display {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(26,29,46,0.9);
    border: 1px solid rgba(108,99,255,0.3);
    border-radius: 8px;
    backdrop-filter: blur(4px);
}
.timer-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #8b90b4;
}
.timer-value {
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: #6c63ff;
    min-width: 54px;
}

/* ── Main content ───────────────────────────────────────── */

.main-content {
    width: 100%;
    max-width: 1100px;
    flex: 1;
    min-height: 0;          /* allow flex child to shrink below content size */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

/* ── Puzzle image + overlay ─────────────────────────────── */

.puzzle-wrapper {
    flex: 1;
    min-height: 0;          /* critical: lets the wrapper shrink */
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.puzzle-image-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 40px rgba(0,0,0,0.6), var(--shadow-glow);
    overflow: hidden;
    background: var(--clr-surface);
    max-width: 100%;
    max-height: 100%;       /* never exceed the wrapper's available height */
    animation: puzzleFadeIn 0.5s ease both;
}

@keyframes puzzleFadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

#puzzle-img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    user-select: none;
}

#overlay-canvas {
    /* Size and position are set entirely by syncCanvasSize() so the canvas
       always matches the displayed image exactly, even when the flex
       container is wider/taller than the image itself.                    */
    position: absolute;
    cursor: pointer;
    touch-action: none;
}

/* ── Instruction text ───────────────────────────────────── */

.select-instruction {
    flex-shrink: 0;
    font-size: 0.9rem;
    color: var(--clr-text-muted);
    text-align: center;
    font-style: italic;
    transition: opacity var(--transition);
}

.select-instruction.hidden {
    opacity: 0;
    pointer-events: none;
}

/* ── Status message ─────────────────────────────────────── */

.status-message {
    flex-shrink: 0;
    padding: 8px 20px;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    animation: slideDown 0.3s ease both;
    min-width: 260px;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.status-message.correct {
    background: rgba(46,213,115,0.15);
    border: 1px solid var(--clr-success);
    color: var(--clr-success);
}

.status-message.wrong {
    background: rgba(255,71,87,0.12);
    border: 1px solid var(--clr-danger);
    color: var(--clr-danger);
    animation: shake 0.4s ease both;
}

.status-message.hint {
    background: rgba(255,165,2,0.12);
    border: 1px solid var(--clr-warn);
    color: var(--clr-warn);
}

.status-message.info {
    background: rgba(108,99,255,0.12);
    border: 1px solid var(--clr-accent);
    color: #c4b5fd;
}

@keyframes shake {
    0%,100% { transform: translateX(0); }
    20%      { transform: translateX(-8px); }
    40%      { transform: translateX(8px); }
    60%      { transform: translateX(-5px); }
    80%      { transform: translateX(5px); }
}

/* ── Buttons ────────────────────────────────────────────── */

.button-group {
    flex-shrink: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform var(--transition), box-shadow var(--transition), filter var(--transition), background var(--transition);
    user-select: none;
    position: relative;
    overflow: hidden;
}

.btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    flex-shrink: 0;
}

.btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0);
    transition: background var(--transition);
}

.btn:hover::after { background: rgba(255,255,255,0.08); }
.btn:active { transform: scale(0.96); }

.btn-primary   { background: var(--clr-accent);  color: #fff; box-shadow: 0 4px 18px rgba(108,99,255,0.45); }
.btn-primary:hover   { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(108,99,255,0.55); }

.btn-info      { background: #0ea5e9; color: #fff; box-shadow: 0 4px 18px rgba(14,165,233,0.4); }
.btn-info:hover      { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(14,165,233,0.5); }

.btn-danger    { background: var(--clr-danger);  color: #fff; box-shadow: 0 4px 18px rgba(255,71,87,0.4); }
.btn-danger:hover    { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(255,71,87,0.5); }

.btn-warning   { background: var(--clr-warn);    color: #1a1a1a; box-shadow: 0 4px 18px rgba(255,165,2,0.4); }
.btn-warning:hover   { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(255,165,2,0.5); }

.btn-success   { background: var(--clr-success); color: #1a1a1a; box-shadow: 0 4px 18px rgba(46,213,115,0.4); }
.btn-success:hover   { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(46,213,115,0.5); }

.btn-secondary { background: var(--clr-surface2); color: var(--clr-text); border: 1px solid var(--clr-border); }
.btn-secondary:hover { transform: translateY(-2px); background: var(--clr-border); }

.btn-icon-only {
    padding: 10px 12px;
}

/* ── Victory overlay ────────────────────────────────────── */

.victory-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: fadeIn 0.3s ease both;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.victory-card {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-lg);
    padding: 48px 56px;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0,0,0,0.7), var(--shadow-glow);
    animation: popIn 0.4s cubic-bezier(0.34,1.56,0.64,1) both;
    max-width: 420px;
    width: 90%;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.75); }
    to   { opacity: 1; transform: scale(1); }
}

.victory-icon {
    font-size: 3.5rem;
    margin-bottom: 12px;
    animation: bounce 1s infinite alternate;
}

@keyframes bounce {
    from { transform: translateY(0); }
    to   { transform: translateY(-10px); }
}

.victory-title {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #a78bfa, var(--clr-accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.victory-message {
    color: var(--clr-text-muted);
    margin-bottom: 6px;
    font-size: 1rem;
}

.victory-time {
    color: var(--clr-accent2);
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 24px;
}

/* ── Confetti ───────────────────────────────────────────── */

.confetti-container {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 101;
    overflow: hidden;
}

.confetti-piece {
    position: absolute;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    animation: confettiFall linear forwards;
}

@keyframes confettiFall {
    0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
    100% { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}

/* ── Timer CSS ──────────────────────────────────────────── */

    .timer-value { font-size: 0.95rem; }

/* ── Responsive ─────────────────────────────────────────── */

@media (max-width: 640px) {
    .app-header {
        flex-direction: column;
        gap: 12px;
    }
    .header-controls {
        width: 100%;
        justify-content: flex-end;
    }
    .btn {
        padding: 9px 16px;
        font-size: 0.85rem;
    }
}
