/* Modern Glassmorphic Game Styling for Keisan 20 */
:root {
    --bg-dark: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.85);
    --card-border: rgba(255, 255, 255, 0.1);
    --primary: #38bdf8;
    --primary-glow: rgba(56, 189, 248, 0.4);
    --accent: #f59e0b;
    --success: #10b981;
    --danger: #ef4444;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: radial-gradient(circle at 50% 10%, #1e293b 0%, #0f172a 100%);
    color: var(--text-main);
    font-family: var(--font-family);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-x: hidden;
    touch-action: manipulation;
}

/* App Container */
.app-container {
    width: 100%;
    max-width: 520px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 16px;
    position: relative;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--card-border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-icon {
    font-size: 1.6rem;
}

.brand-title {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #38bdf8, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 6px 12px;
    border-radius: 9999px;
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* Screen Visibility Controller */
.screen {
    display: none;
    flex-direction: column;
    flex: 1;
    animation: fadeIn 0.25s ease-out;
}

.screen.active {
    display: flex;
}

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

/* ==================== START SCREEN ==================== */
.hero-section {
    text-align: center;
    margin: 24px 0 16px;
}

.hero-title {
    font-size: 2.2rem;
    font-weight: 900;
    letter-spacing: -1px;
    margin-bottom: 6px;
}

.hero-title span {
    color: var(--primary);
    text-shadow: 0 0 20px var(--primary-glow);
}

.hero-subtitle {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.4;
}

.features-banner {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 14px 0 24px;
    flex-wrap: wrap;
}

.feature-tag {
    background: rgba(56, 189, 248, 0.12);
    border: 1px solid rgba(56, 189, 248, 0.3);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 9999px;
}

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

.mode-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(8px);
}

.mode-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 8px 24px -6px var(--primary-glow);
}

.mode-card:active {
    transform: translateY(0);
}

.mode-card.recommended {
    border-color: rgba(56, 189, 248, 0.5);
    background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(56, 189, 248, 0.1));
}

.mode-info h3 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge-rec {
    font-size: 0.68rem;
    background: var(--accent);
    color: #000;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 4px;
}

.mode-info p {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.mode-best {
    text-align: right;
    font-size: 0.8rem;
}

.mode-best-label {
    color: var(--text-muted);
    font-size: 0.7rem;
    margin-bottom: 2px;
}

.mode-best-val {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.95rem;
}

.how-to-play-box {
    background: rgba(255, 255, 255, 0.04);
    border: 1px dashed var(--card-border);
    border-radius: 12px;
    padding: 14px;
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.how-to-play-box strong {
    color: var(--text-main);
}

/* ==================== GAME SCREEN ==================== */
.game-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 8px 0 12px;
}

.progress-container {
    flex: 1;
    margin-right: 16px;
}

.progress-label-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.progress-track {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 5%;
    background: linear-gradient(90deg, #38bdf8, #818cf8);
    border-radius: 9999px;
    transition: width 0.3s ease;
}

.timer-box {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 4px 14px;
    font-size: 1.25rem;
    font-weight: 800;
    font-family: monospace;
    color: var(--primary);
}

/* Question Area */
.question-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 16px 20px;
    text-align: center;
    margin-bottom: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.question-text {
    font-size: 2.8rem;
    font-weight: 900;
    letter-spacing: 1px;
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

/* Canvas Area */
.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 260px;
    background: #020617;
    border: 2px solid rgba(56, 189, 248, 0.35);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 10px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.8), 0 4px 20px rgba(56, 189, 248, 0.15);
}

#drawCanvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

/* Feedback Overlay (Flash on Correct/Wrong) */
.feedback-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    font-weight: 900;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 10;
}

.feedback-overlay.active {
    opacity: 1;
}

.feedback-overlay.correct {
    background: rgba(16, 185, 129, 0.25);
    color: #10b981;
    text-shadow: 0 0 30px #10b981;
}

.feedback-overlay.wrong {
    background: rgba(239, 68, 68, 0.25);
    color: #ef4444;
    text-shadow: 0 0 30px #ef4444;
}

/* Recognition Live Status Bar */
.recognition-status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 4px;
    margin-bottom: 12px;
}

.live-val-box {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.live-val {
    font-size: 1.4rem;
    font-weight: 900;
    color: var(--primary);
    font-family: monospace;
    min-width: 32px;
    display: inline-block;
}

.speed-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 10px;
    border-radius: 9999px;
    border: 1px solid var(--card-border);
}

/* Game Action Controls */
.game-controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 0.8fr;
    gap: 8px;
    margin-top: auto;
}

.btn-game {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    padding: 12px 6px;
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.btn-game:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-game:active {
    transform: scale(0.96);
}

.btn-game.clear {
    border-color: rgba(245, 158, 11, 0.4);
    color: #fbbf24;
}

.btn-game.skip {
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

/* ==================== RESULT SCREEN ==================== */
.result-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 24px;
    text-align: center;
    margin: auto 0;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.result-header h2 {
    font-size: 1.5rem;
    font-weight: 800;
    margin-bottom: 12px;
}

.rank-display {
    margin: 16px 0 24px;
}

.rank-badge {
    font-size: 5rem;
    font-weight: 900;
    line-height: 1;
    text-shadow: 0 0 30px currentColor;
}

.rank-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 8px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.stat-item {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 12px;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.stat-value {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main);
}

.result-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.btn-primary {
    background: linear-gradient(135deg, #0284c7, #38bdf8);
    border: none;
    color: white;
    font-size: 1.05rem;
    font-weight: 800;
    padding: 14px;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--primary-glow);
    transition: all 0.2s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--primary-glow);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 700;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-twitter {
    background: rgba(29, 155, 240, 0.15);
    border-color: rgba(29, 155, 240, 0.4);
    color: #38bdf8;
}

/* Footer */
.app-footer {
    text-align: center;
    padding-top: 16px;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: auto;
}

.app-footer a {
    color: var(--primary);
    text-decoration: none;
}

/* Responsive adjust for small phones */
@media (max-height: 680px) {
    .hero-title { font-size: 1.8rem; }
    .canvas-wrapper { height: 190px; }
    .question-text { font-size: 2.2rem; }
    .app-container { padding: 10px; }
}
