/* Sons of Liberty v2 - Full RPG Architecture */

:root {
    --cream: #f5f0e1;
    --parchment: #e8dfc8;
    --ink: #2c2416;
    --red: #8b2635;
    --blue: #1e3a5f;
    --gold: #b8860b;
    --green: #2f4f2f;
    --brown: #5c4033;
    --paper: #fffef8;
}

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

body {
    font-family: 'Georgia', serif;
    background: var(--cream);
    color: var(--ink);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    animation: fadeIn 0.5s ease;
}

.screen.active { display: block; }
.hidden { display: none !important; }

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

/* ===== AUTHENTICATION SCREEN ===== */
#auth-screen {
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--blue) 0%, var(--ink) 100%);
    padding: 20px;
}

#auth-screen.active {
    display: flex;
}

.auth-container {
    background: var(--paper);
    border-radius: 15px;
    padding: 40px;
    max-width: 500px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.logo {
    text-align: center;
    margin-bottom: 30px;
}

.logo .emoji {
    font-size: 4rem;
    display: block;
    margin-bottom: 10px;
}

.logo h1 {
    color: var(--blue);
    font-size: 2rem;
    margin-bottom: 5px;
}

.logo .subtitle {
    color: var(--brown);
    font-style: italic;
}

/* Auth Tabs */
#auth-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
}

.tab-btn {
    flex: 1;
    padding: 12px;
    border: none;
    background: var(--parchment);
    color: var(--brown);
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--red);
    color: white;
}

/* Forms */
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.auth-form input {
    padding: 14px;
    border: 2px solid var(--parchment);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.auth-form input:focus {
    outline: none;
    border-color: var(--blue);
}

/* Grade Selector */
.age-selector, .difficulty-selector {
    margin-top: 10px;
}

.age-selector label, .difficulty-selector label {
    display: block;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--brown);
}

.grade-buttons, .difficulty-buttons {
    display: grid;
    gap: 8px;
}

.grade-buttons {
    grid-template-columns: repeat(3, 1fr);
}

.difficulty-buttons {
    grid-template-columns: 1fr;
}

.grade-btn, .diff-btn {
    padding: 12px;
    border: 2px solid var(--parchment);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s;
    text-align: center;
}

.grade-btn:hover, .diff-btn:hover {
    border-color: var(--blue);
}

.grade-btn.selected, .diff-btn.selected {
    border-color: var(--red);
    background: linear-gradient(135deg, white, #fff5f5);
    box-shadow: 0 0 0 2px var(--red);
}

.grade-btn small {
    display: block;
    font-size: 0.75rem;
    color: var(--brown);
    margin-top: 2px;
}

.diff-btn strong {
    display: block;
    font-size: 1.1rem;
    color: var(--blue);
    margin-bottom: 4px;
}

.diff-btn small {
    display: block;
    font-size: 0.85rem;
    color: var(--brown);
}

.btn-primary {
    background: linear-gradient(180deg, var(--red) 0%, #6b1e2a 100%);
    color: white;
    border: none;
    padding: 16px;
    font-family: inherit;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.3s, box-shadow 0.3s;
    margin-top: 10px;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(139, 38, 53, 0.4);
}

/* ===== GAME SCREEN ===== */
#game-screen {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--cream);
}

/* Header */
#game-header {
    background: linear-gradient(180deg, var(--blue) 0%, var(--ink) 100%);
    color: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

#player-avatar {
    font-size: 2rem;
}

.player-info {
    display: flex;
    flex-direction: column;
}

#player-name-display {
    font-weight: bold;
    font-size: 1.1rem;
}

#player-rank {
    font-size: 0.85rem;
    color: var(--gold);
}

.header-center {
    text-align: center;
}

#current-era {
    display: block;
    font-size: 0.9rem;
    color: var(--gold);
}

#current-year {
    display: block;
    font-size: 1.4rem;
    font-weight: bold;
}

.icon-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s;
}

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

/* Stats Bar */
#stats-bar {
    background: var(--paper);
    padding: 10px 20px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-bottom: 2px solid var(--parchment);
}

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

.stat-icon {
    font-size: 1.2rem;
}

