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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
    padding: 20px;
    color: #333;
    overflow-x: hidden;
    position: relative;
}

#canvas-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    transition: background 2s ease;
}

#canvas-container.menu-colors { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
#canvas-container.story-colors { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
#canvas-container.playing-colors { background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%); }
#canvas-container.result-colors { background: linear-gradient(135deg, #fa709a 0%, #fee140 100%); }

.container {
    max-width: 900px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    padding: 40px;
    box-shadow: 0 30px 80px rgba(0,0,0,0.3);
    border: 1px solid rgba(255, 255, 255, 0.5);
    animation: fadeIn 0.6s ease-out;
}

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

h1 {
    text-align: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 3.5em;
    margin-bottom: 10px;
    font-weight: 800;
}

.subtitle {
    text-align: center;
    color: #764ba2;
    font-size: 1.3em;
    margin-bottom: 30px;
    font-weight: 500;
}

.mode-selection, .story-selection, .game-area, .result-area {
    display: none;
    animation: slideIn 0.4s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.mode-selection.active, .story-selection.active, .game-area.active, .result-area.active {
    display: block;
}

.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 18px 35px;
    font-size: 1.1em;
    border-radius: 15px;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s ease;
    font-weight: 600;
    box-shadow: 0 10px 25px rgba(102, 126, 234, 0.3);
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 15px 35px rgba(102, 126, 234, 0.4);
}

.mode-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    align-items: center;
}

.loading {
    text-align: center;
    color: #667eea;
    font-size: 1.6em;
    padding: 50px;
    font-weight: 600;
}

.error {
    background: rgba(255, 235, 235, 0.95);
    border: 2px solid #ff8888;
    padding: 25px;
    border-radius: 15px;
    color: #cc3333;
    margin: 25px 0;
}

.story-list {
    max-height: 450px;
    overflow-y: auto;
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-radius: 15px;
    padding: 20px;
    margin: 25px 0;
    background: rgba(255, 255, 255, 0.5);
}

