/* =================================
   1. General Styles & Variables
   ================================= */
:root {
    --bg-main: #FFF8F0;
    --bg-content: #FFFDF9;
    --header-bg: #E53935;
    --button-bg: #43A047;
    --button-hover: #388E3C;
    --text-dark: #3E2723;
    --text-light: #FFFFFF;
    --border-color: #E8DDD0;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
    /* Lv.99-inspired Red/Green/Beige palette */
    --primary-red: #D84315;
    --primary-red-dark: #BF360C;
    --primary-red-light: #FFCDD2;
    --accent-green: #43A047;
    --accent-green-hover: #388E3C;
    --beige: #FFF8F0;
    --beige-dark: #F5EDE3;
    --bg-white: #FFFDF9;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', 'Arial', 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-dark);
    margin: 0;
    padding: 0;
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Login page specific background */
body.login-page {
    background: linear-gradient(135deg, #FFF3E0 0%, #F5EDE3 50%, #FFE0B2 100%);
}

/* App pages background */
body:not(.login-page) {
    background: linear-gradient(135deg, #FFF3E0 0%, #F5EDE3 50%, #FFE0B2 100%);
}

/* =================================
   2. Main Containers
   ================================= */
#app-view {
    width: 95%;
    max-width: 1600px;
    margin: 2rem auto;
    padding: 0;
    background: var(--bg-content);
    border-radius: 24px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.12);
    box-sizing: border-box;
    min-height: calc(100vh - 4rem);
    align-self: stretch;
    overflow: hidden;
    animation: slideUp 0.6s ease-out;
}

/* =================================
   3. Header
   ================================= */
header {
    background: linear-gradient(135deg, #D84315 0%, #E64A19 100%);
    color: var(--text-light);
    padding: 1.5rem 2.5rem;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.header-logo-container { 
    height: 50px; 
    flex-shrink: 0; 
}
.header-logo-container img { 
    height: 100%; 
    width: auto; 
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.2));
}

.header-center { 
    flex: 1;
    min-width: 200px;
    text-align: center; 
}
.header-center p { 
    margin: 0.25rem 0; 
    font-size: 0.95rem; 
    white-space: nowrap;
}
.header-center p:first-child {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}
.page-level { 
    font-size: 0.9rem; 
    opacity: 0.95; 
    margin: 0.25rem 0;
}
.page-level strong { 
    color: #fff; 
    font-size: 1rem;
}
.timer-wrapper { 
    font-size: 0.85rem; 
    opacity: 0.9; 
    margin: 0.25rem 0;
}
#timer-display { 
    font-weight: bold; 
    background-color: rgba(0,0,0,0.25); 
    padding: 0.4rem 1rem; 
    border-radius: 20px; 
    display: inline-block;
    font-family: 'Courier New', monospace;
    letter-spacing: 1px;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-shrink: 0;
}

#logout-button,
#level-switcher-btn {
    background-color: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.4);
    color: var(--text-light);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.65rem 1.4rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
#logout-button:hover,
#level-switcher-btn:hover { 
    background-color: rgba(255,255,255,0.3); 
    border-color: rgba(255,255,255,0.6);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* Header tab switcher styles */
.header-tab-switcher {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.header-tab-switcher .tab-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.3);
    color: var(--text-light);
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.header-tab-switcher .tab-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.header-tab-switcher .tab-btn.active {
    background: rgba(255,255,255,0.35);
    border-color: rgba(255,255,255,0.6);
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.header-tab-switcher .tab-btn:disabled {
    background: rgba(255,255,255,0.08);
    border-color: rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.35);
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
    transform: none;
}

/* =================================
   4. Login Form - Modern Split-Screen Design
   ================================= */
#login-view {
    max-width: 900px;
    width: 95%;
    margin: 2rem auto;
    border-radius: 24px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.12);
    background: var(--bg-white);
    overflow: hidden;
    display: grid;
    grid-template-columns: 2fr 3fr;
    grid-template-rows: 1fr;
    grid-auto-flow: column;
    min-height: 550px;
    animation: slideUp 0.6s ease-out;
}

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

/* =================================
   Left Panel - Decorative
   ================================= */
.login-left-panel {
    background: linear-gradient(135deg, #D84315 0%, #E64A19 100%);
    padding: 3rem 2rem;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    grid-column: 1;
    grid-row: 1;
}

.floating-elements {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.float-letter {
    position: absolute;
    font-size: 3rem;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.3);
    animation: float 6s ease-in-out infinite;
}

.float-star {
    position: absolute;
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.4);
    animation: twinkle 3s ease-in-out infinite;
}