.stat-bar {
    width: 60px;
    height: 8px;
    background: #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar .fill {
    height: 100%;
    background: linear-gradient(90deg, var(--red), #ff4444);
    transition: width 0.5s;
}

/* Main Content */
#game-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.game-view {
    display: none;
    height: 100%;
}

.game-view.active {
    display: block;
}

/* ===== WORLD MAP ===== */
#world-map {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.map-container {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

#colonies-map {
    width: 100%;
    height: auto;
    max-height: 400px;
    border-radius: 8px;
    background: var(--parchment);
}

.map-region {
    fill: var(--parchment);
    stroke: var(--brown);
    stroke-width: 2;
    cursor: pointer;
    transition: all 0.3s;
}

.map-region:hover {
    fill: var(--cream);
    stroke: var(--red);
}

.map-region.selected {
    fill: #ffe4e4;
    stroke: var(--red);
    stroke-width: 3;
}

.location-point {
    fill: var(--red);
    stroke: white;
    stroke-width: 2;
    cursor: pointer;
    transition: r 0.3s;
}

.location-point:hover {
    r: 12;
    fill: var(--gold);
}

.loc-label {
    font-size: 12px;
    fill: var(--ink);
    font-weight: bold;
    pointer-events: none;
}

#player-marker {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.map-controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    flex-wrap: wrap;
}

.btn-action {
    flex: 1;
    min-width: 120px;
    padding: 12px 20px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-action:hover:not(:disabled) {
    background: var(--gold);
    color: var(--ink);
}

.btn-action:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.region-info {
    background: white;
    border-radius: 12px;
    padding: 20px;
    border-left: 4px solid var(--red);
}

#region-name {
    color: var(--blue);
    font-size: 1.4rem;
    margin-bottom: 10px;
}

#region-desc {
    color: var(--brown);
    margin-bottom: 15px;
    line-height: 1.6;
}

.region-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag {
    background: var(--cream);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    color: var(--brown);
}

/* ===== STORY VIEW ===== */
.story-panel {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 800px;
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

#story-scene {
    margin-bottom: 25px;
}

#scene-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(135deg, var(--parchment), var(--cream));
    border-radius: 8px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
}

#scene-title {
    color: var(--blue);
    font-size: 1.5rem;
    margin-bottom: 15px;
}

#scene-text {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--ink);
}

#story-choices {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.story-choice {
    background: linear-gradient(90deg, var(--cream), white);
    border: 2px solid var(--parchment);
    border-left: 5px solid var(--blue);
    padding: 18px;
    text-align: left;
    font-family: inherit;
    font-size: 1.05rem;
    cursor: pointer;
    border-radius: 0 8px 8px 0;
    transition: all 0.3s;
}

.story-choice:hover {
    border-left-color: var(--red);
    background: white;
    transform: translateX(8px);
}

/* ===== BATTLE VIEW ===== */
.battle-panel {
    background: white;
    border-radius: 12px;
    padding: 25px;
    max-width: 1000px;
    margin: 0 auto;
}

#battle-name {
    text-align: center;
    color: var(--red);
    font-size: 1.6rem;
    margin-bottom: 20px;
}

.battlefield {
    display: grid;
    grid-template-columns: 1fr 1.5fr 1fr;
    gap: 20px;
}

.army {
    background: var(--cream);
    border-radius: 10px;
    padding: 20px;
}

.army h3 {
    text-align: center;
    margin-bottom: 15px;
    font-size: 1.1rem;
}

.american h3 { color: var(--blue); }
.british h3 { color: var(--red); }

.army-morale {
    margin-top: 15px;
}

.army-morale label {
    display: block;
    font-size: 0.85rem;
    color: var(--brown);
    margin-bottom: 5px;
}

.bar {
    height: 12px;
    background: #ddd;
    border-radius: 6px;
    overflow: hidden;
}

#american-morale-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--blue), #4a7aa7);
    transition: width 0.5s;
}

#british-morale-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--red), #a03040);
    transition: width 0.5s;
}

.battle-center {
    text-align: center;
}

