/* WordWeft Web Client — Dark theme matching Android app */

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

:root {
    --bg-primary: #0F0F23;
    --bg-secondary: #1A1A2E;
    --bg-card: #1E1E36;
    --bg-input: #16213E;
    --accent-indigo: #6366F1;
    --accent-purple: #8B5CF6;
    --accent-green: #10B981;
    --accent-red: #EF4444;
    --accent-amber: #F59E0B;
    --text-primary: #FFFFFF;
    --text-secondary: #A0A0B8;
    --text-muted: #666680;
    --text-dim: #333355;
    --border: #333355;
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* Screen management */
.screen {
    display: none;
    position: fixed;
    inset: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.screen.active {
    display: block;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    -webkit-user-select: none;
    user-select: none;
}
.btn:active {
    transform: scale(0.97);
}
.btn:disabled {
    opacity: 0.4;
    cursor: default;
    transform: none;
}
.btn-large {
    width: 100%;
    height: 56px;
    font-size: 18px;
}
.btn-small {
    height: 36px;
    padding: 0 16px;
    font-size: 13px;
    border-radius: var(--radius-xs);
}
.btn-primary {
    background: var(--accent-purple);
    color: white;
}
.btn-secondary {
    background: transparent;
    color: var(--accent-purple);
    border: 2px solid var(--accent-purple);
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.game-mode-selector {
    margin-bottom: 16px;
}
.game-mode-selector label {
    display: block;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 8px;
}
.mode-options {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.btn-mode {
    padding: 8px 14px;
    border-radius: 20px;
    border: 2px solid var(--accent-purple);
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
}
.btn-mode.active {
    background: var(--accent-purple);
    color: white;
}
.btn-green {
    background: var(--accent-green);
    color: white;
}
.btn-google {
    background: white;
    color: #333;
    font-size: 15px;
    height: 44px;
    padding: 0 20px;
    border-radius: var(--radius-sm);
    width: 100%;
}
.btn-icon {
    font-size: 18px;
}
.btn-back {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    margin: -8px;
}

/* Input */
.input-field {
    width: 100%;
    height: 52px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 16px;
    padding: 0 16px;
    outline: none;
    transition: border-color 0.2s;
}
.input-field:focus {
    border-color: var(--accent-purple);
}
.input-field::placeholder {
    color: var(--text-muted);
}

/* Dialog */
.dialog {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 24px;
}
.dialog.hidden {
    display: none;
}
.dialog-content {
    background: var(--bg-card);
    border-radius: 20px;
    padding: 28px;
    width: 100%;
    max-width: 400px;
}
.dialog-content h3 {
    font-size: 20px;
    margin-bottom: 4px;
}
.dialog-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 16px;
}
.dialog-buttons {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}
.dialog-buttons .btn {
    flex: 1;
    height: 44px;
}

/* Avatar grid */
.avatar-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
    margin-top: 16px;
}
.avatar-option {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    border: 2px solid transparent;
    transition: background 0.15s;
}
.avatar-option:hover {
    background: rgba(99,102,241,0.15);
}
.avatar-option.selected {
    background: rgba(99,102,241,0.25);
    border-color: var(--accent-indigo);
}

.hidden {
    display: none !important;
}

/* ─── Home Screen ─────────────────────────────────────── */

.home-container {
    min-height: 100%;
    background: linear-gradient(180deg, #0F0F23 0%, #1A1A2E 50%, #16213E 100%);
    padding: 24px;
    padding-top: calc(24px + var(--safe-top));
    padding-bottom: calc(24px + var(--safe-bottom));
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 480px;
    margin: 0 auto;
}

.logo-section {
    text-align: center;
    margin-top: 24px;
    margin-bottom: 12px;
}
.logo-placeholder {
    width: 100px;
    height: 100px;
    background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 48px;
    font-weight: bold;
    color: white;
    margin: 0 auto 16px;
}
.logo-section h1 {
    font-size: 42px;
    font-weight: 800;
    letter-spacing: -1px;
}
.tagline {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 16px;
    margin-top: 8px;
}

/* User bar */
.user-bar {
    width: 100%;
    background: var(--bg-card);
    border-radius: 14px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.user-avatar {
    font-size: 28px;
}
.user-info {
    display: flex;
    flex-direction: column;
    flex: 1;
}
.user-name {
    font-weight: 700;
    font-size: 16px;
}
.user-level {
    font-size: 12px;
    color: var(--accent-indigo);
    font-weight: 600;
}
.xp-bar-container {
    flex: 1;
    height: 6px;
    background: var(--text-dim);
    border-radius: 3px;
    overflow: hidden;
}
.xp-bar {
    height: 100%;
    background: var(--accent-indigo);
    border-radius: 3px;
    transition: width 0.5s ease;
    width: 0%;
}
.xp-text {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

.button-group {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.auth-section {
    width: 100%;
    margin-top: 20px;
    text-align: center;
}
.auth-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

.how-to-play {
    width: 100%;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 24px;
}
.how-to-play h4 {
    color: var(--accent-indigo);
    font-size: 16px;
    margin-bottom: 12px;
}
.how-to-play ol {
    list-style-position: inside;
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.8;
}

.footer {
    margin-top: 20px;
    display: flex;
    gap: 12px;
    align-items: center;
}
.footer a {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
}
.footer a:hover {
    color: var(--accent-indigo);
}
.footer-dot {
    color: var(--text-dim);
}

/* ─── Lobby Screen ────────────────────────────────────── */

.lobby-container {
    min-height: 100%;
    background: linear-gradient(180deg, #0F0F23, #1A1A2E);
    padding: 24px;
    padding-top: calc(24px + var(--safe-top));
    max-width: 480px;
    margin: 0 auto;
}
.lobby-container h2 {
    font-size: 24px;
    margin-bottom: 16px;
    display: inline-block;
    margin-left: 12px;
}

.room-code-display {
    background: #2D1F5E;
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}
.room-code-label {
    font-size: 11px;
    color: #A78BFA;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.room-code-value {
    font-size: 24px;
    font-weight: 800;
    letter-spacing: 3px;
    flex: 1;
}
.players-section h4 {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 10px;
}
.player-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 20px;
}
.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-card);
    border-radius: var(--radius-xs);
}
.player-item-avatar {
    font-size: 20px;
}
.player-item-name {
    font-size: 16px;
    font-weight: 500;
    flex: 1;
}
.player-item-host {
    font-size: 11px;
    color: var(--accent-purple);
    background: rgba(139,92,246,0.15);
    padding: 2px 8px;
    border-radius: 4px;
}
.lobby-status {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 20px;
}

/* ─── Game Screen ─────────────────────────────────────── */

.game-container {
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    max-width: 600px;
    margin: 0 auto;
}
.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    padding-top: calc(12px + var(--safe-top));
    border-bottom: 1px solid var(--border);
}
.game-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.game-room-code {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent-purple);
    background: rgba(139,92,246,0.15);
    padding: 4px 10px;
    border-radius: 6px;
}
.game-mode-label {
    font-size: 12px;
    color: var(--text-muted);
}

.story-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    -webkit-overflow-scrolling: touch;
}
.story-text {
    font-size: 18px;
    line-height: 1.7;
    word-wrap: break-word;
}
.story-placeholder {
    color: var(--text-muted);
    font-style: italic;
}
.story-word {
    display: inline;
    transition: color 0.3s;
}
.story-word.new {
    animation: wordFadeIn 0.4s ease;
}
@keyframes wordFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.turn-info {
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid var(--border);
}
.turn-indicator {
    font-size: 14px;
    color: var(--text-secondary);
}
.turn-indicator .current-player {
    color: var(--accent-green);
    font-weight: 600;
}
.timer-display {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent-amber);
    min-width: 36px;
    text-align: right;
}
.timer-display.urgent {
    color: var(--accent-red);
    animation: pulse 0.5s ease infinite alternate;
}
@keyframes pulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