.float-cloud {
    position: absolute;
    font-size: 2.5rem;
    color: rgba(255, 255, 255, 0.2);
    animation: float 8s ease-in-out infinite;
}

.float-book {
    position: absolute;
    font-size: 2rem;
    animation: float 7s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translateY(0px);
    }
    50% {
        transform: translateY(-20px);
    }
}

@keyframes twinkle {
    0%, 100% {
        opacity: 0.4;
        transform: scale(1);
    }
    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

.mascot-container {
    position: relative;
    z-index: 2;
    text-align: center;
}

.mascot-wave {
    width: 180px;
    height: auto;
    filter: drop-shadow(0 8px 16px rgba(0,0,0,0.2));
    animation: wave 2s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% {
        transform: rotate(0deg);
    }
    25% {
        transform: rotate(-5deg);
    }
    75% {
        transform: rotate(5deg);
    }
}

/* =================================
   Right Panel - Form
   ================================= */
.login-right-panel {
    padding: 3rem 2.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    background: var(--beige);
    grid-column: 2;
    grid-row: 1;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 2.5rem;
    background: linear-gradient(135deg, var(--primary-red) 0%, var(--primary-red-dark) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.login-subtitle {
    font-size: 0.95rem;
    color: #666;
    font-weight: 400;
}

/* =================================
   Form Styles
   ================================= */
#login-form {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-dark);
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 1rem;
    font-size: 1.2rem;
    pointer-events: none;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    padding: 1rem 1rem 1rem 3rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: #FFFDF9;
}

input[type="text"]:hover,
input[type="email"]:hover,
input[type="password"]:hover {
    border-color: #c0c0c0;
    background: #fff;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-red);
    box-shadow: 0 0 0 4px rgba(229, 57, 53, 0.1);
    background: #fff;
}

input::placeholder {
    color: #999;
}

/* =================================
   Button Styles
   ================================= */
.login-submit-btn {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, var(--accent-green) 0%, var(--accent-green-hover) 100%);
    color: var(--text-light);
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 0.5rem;
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.3);
    position: relative;
    overflow: hidden;
}

.login-submit-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}

.login-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
}

.login-submit-btn:hover::before {
    left: 100%;
}

.login-submit-btn:active {
    transform: translateY(0);
}

.login-submit-btn span {
    position: relative;
    z-index: 1;
}

/* =================================
   Error Message
   ================================= */
.error-message {
    color: #d32f2f;
    text-align: center;
    margin-top: 1rem;
    font-weight: 500;
    padding: 0.75rem 1rem;
    background: #ffebee;
    border-radius: 8px;
    font-size: 0.9rem;
    border: 1px solid #ffcdd2;
    animation: slideDown 0.3s ease-out;
}

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

.error-message:empty {
    display: none;
}

/* =================================
   5. Main Content Layout
   ================================= */
.main-content-grid {
    display: grid;
    grid-template-columns: minmax(380px, 500px) minmax(600px, 800px);
    gap: 2.5rem;
    align-items: start;
    padding: 2rem 2.5rem;
    justify-content: center;
}

.instructions-panel {
    background: var(--beige);
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    backdrop-filter: blur(10px);
}

.instructions-panel h2 {
    font-size: 1.25rem;
    color: var(--text-dark);
    margin-bottom: 1rem;
    margin-top: 0;
    font-weight: 600;
}
.instructions-panel h2:not(:first-child) { 
    margin-top: 1.5rem; 
}

.instructions-list {
    padding-left: 1.5rem;
    margin: 0 0 1.5rem 0;
}
.instructions-list li {
    margin-bottom: 0.75rem;
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-dark);
}

.instructions-panel p {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text-dark);
    margin-bottom: 1rem;
}

.hint-text {
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-dark);
    margin-bottom: 1rem;
}

#app-content {
    display: flex;
    border: none;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    background: #fff;
    min-height: 500px;
    height: 600px;
    max-height: 700px;
}

#app-content iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* =================================
   6. Overlays & Fixed Elements
   ================================= */
#time-up-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.85);
    display: none; justify-content: center; align-items: center;
    text-align: center; z-index: 1000;
}
.overlay-content { 
    padding: 3rem; 
    background: var(--bg-white); 
    border-radius: 24px; 
    max-width: 500px; 
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: slideUp 0.6s ease-out;
    color: var(--text-dark);
}
.overlay-content h2 {
    color: var(--text-dark);
    margin-bottom: 1rem;
}