#battle-log {
    background: var(--parchment);
    padding: 15px;
    border-radius: 8px;
    min-height: 100px;
    margin-bottom: 15px;
    font-style: italic;
}

#battle-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.battle-action {
    background: var(--blue);
    color: white;
    border: none;
    padding: 14px;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s;
}

.battle-action:hover {
    background: var(--gold);
    color: var(--ink);
}

/* ===== SETTLEMENT VIEW ===== */
.settlement-panel {
    background: white;
    border-radius: 12px;
    padding: 25px;
    max-width: 900px;
    margin: 0 auto;
}

#settlement-name {
    text-align: center;
    color: var(--blue);
    font-size: 1.5rem;
    margin-bottom: 20px;
}

#settlement-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    margin-bottom: 20px;
}

.settlement-tile {
    aspect-ratio: 1;
    background: var(--cream);
    border: 2px solid var(--parchment);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s;
}

.settlement-tile:hover {
    border-color: var(--blue);
    background: var(--parchment);
}

.settlement-tile.occupied {
    background: white;
    border-color: var(--brown);
}

.settlement-controls {
    background: var(--cream);
    border-radius: 10px;
    padding: 20px;
}

.build-menu {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.build-btn {
    padding: 10px 16px;
    background: white;
    border: 2px solid var(--parchment);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s;
}

.build-btn:hover {
    border-color: var(--blue);
    background: var(--paper);
}

.build-btn.selected {
    border-color: var(--red);
    background: #fff5f5;
}

.settlement-stats {
    display: flex;
    justify-content: space-around;
    flex-wrap: wrap;
    gap: 10px;
}

.settlement-stats span {
    color: var(--brown);
}

.settlement-stats b {
    color: var(--blue);
}

/* ===== CHARACTER/DIPLOMACY VIEW ===== */
.character-panel {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 25px;
    background: white;
    border-radius: 12px;
    padding: 25px;
    max-width: 800px;
    margin: 0 auto;
}

#npc-portrait {
    background: linear-gradient(135deg, var(--parchment), var(--cream));
    border-radius: 10px;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 6rem;
}

.dialogue-box {
    display: flex;
    flex-direction: column;
}

#npc-name {
    color: var(--blue);
    font-size: 1.4rem;
    margin-bottom: 5px;
}

#npc-title {
    color: var(--brown);
    font-style: italic;
    margin-bottom: 20px;
}

#dialogue-text {
    background: var(--cream);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--gold);
    font-size: 1.1rem;
    line-height: 1.7;
    margin-bottom: 20px;
    flex: 1;
}

#dialogue-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.dialogue-option {
    background: white;
    border: 2px solid var(--parchment);
    padding: 14px 18px;
    text-align: left;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.3s;
}

.dialogue-option:hover {
    border-color: var(--blue);
    background: var(--cream);
}

/* ===== NAVIGATION ===== */
#game-nav {
    background: var(--ink);
    display: flex;
    justify-content: space-around;
    padding: 10px;
}

.nav-btn {
    flex: 1;
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.6);
    padding: 8px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.nav-btn .icon {
    font-size: 1.5rem;
}

.nav-btn .label {
    font-size: 0.75rem;
}

.nav-btn:hover, .nav-btn.active {
    color: white;
}

.nav-btn.active {
    background: rgba(255,255,255,0.1);
    border-radius: 8px;
}

/* ===== MENU OVERLAY ===== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.menu-panel {
    background: white;
    border-radius: 15px;
    padding: 30px;
    width: 90%;
    max-width: 350px;
}

.menu-panel h2 {
    text-align: center;
    color: var(--blue);
    margin-bottom: 20px;
}

.menu-btn {
    display: block;
    width: 100%;
    padding: 14px;
    margin-bottom: 10px;
    background: var(--cream);
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    text-align: left;
}

.menu-btn:hover {
    background: var(--parchment);
}

.menu-btn.secondary {
    background: var(--blue);
    color: white;
    text-align: center;
    margin-top: 15px;
}

.menu-btn.secondary:hover {
    background: var(--gold);
    color: var(--ink);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .auth-container {
        padding: 25px;
    }
    
    .grade-buttons {
        grid-template-columns: repeat(2, 1fr);
    }
    
    #game-header {
        padding: 10px 15px;
    }
    
    #player-name-display {
        font-size: 0.95rem;
    }
    
    #current-year {
        font-size: 1.1rem;
    }
    
    .battlefield {
        grid-template-columns: 1fr;
    }
    
    .character-panel {
        grid-template-columns: 1fr;
    }
    
    #npc-portrait {
        min-height: 120px;
    }
    
    #settlement-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Grade-based UI adjustments */
