/**
 * games.css - Mini-Games Styling fuer IHK-Lernapp
 *
 * Spiele:
 * - Snake (Canvas 20x20)
 * - Memory (DOM 6x6, Flip-Animation)
 * - TicTacToe (DOM 3x3)
 * - ConnectFour (DOM 7x6, Gravity)
 *
 * Design-Tokens aus base.css verwendet
 *
 * Version: 2.12.0
 * AZAV-Referenz: §2 AZAV Nr. 3, 4 (Methoden, Ausstattung)
 */

/* ═══════════════════════════════════════════════════════════════════════════════
   CSS VARIABLES (Games-spezifisch)
   ═══════════════════════════════════════════════════════════════════════════════ */

:root {
    /* Game Colors */
    --game-bg: #1e293b;
    --game-surface: #334155;
    --game-border: #475569;
    --game-accent: #3b82f6;
    --game-success: #22c55e;
    --game-warning: #eab308;
    --game-error: #ef4444;

    /* Player Colors */
    --player-color: #eab308;      /* Gelb */
    --ai-color: #ef4444;          /* Rot */

    /* Snake Colors */
    --snake-head: #22c55e;
    --snake-body: #16a34a;
    --snake-food: #ef4444;

    /* Memory Colors */
    --memory-card-bg: #3b82f6;
    --memory-card-front: #1e293b;
    --memory-card-matched: #22c55e;

    /* Grid */
    --game-gap: 4px;
    --game-radius: 8px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   GAME CONTAINER (Gemeinsam)
   ═══════════════════════════════════════════════════════════════════════════════ */

.game-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 1rem;
    background: var(--game-bg);
    border-radius: var(--game-radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.game-status {
    text-align: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: #f1f5f9;
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
}

.game-score {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
    font-size: 0.9rem;
    color: #94a3b8;
}

.game-score strong {
    color: #f1f5f9;
    font-size: 1.1rem;
}

/* Game Controls Hint (Tastatur-Hinweis) */
.game-controls-hint {
    text-align: center;
    font-size: 0.85rem;
    color: #94a3b8;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   SNAKE GAME (Canvas)
   ═══════════════════════════════════════════════════════════════════════════════ */

.snake-canvas {
    display: block;
    margin: 0 auto;
    background: #0f172a;
    border: 2px solid var(--game-border);
    border-radius: var(--game-radius);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.snake-controls {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* Touch Controls (Mobile) */
.snake-touch-controls {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (max-width: 768px) {
    .snake-touch-controls {
        display: flex;
    }
}

.snake-touch-row {
    display: flex;
    gap: 0.5rem;
}

.snake-touch-btn {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    background: var(--game-surface);
    border: 2px solid var(--game-border);
    border-radius: var(--game-radius);
    color: #f1f5f9;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.snake-touch-btn:active {
    background: var(--game-accent);
    transform: scale(0.95);
}

/* ═══════════════════════════════════════════════════════════════════════════════
   MEMORY GAME (6x6 Grid)
   ═══════════════════════════════════════════════════════════════════════════════ */

.memory-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: var(--game-gap);
    padding: 0.5rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
}

@media (max-width: 480px) {
    .memory-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 2px;
    }
}

.memory-card {
    aspect-ratio: 1;
    min-width: 60px;
    min-height: 60px;
    perspective: 1000px;
    cursor: pointer;
}

.memory-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease;
    transform-style: preserve-3d;
}

.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
    transform: rotateY(180deg);
}

.memory-card-front,
.memory-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

@media (max-width: 480px) {
    .memory-card-front,
    .memory-card-back {
        font-size: 1.2rem;
    }
}

.memory-card-back {
    background: linear-gradient(135deg, var(--memory-card-bg), #2563eb);
    color: white;
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.2);
}

.memory-card-back::before {
    content: '?';
    font-size: 1.8rem;
    font-weight: bold;
    opacity: 0.5;
}

.memory-card-front {
    background: var(--memory-card-front);
    transform: rotateY(180deg);
    border: 2px solid var(--game-border);
}

.memory-card.matched .memory-card-front {
    background: var(--memory-card-matched);
    border-color: var(--memory-card-matched);
}

.memory-card.matched .memory-card-inner {
    animation: matchPulse 0.5s ease;
}

@keyframes matchPulse {
    0%, 100% { transform: rotateY(180deg) scale(1); }
    50% { transform: rotateY(180deg) scale(1.1); }
}

/* Memory Stats */
.memory-stats {
    display: flex;
    justify-content: space-around;
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
}

.memory-stat {
    text-align: center;
}

.memory-stat-label {
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: uppercase;
}

.memory-stat-value {
    font-size: 1.25rem;
    font-weight: bold;
    color: #f1f5f9;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   TIC TAC TOE (3x3 Grid)
   ═══════════════════════════════════════════════════════════════════════════════ */

/* TicTacToe Header (Score + Runde) */
.game-header,
.ttt-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
    font-size: 0.95rem;
    font-weight: 600;
    color: #f1f5f9;
}

.ttt-header span {
    flex: 1;
    text-align: center;
}

.ttt-header span:first-child {
    text-align: left;
    color: var(--player-color);
}

.ttt-header span:last-child {
    text-align: right;
    color: var(--ai-color);
}

.ttt-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 300px;
    min-width: 280px;
    margin: 0 auto;
    padding: 1rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
}

.ttt-cell {
    aspect-ratio: 1;
    min-width: 80px;
    min-height: 80px;
    background: var(--game-bg);
    border: 2px solid var(--game-border);
    border-radius: var(--game-radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #f1f5f9;
}

.ttt-cell:hover:not(.occupied) {
    background: var(--game-accent);
    border-color: var(--game-accent);
}

.ttt-cell.occupied {
    cursor: default;
}

.ttt-cell.player {
    color: var(--player-color);
}

.ttt-cell.ai {
    color: var(--ai-color);
}

.ttt-cell.winning {
    animation: winPulse 0.5s ease infinite alternate;
    background: rgba(34, 197, 94, 0.2);
    border-color: var(--game-success);
}

@keyframes winPulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

/* TicTacToe Scoreboard */
.ttt-scoreboard {
    display: flex;
    justify-content: space-around;
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: var(--game-surface);
    border-radius: var(--game-radius);
}

.ttt-score-item {
    text-align: center;
}

.ttt-score-label {
    font-size: 0.75rem;
    color: #94a3b8;
    text-transform: uppercase;
}

.ttt-score-value {
    font-size: 1.5rem;
    font-weight: bold;
}

.ttt-score-value.player {
    color: var(--player-color);
}

.ttt-score-value.ai {
    color: var(--ai-color);
}

.ttt-score-value.draws {
    color: #94a3b8;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   CONNECT FOUR (7x6 Grid)
   ═══════════════════════════════════════════════════════════════════════════════ */

.c4-buttons {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 0.5rem;
}

.c4-drop-btn {
    width: 45px;
    height: 35px;
    background: var(--game-accent);
    border: none;
    border-radius: 6px 6px 0 0;
    color: white;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.c4-drop-btn:hover:not(:disabled) {
    background: #2563eb;
    transform: translateY(-3px);
}

.c4-drop-btn:disabled,
.c4-drop-btn.disabled {
    background: var(--game-border);
    cursor: not-allowed;
    opacity: 0.5;
}

.c4-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: 1fr;
    gap: 4px;
    padding: 0.75rem;
    background: linear-gradient(180deg, #1e40af, #1e3a8a);
    border-radius: var(--game-radius);
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.3);
    max-width: 350px;
    margin: 0 auto;
}

.c4-cell {
    aspect-ratio: 1;
    min-width: 40px;
    min-height: 40px;
    background: var(--game-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.3);
}

.c4-disc {
    width: 85%;
    height: 85%;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.c4-disc.player {
    background: radial-gradient(circle at 30% 30%, #fde047, var(--player-color));
    box-shadow: 0 3px 8px rgba(234, 179, 8, 0.5);
}

.c4-disc.ai {
    background: radial-gradient(circle at 30% 30%, #f87171, var(--ai-color));
    box-shadow: 0 3px 8px rgba(239, 68, 68, 0.5);
}

/* Drop Animation */
@keyframes discDrop {
    0% {
        transform: translateY(-300px);
        opacity: 0;
    }
    60% {
        transform: translateY(10px);
    }
    80% {
        transform: translateY(-5px);
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.c4-disc.dropping {
    animation: discDrop 0.5s ease-out forwards;
}

/* Winning Animation */
.c4-cell.winning .c4-disc {
    animation: winBlink 0.5s ease infinite alternate;
}

@keyframes winBlink {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0.7; transform: scale(1.1); }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   GAME BUTTONS (Gemeinsam)
   ═══════════════════════════════════════════════════════════════════════════════ */

.game-btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--game-radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

.game-btn-primary {
    background: var(--game-accent);
    color: white;
}

.game-btn-primary:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.game-btn-secondary {
    background: var(--game-surface);
    color: #f1f5f9;
    border: 1px solid var(--game-border);
}

.game-btn-secondary:hover {
    background: var(--game-border);
}

.game-btn-success {
    background: var(--game-success);
    color: white;
}

.game-btn-success:hover {
    background: #16a34a;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   GAME MENU (Auswahl)
   ═══════════════════════════════════════════════════════════════════════════════ */

.game-menu {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    padding: 1rem;
}

@media (max-width: 400px) {
    .game-menu {
        grid-template-columns: 1fr;
    }
}

.game-menu-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 1rem;
    background: var(--game-surface);
    border: 2px solid var(--game-border);
    border-radius: var(--game-radius);
    cursor: pointer;
    transition: all 0.2s ease;
}

.game-menu-item:hover {
    background: var(--game-bg);
    border-color: var(--game-accent);
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.game-menu-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.game-menu-title {
    font-size: 1rem;
    font-weight: 600;
    color: #f1f5f9;
}

.game-menu-desc {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 0.25rem;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   GAME OVER OVERLAY
   ═══════════════════════════════════════════════════════════════════════════════ */

.game-over-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: var(--game-radius);
    z-index: 100;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.game-over-title {
    font-size: 2rem;
    font-weight: bold;
    color: #f1f5f9;
    margin-bottom: 0.5rem;
}

.game-over-title.win {
    color: var(--game-success);
}

.game-over-title.lose {
    color: var(--game-error);
}

.game-over-score {
    font-size: 1.25rem;
    color: #94a3b8;
    margin-bottom: 1.5rem;
}

.game-over-buttons {
    display: flex;
    gap: 1rem;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   PREMIUM MODAL (Spiel waehrend Warten)
   ═══════════════════════════════════════════════════════════════════════════════ */

.premium-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 1rem;
}

.premium-modal.hidden {
    display: none;
}

.premium-modal-content {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--game-bg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.premium-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--game-border);
}

.premium-modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #f1f5f9;
}

.premium-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #94a3b8;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.premium-modal-close:hover {
    color: #f1f5f9;
}

.premium-modal-body {
    padding: 1.5rem;
}

/* Progress Ring */
.premium-progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}

.premium-progress-ring {
    position: relative;
    width: 120px;
    height: 120px;
}

.premium-progress-ring svg {
    transform: rotate(-90deg);
}

.premium-progress-ring circle {
    fill: none;
    stroke-width: 8;
}

.premium-progress-ring .bg {
    stroke: var(--game-surface);
}

.premium-progress-ring .progress {
    stroke: var(--game-accent);
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s ease;
}

.premium-progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.premium-progress-percent {
    font-size: 1.5rem;
    font-weight: bold;
    color: #f1f5f9;
}

.premium-progress-eta {
    font-size: 0.85rem;
    color: #94a3b8;
}

.premium-progress-status {
    margin-top: 0.75rem;
    font-size: 0.9rem;
    color: #94a3b8;
    text-align: center;
}

/* Game Selector in Modal */
.premium-game-selector {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.premium-game-btn {
    padding: 0.5rem 1rem;
    background: var(--game-surface);
    border: 2px solid var(--game-border);
    border-radius: var(--game-radius);
    color: #f1f5f9;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.premium-game-btn:hover {
    border-color: var(--game-accent);
}

.premium-game-btn.active {
    background: var(--game-accent);
    border-color: var(--game-accent);
}

.premium-game-container {
    position: relative;
    min-height: 350px;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   IT-AFFINITAET ANZEIGE
   ═══════════════════════════════════════════════════════════════════════════════ */

.it-affinity-card {
    background: var(--game-surface);
    border-radius: var(--game-radius);
    padding: 1.25rem;
    margin-top: 1rem;
}

.it-affinity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.it-affinity-title {
    font-size: 1rem;
    font-weight: 600;
    color: #f1f5f9;
}

.it-affinity-score {
    font-size: 1.5rem;
    font-weight: bold;
}

.it-affinity-score.high {
    color: var(--game-success);
}

.it-affinity-score.medium {
    color: var(--game-warning);
}

.it-affinity-score.low {
    color: var(--game-error);
}

.it-affinity-indicators {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

@media (max-width: 480px) {
    .it-affinity-indicators {
        grid-template-columns: repeat(2, 1fr);
    }
}

.it-affinity-indicator {
    text-align: center;
}

.it-affinity-indicator-label {
    font-size: 0.7rem;
    color: #94a3b8;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
}

.it-affinity-indicator-bar {
    height: 4px;
    background: var(--game-bg);
    border-radius: 2px;
    overflow: hidden;
}

.it-affinity-indicator-fill {
    height: 100%;
    background: var(--game-accent);
    transition: width 0.5s ease;
}

.it-affinity-indicator-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: #f1f5f9;
    margin-top: 0.25rem;
}

/* ═══════════════════════════════════════════════════════════════════════════════
   RESPONSIVE ANPASSUNGEN
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (max-width: 360px) {
    .game-container {
        padding: 0.5rem;
    }

    .c4-drop-btn {
        width: 38px;
        height: 30px;
        font-size: 1rem;
    }

    .ttt-cell {
        font-size: 2rem;
    }

    .memory-card-front,
    .memory-card-back {
        font-size: 1rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   ANIMATIONEN
   ═══════════════════════════════════════════════════════════════════════════════ */

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

.shake {
    animation: shake 0.3s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.bounce {
    animation: bounce 0.5s ease;
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 5px var(--game-accent); }
    50% { box-shadow: 0 0 20px var(--game-accent); }
}

.glow {
    animation: glow 1s ease infinite;
}