.typing-indicator {
    padding: 4px 16px 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text-muted);
}
.typing-dot {
    width: 5px;
    height: 5px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}
.typing-name {
    margin-left: 4px;
}

.input-section {
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}
.input-row {
    display: flex;
    gap: 10px;
}
.word-input {
    flex: 1;
    height: 48px;
    background: var(--bg-input);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 17px;
    padding: 0 16px;
    outline: none;
}
.word-input:focus {
    border-color: var(--accent-indigo);
}
.word-input::placeholder {
    color: var(--text-muted);
}
.word-input:disabled {
    opacity: 0.4;
}
.btn-submit {
    width: 72px;
    height: 48px;
    flex-shrink: 0;
}

.secret-word-area {
    padding: 8px 16px;
    background: rgba(245,158,11,0.1);
    border-top: 1px solid rgba(245,158,11,0.2);
    display: flex;
    align-items: center;
    gap: 8px;
}
.secret-label {
    font-size: 12px;
    color: var(--accent-amber);
}
.secret-word {
    font-size: 14px;
    font-weight: 700;
    color: var(--accent-amber);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* ─── Results Screen ──────────────────────────────────── */

.results-container {
    min-height: 100%;
    background: linear-gradient(180deg, #0F0F23, #1A1A2E);
    padding: 24px;
    padding-top: calc(24px + var(--safe-top));
    padding-bottom: calc(24px + var(--safe-bottom));
    max-width: 520px;
    margin: 0 auto;
}
.results-container h2 {
    font-size: 28px;
    text-align: center;
    margin-bottom: 20px;
}
.results-container h4 {
    font-size: 16px;
    color: var(--text-secondary);
    margin: 20px 0 12px;
}

.story-grade-section {
    text-align: center;
    margin-bottom: 20px;
}
.result-grade {
    font-size: 64px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.result-genre {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.result-story-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}
.result-story-card h4 {
    margin: 0 0 8px;
    color: var(--accent-indigo);
}
.result-story-text {
    color: var(--text-secondary);
    font-size: 15px;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

.score-bars {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.score-bar-item {
    display: flex;
    align-items: center;
    gap: 10px;
}
.score-label {
    width: 80px;
    font-size: 13px;
    color: var(--text-secondary);
}
.score-bar {
    flex: 1;
    height: 8px;
    background: var(--text-dim);
    border-radius: 4px;
    overflow: hidden;
}
.score-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 1s ease;
    width: 0%;
}
.score-value {
    width: 32px;
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.player-stats-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.player-stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 14px;
}
.player-stat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.player-stat-avatar {
    font-size: 22px;
}
.player-stat-name {
    font-weight: 600;
    font-size: 15px;
    flex: 1;
}
.player-stat-impact {
    font-size: 20px;
    font-weight: 800;
    color: var(--accent-indigo);
}
.player-stat-title {
    font-size: 13px;
    color: var(--accent-purple);
    font-style: italic;
}
.player-stat-details {
    display: flex;
    gap: 16px;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

.xp-earned-section {
    text-align: center;
    margin-top: 16px;
}
.xp-earned-text {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent-green);
}

.result-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 24px;
}

/* Utilities */
.text-center { text-align: center; }
.mt-12 { margin-top: 12px; }

/* Player colors (matching Android) */
.color-0 { color: #FF6B6B; }
.color-1 { color: #4ECDC4; }
.color-2 { color: #45B7D1; }
.color-3 { color: #96CEB4; }
.color-4 { color: #FFEAA7; }
.color-5 { color: #DDA0DD; }
.color-6 { color: #98D8C8; }
.color-7 { color: #F7DC6F; }

/* Score bar colors */
.score-coherence { background: #6366F1; }
.score-creativity { background: #8B5CF6; }
.score-humor { background: #F59E0B; }
.score-vocabulary { background: #10B981; }
.score-flow { background: #3B82F6; }

/* Profile Screen */
.profile-container {
    max-width: 500px;
    margin: 0 auto;
    padding: 24px 16px;
}
.profile-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 24px;
    text-align: center;
    margin-bottom: 20px;
}
.profile-avatar {
    font-size: 64px;
    margin-bottom: 8px;
}
.profile-name {
    font-size: 22px;
    font-weight: bold;
    color: var(--text-primary);
    margin-bottom: 4px;
}
.profile-rank {
    font-size: 14px;
    color: var(--accent-purple);
    margin-bottom: 12px;
}
.profile-xp-bar {
    height: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}
.profile-xp-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-purple), #a78bfa);
    border-radius: 4px;
    transition: width 0.5s;
}
.profile-xp-text {
    font-size: 12px;
    color: var(--text-secondary);
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 16px 8px;
    text-align: center;
}
.stat-value {
    font-size: 24px;
    font-weight: bold;
    color: var(--accent-purple);
}
.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Leaderboard Screen */
.leaderboard-container {
    max-width: 500px;
    margin: 0 auto;
    padding: 24px 16px;
}
.leaderboard-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}
.btn-tab {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius-md);
    border: 2px solid var(--accent-purple);
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
}
.btn-tab.active {
    background: var(--accent-purple);
    color: white;
}
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.leaderboard-empty {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 16px;
}
.lb-entry {
    display: flex;
    align-items: center;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    gap: 12px;
}
.lb-rank {
    font-size: 18px;
    font-weight: bold;
    color: var(--text-secondary);
    width: 30px;
    text-align: center;
}
.lb-rank.gold { color: #F59E0B; }
.lb-rank.silver { color: #9CA3AF; }
.lb-rank.bronze { color: #CD7F32; }
.lb-avatar {
    font-size: 28px;
}
.lb-info {
    flex: 1;
}
.lb-name {
    font-weight: bold;
    color: var(--text-primary);
    font-size: 15px;
}
.lb-level {
    font-size: 12px;
    color: var(--text-secondary);
}
.lb-xp {
    font-weight: bold;
    color: var(--accent-purple);
    font-size: 15px;
}
.lb-entry.me {
    border: 2px solid var(--accent-purple);
}