.grade-4 .story-choice { font-size: 1.2rem; padding: 22px; }
.grade-4 #scene-text { font-size: 1.2rem; line-height: 1.9; }
.grade-5 .story-choice { font-size: 1.15rem; padding: 20px; }
.grade-5 #scene-text { font-size: 1.15rem; }
.grade-9 .story-choice { font-size: 0.95rem; padding: 15px; }
.grade-9 #scene-text { font-size: 1rem; }

/* ===== NPC CONVERSATION SYSTEM ===== */
.character-panel {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.npc-info {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
    background: var(--paper);
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.npc-info .portrait {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--blue), var(--ink));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    border: 3px solid var(--gold);
}

.npc-header h3 {
    color: var(--blue);
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.npc-header p {
    color: var(--brown);
    font-style: italic;
}

.conversation-area {
    background: var(--parchment);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

.conversation-area .history {
    max-height: 400px;
    overflow-y: auto;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--paper);
    border-radius: 8px;
    border: 2px solid var(--gold);
}

.conversation-area .history:empty::before {
    content: 'Start the conversation by typing a message or selecting a quick prompt below...';
    color: var(--brown);
    font-style: italic;
    opacity: 0.6;
}

.history .message {
    margin-bottom: 15px;
    padding: 12px;
    border-radius: 8px;
    animation: slideIn 0.3s ease;
}

.history .message.player {
    background: var(--blue);
    color: white;
    margin-left: 60px;
    text-align: right;
}

.history .message.npc {
    background: var(--cream);
    color: var(--ink);
    margin-right: 60px;
    border-left: 4px solid var(--gold);
}

.history .message .sender {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.history .message .text {
    line-height: 1.6;
}

.history .message .timestamp {
    font-size: 0.75rem;
    opacity: 0.7;
    margin-top: 5px;
}

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

.input-area {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.input-area input {
    flex: 1;
    padding: 12px;
    border: 2px solid var(--gold);
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
    background: var(--paper);
}

.input-area input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.1);
}

.input-area button {
    padding: 12px 24px;
    background: var(--blue);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.input-area button:hover {
    background: var(--ink);
    transform: translateY(-2px);
}

.input-area button:active {
    transform: translateY(0);
}

.quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.prompt-btn {
    padding: 8px 16px;
    background: var(--gold);
    color: white;
    border: none;
    border-radius: 20px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s;
}

.prompt-btn:hover {
    background: var(--red);
    transform: scale(1.05);
}

#btn-end-conversation {
    width: 100%;
    padding: 12px;
    background: var(--brown);
    color: white;
    border: none;
    border-radius: 8px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

#btn-end-conversation:hover {
    background: var(--ink);
}

/* Loading state */
.message.loading {
    opacity: 0.6;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 0.3; }
}

/* API Key Setup */
.api-setup-notice {
    background: #fff3cd;
    border: 2px solid #ffc107;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
}

.api-setup-notice h4 {
    color: #856404;
    margin-bottom: 10px;
}

.api-setup-notice p {
    margin-bottom: 15px;
    color: #856404;
}

.api-setup-notice input {
    width: 100%;
    padding: 10px;
    border: 2px solid #ffc107;
    border-radius: 6px;
    margin-bottom: 10px;
    font-family: monospace;
}

.api-setup-notice button {
    padding: 10px 20px;
    background: #ffc107;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
}

.api-setup-notice button:hover {
    background: #ff9800;
    transform: translateY(-2px);
}

.api-setup-notice small {
    display: block;
    margin-top: 10px;
    color: #856404;
    font-size: 0.85rem;
}

.api-setup-notice a {
    color: #007bff;
    text-decoration: underline;
}