#level-selection-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.85);
    display: none; justify-content: center; align-items: center;
    z-index: 1000;
}
.level-selection-content {
    padding: 3rem; 
    background: var(--bg-content); 
    border-radius: 24px;
    max-width: 600px; 
    text-align: center; 
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: slideUp 0.6s ease-out;
}
.level-selection-content h2 {
    margin-top: 0; margin-bottom: 2rem; color: var(--text-dark);
    font-size: 2rem;
}
.level-buttons {
    display: flex; flex-direction: column; gap: 1.5rem;
}
.level-btn {
    padding: 1.5rem 2rem; 
    background: linear-gradient(135deg, var(--accent-green) 0%, var(--accent-green-hover) 100%);
    color: var(--text-light); 
    border: none; 
    border-radius: 12px;
    font-size: 1.3rem; 
    font-weight: bold; 
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 20px rgba(76, 175, 80, 0.3);
    position: relative;
    overflow: hidden;
}
.level-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.5s;
}
.level-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(76, 175, 80, 0.4);
}
.level-btn:hover::before {
    left: 100%;
}
.level-btn:active { 
    transform: translateY(0);
}

#level-switcher-btn {
    background-color: transparent;
    border: 2px solid rgba(255,255,255,0.8);
    color: var(--text-light);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.65rem 1.4rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}
#level-switcher-btn:hover {
    background-color: var(--text-light);
    color: var(--primary-red);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

#fixed-corner-logo {
    position: fixed; bottom: 25px; right: 25px;
    z-index: 1001; opacity: 0.8; transition: opacity 0.3s;
}
#fixed-corner-logo:hover { opacity: 1; }
#fixed-corner-logo img { height: 45px; width: auto; display: block; }

/* =================================
   7. Responsive Design
   ================================= */
@media (max-width: 1400px) {
    .main-content-grid {
        grid-template-columns: minmax(350px, 450px) minmax(550px, 700px);
        gap: 2rem;
        padding: 1.5rem 2rem;
    }
}

@media (max-width: 1200px) {
    .main-content-grid {
        grid-template-columns: minmax(320px, 400px) minmax(500px, 1fr);
        gap: 1.5rem;
        padding: 1.5rem 2rem;
    }
    #app-content {
        height: 550px;
        max-height: 600px;
    }
}

@media (max-width: 1024px) {
    .main-content-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
        padding: 1.5rem;
    }
    .instructions-panel {
        position: relative;
        top: 0;
        max-height: none;
    }
    #app-content {
        min-height: 60vh;
    }
}

@media (max-width: 768px) {
    body { padding: 0; }
    body {
        align-items: flex-start;
    }
    #app-view {
        width: 100%;
        border-radius: 0;
        padding: 0;
        min-height: 100vh;
    }
    #login-view {
        grid-template-columns: 2fr 3fr;
        grid-template-rows: 1fr;
        margin: 1rem;
        min-height: auto;
        max-width: 100%;
    }
    
    .login-left-panel {
        padding: 2rem 1.5rem;
        min-height: 200px;
        grid-column: 1;
        grid-row: 1;
    }
    
    .mascot-wave {
        width: 120px;
    }
    
    .login-right-panel {
        padding: 2rem 1.5rem;
        grid-column: 2;
        grid-row: 1;
    }
    
    .login-header h1 {
        font-size: 2rem;
    }
    
    .float-letter {
        font-size: 2rem;
    }
    header {
        flex-direction: column;
        gap: 1rem;
        padding: 1.25rem 1.5rem;
    }
    .header-center {
        width: 100%;
        order: 2;
    }
    .header-tab-switcher {
        width: 100%;
        order: 3;
        justify-content: center;
    }
    .header-logo-container {
        order: 1;
    }
    .header-actions {
        order: 4;
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }
    .main-content-grid { 
        gap: 1.5rem; 
        padding: 1.25rem;
    }
    .instructions-panel {
        padding: 1.5rem;
    }
    #app-content {
        min-height: 450px;
        height: 500px;
        max-height: none;
    }
}

@media (max-width: 480px) {
    #login-view {
        grid-template-columns: 2fr 3fr;
        grid-template-rows: 1fr;
        margin: 0.5rem;
        width: calc(100% - 1rem);
    }
    
    .login-left-panel {
        padding: 1.5rem 1rem;
        grid-column: 1;
        grid-row: 1;
    }
    
    .login-right-panel {
        padding: 1.5rem 1rem;
        grid-column: 2;
        grid-row: 1;
    }
    
    .login-header h1 {
        font-size: 1.75rem;
    }
    
    .login-submit-btn {
        font-size: 1rem;
        padding: 0.875rem 1.5rem;
    }
    
    .mascot-wave {
        width: 100px;
    }
    
    .float-letter {
        font-size: 1.5rem;
    }
}