.story-item {
    padding: 20px;
    margin: 15px 0;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.story-item:hover {
    border-color: #667eea;
    transform: translateX(8px);
}

.story-item-title {
    font-weight: 700;
    color: #667eea;
    font-size: 1.3em;
}

.button-group {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
    margin-top: 25px;
}

.input-group {
    margin: 25px 0;
}

.input-group label {
    display: block;
    font-size: 1.4em;
    color: #667eea;
    margin-bottom: 15px;
    font-weight: 700;
}

.input-group input {
    width: 100%;
    padding: 18px;
    font-size: 1.2em;
    border: 3px solid #667eea;
    border-radius: 15px;
    outline: none;
}

.typing-preview {
    min-height: 60px;
    padding: 15px;
    margin-top: 15px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 12px;
    border: 2px dashed rgba(102, 126, 234, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8em;
    font-weight: 700;
    color: #667eea;
}

.typing-preview.empty {
    color: rgba(102, 126, 234, 0.3);
    font-style: italic;
    font-size: 1.2em;
}

.typing-char {
    display: inline-block;
    animation: charBounce 0.5s ease-out;
}

@keyframes charBounce {
    0% { transform: translateY(-20px) scale(0.5); opacity: 0; }
    50% { transform: translateY(-10px) scale(1.2); }
    70% { transform: translateY(5px) scale(0.9); }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.sparkle {
    position: fixed;
    pointer-events: none;
    z-index: 1500;
    font-size: 2em;
    animation: sparkleBurst 1s ease-out forwards;
}

@keyframes sparkleBurst {
    0% { transform: translate(0, 0) scale(0); opacity: 1; }
    100% { transform: translate(var(--tx), var(--ty)) scale(0); opacity: 0; }
}

.story-result {
    background: rgba(102, 126, 234, 0.1);
    padding: 35px;
    border-radius: 20px;
    font-size: 1.4em;
    line-height: 2;
    margin: 25px 0;
    border: 3px solid rgba(102, 126, 234, 0.3);
}

.story-result .blank {
    color: #764ba2;
    font-weight: 800;
    text-decoration: underline;
}

.confetti {
    position: fixed;
    width: 10px;
    height: 10px;
    pointer-events: none;
    z-index: 1000;
    animation: confettiFall linear forwards;
}

.confetti.square { background: var(--color); }
.confetti.circle { background: var(--color); border-radius: 50%; }

@keyframes confettiFall {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
    100% { transform: translate(var(--x), var(--y)) rotate(var(--rotation)); opacity: 0; }
}

.player-badge {
    display: inline-block;
    padding: 8px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 25px;
    font-size: 1.1em;
    font-weight: 700;
    margin: 15px auto;
    text-align: center;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.player-setup {
    background: rgba(248, 249, 250, 0.95);
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-radius: 15px;
    padding: 25px;
    margin: 25px 0;
    text-align: center;
}

.player-setup h3 {
    color: #667eea;
    margin-bottom: 15px;
}

.player-setup input {
    width: 80%;
    max-width: 300px;
    padding: 12px;
    font-size: 1.1em;
    border: 2px solid #667eea;
    border-radius: 10px;
    margin: 10px 0;
}

.player-list {
    margin: 20px 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.player-chip {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-weight: 600;
}

.timer-display {
    text-align: center;
    font-size: 3em;
    font-weight: 800;
    margin: 20px 0;
    color: #667eea;
}

.timer-display.warning { color: #fa709a; }
.timer-display.danger { color: #ff4444; animation: timerPulse 0.3s ease-in-out infinite; }

@keyframes timerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.time-bar {
    width: 100%;
    height: 10px;
    background: rgba(102, 126, 234, 0.2);
    border-radius: 10px;
    overflow: hidden;
    margin: 15px 0;
}

.time-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #43e97b 0%, #667eea 50%, #fa709a 100%);
    transition: width 0.1s linear;
    border-radius: 10px;
}

.difficulty-selector {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin: 25px 0;
    flex-wrap: wrap;
}

.difficulty-btn {
    background: white;
    border: 3px solid #667eea;
    color: #667eea;
    padding: 15px 30px;
    border-radius: 15px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.difficulty-btn:hover {
    background: #667eea;
    color: white;
    transform: translateY(-3px);
}

.difficulty-btn.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #764ba2;
}

.competitive-stories {
    display: grid;
    gap: 25px;
    margin: 25px 0;
}

.competitive-story-card {
    background: rgba(102, 126, 234, 0.1);
    border: 3px solid rgba(102, 126, 234, 0.3);
    border-radius: 20px;
    padding: 25px;
    transition: all 0.3s ease;
}

.competitive-story-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 40px rgba(102, 126, 234, 0.2);
}

.competitive-story-card.winner {
    border-color: #fee140;
    background: rgba(254, 225, 64, 0.2);
    box-shadow: 0 10px 40px rgba(254, 225, 64, 0.4);
}

.competitive-player-name {
    font-size: 1.5em;
    font-weight: 700;
    color: #667eea;
    margin-bottom: 15px;
}

.competitive-story-text {
    font-size: 1.2em;
    line-height: 1.8;
    margin: 15px 0;
}

.vote-btn {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    color: white;
    border: none;
    padding: 12px 25px;
    font-size: 1em;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
}

.vote-btn:hover {
    transform: translateY(-2px);
}

.vote-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.vote-count {
    font-size: 1.3em;
    font-weight: 700;
    color: #764ba2;
    margin-top: 10px;
}

.winner-badge {
    display: inline-block;
    background: linear-gradient(135deg, #fee140 0%, #fa709a 100%);
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 1.2em;
    font-weight: 700;
    margin: 10px 0;
    animation: winnerPulse 1.5s ease-in-out infinite;
}

@keyframes winnerPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}