:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #ec4899;
    --bg-color: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --danger: #ef4444;
    --success: #10b981;
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    color: var(--text-main);
    background-color: var(--bg-color);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* Background Animation */
.background-animation {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 50% 50%, #312e81 0%, #0f172a 40%),
                radial-gradient(circle at 80% 20%, #831843 0%, transparent 40%);
    animation: rotateBg 30s linear infinite;
    z-index: -1;
}

@keyframes rotateBg {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.app-container {
    width: 100%;
    max-width: 500px;
    min-height: 600px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    overflow: hidden;
}

.screen {
    display: none;
    flex-direction: column;
    align-items: center;
    height: 100%;
    animation: fadeIn 0.4s ease-out forwards;
}

.screen.active {
    display: flex;
}

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

/* Typography & Utilities */
.title {
    font-size: 3rem;
    font-weight: 900;
    margin-bottom: 0.5rem;
    text-align: center;
}

.gradient-text {
    background: linear-gradient(135deg, #a855f7, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-muted);
    margin-bottom: 3rem;
    text-align: center;
}

/* Buttons */
.primary-btn {
    background: linear-gradient(135deg, var(--primary-color), #8b5cf6);
    color: white;
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
    margin-bottom: 2rem;
}

.primary-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.primary-btn:active {
    transform: translateY(1px);
}

/* Rules */
.rules {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 1.5rem;
    width: 100%;
}

.rules h3 {
    margin-bottom: 1rem;
    font-size: 1.2rem;
    color: #cbd5e1;
}

.rules ul {
    list-style-position: inside;
    color: var(--text-muted);
    line-height: 1.6;
    font-size: 0.95rem;
}

/* Game Screen */
.header {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--glass-border);
}

.score-container, .timer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.score-container span:first-child, .timer-container span:first-child {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.2rem;
}

#score-display {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--success);
}

#timer-display {
    font-size: 1.8rem;
    font-weight: 800;
    transition: color 0.3s ease;
}

.time-normal { color: white; }
.time-warning { color: #fbbf24; }
.time-danger { color: var(--danger); animation: pulse 1s infinite; }

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

.game-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.target-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 2.5rem;
}

.current-kana {
    font-size: 5rem;
    font-weight: 900;
    background: linear-gradient(135deg, #fde047, #f97316);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 15px rgba(249, 115, 22, 0.4));
}

.target-length {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1.2rem;
    color: var(--text-muted);
}

#target-length-num {
    font-size: 4rem;
    font-weight: 900;
    color: var(--text-main);
    line-height: 1;
}

.input-area {
    width: 100%;
    position: relative;
    margin-bottom: 2rem;
}

#word-form {
    display: flex;
    position: relative;
}

#word-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid var(--glass-border);
    border-radius: 12px;
    padding: 1.2rem 4rem 1.2rem 1.5rem;
    font-size: 1.5rem;
    color: white;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
}

#word-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.3);
    background: rgba(255, 255, 255, 0.1);
}

.submit-btn {
    position: absolute;
    right: 8px;
    top: 8px;
    bottom: 8px;
    width: 48px;
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}

.submit-btn:hover {
    background: var(--primary-hover);
}

.message {
    text-align: center;
    min-height: 1.5rem;
    margin-top: 0.5rem;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--danger);
    opacity: 0;
    transition: opacity 0.3s;
}

.message.show {
    opacity: 1;
}

.history-area {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    max-height: 150px;
    overflow-y: auto;
    padding-right: 5px;
}

.history-area::-webkit-scrollbar {
    width: 6px;
}

.history-area::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.history-area::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 3px;
}

.history-word {
    background: rgba(255, 255, 255, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.9rem;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Result Screen */
.result-title {
    font-size: 2.5rem;
    color: var(--danger);
    margin-bottom: 1rem;
    margin-top: 2rem;
}

.result-reason {
    font-size: 1.2rem;
    color: var(--text-muted);
    margin-bottom: 3rem;
    text-align: center;
}

.final-score {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 4rem;
}

.final-score span {
    font-size: 1.2rem;
    color: var(--text-muted);
}

#final-score-display {
    font-size: 5rem;
    font-weight: 900;
    line-height: 1;
    margin-top: 0.5rem;
}

/* Loading Overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 10;
    border-radius: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.overlay.hidden {
    display: none;
}

.overlay.active {
    opacity: 1;
    pointer-events: all;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .app-container {
        width: 95%;
        height: 95vh;
        border-radius: 16px;
    }
    
    .current-kana {
        font-size: 4rem;
    }
    
    #target-length-num {
        font-size: 3rem;
    }
}

.mode-selection {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

#multiplayer-setup {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}

.peer-info {
    margin-bottom: 15px;
    text-align: left;
}

.peer-id-text {
    font-size: 1.2rem;
    color: #4a90e2;
    background: rgba(255,255,255,0.8);
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 2px;
}

.small-text {
    font-size: 0.8rem;
    color: #666;
    margin-top: 5px;
}

.join-room {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

#join-peer-id {
    flex: 1;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 8px;
    font-size: 1rem;
    outline: none;
}

.status-msg {
    font-size: 0.9rem;
    color: #ff3b30;
    margin-bottom: 10px;
    min-height: 1.5em;
}

.text-btn {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.9rem;
}

.text-btn:hover {
    color: #333;
}

.secondary-btn {
    width: 100%;
    padding: 15px;
    border: 2px solid var(--primary-color);
    border-radius: 12px;
    background: transparent;
    color: var(--primary-color);
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

.secondary-btn:hover {
    background: rgba(74, 144, 226, 0.1);
}

.turn-indicator {
    text-align: center;
    font-weight: bold;
    padding: 8px;
    margin: 10px 0;
    border-radius: 8px;
    background: rgba(74, 144, 226, 0.1);
    color: var(--primary-color);
    animation: pulse 2s infinite;
}

.turn-indicator.opponent-turn {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
    animation: none;
}


.timers {
    display: flex;
    gap: 15px;
}

.timer-label {
    font-size: 0.8rem;
    margin-right: 5px;
}

.opponent-last-word {
    text-align: center;
    font-size: 1.1rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 15px;
    color: #333;
    font-weight: bold;
    border: 1px dashed rgba(255, 255, 255, 0.5);
    animation: fadeIn 0.3s ease;
}

#opponent-last-word {
    color: var(--primary-color);
    font-size: 1.3rem;
    margin-left: 10px;
}


.game-settings {
    margin-bottom: 20px;
    background: rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 12px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#initial-time-input {
    width: 80px;
    padding: 5px;
    border-radius: 4px;
    border: none;
    text-align: center;
    font-size: 1.1rem;
}


.hidden {
    display: none !important;
}

