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

body {
    font-family: 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

#app {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen {
    width: 100%;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.screen.hidden {
    display: none;
}

/* Auth Screen */
.auth-container {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    width: 100%;
}

.auth-container h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 10px;
    font-size: 2.5em;
}

.auth-container p {
    text-align: center;
    color: #666;
    margin-bottom: 30px;
}

.tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    color: #999;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.tab-btn:hover {
    color: #667eea;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.tab-content form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

input {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
    transition: border-color 0.3s;
}

input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

button {
    padding: 12px;
    border: none;
    border-radius: 5px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: bold;
}

.primary {
    background: #667eea;
    color: white;
}

.primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.secondary {
    background: #f0f0f0;
    color: #333;
}

.secondary:hover {
    background: #e0e0e0;
}

.error-message {
    color: #e74c3c;
    text-align: center;
    margin-top: 15px;
    display: none;
}

.error-message.show {
    display: block;
}

/* Main Menu Screen */
.main-menu {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 800px;
    width: 100%;
}

.main-menu h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 20px;
}

.user-info {
    text-align: right;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}

.user-info p {
    margin-bottom: 10px;
    color: #666;
}

.saves-section h2 {
    color: #333;
    margin-bottom: 20px;
}

.saves-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.save-card {
    background: #f9f9f9;
    border: 2px solid #ddd;
    border-radius: 5px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s;
}

.save-card:hover {
    border-color: #667eea;
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.2);
    transform: translateY(-2px);
}

.save-card h3 {
    margin-bottom: 10px;
    color: #667eea;
}

.save-card p {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

/* Game Setup Screen */
.game-setup {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 1000px;
    width: 100%;
}

.game-setup h2 {
    color: #667eea;
    margin-bottom: 30px;
}

.setup-step {
    display: block;
}

.setup-step.hidden {
    display: none;
}

.setup-step p {
    margin-bottom: 15px;
    font-size: 1.1em;
    color: #333;
}

.setup-step input {
    display: block;
    width: 100%;
    margin-bottom: 20px;
}

.kobold-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.kobold-card {
    background: #f9f9f9;
    border: 2px solid #ddd;
    border-radius: 5px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
}

.kobold-card:hover {
    border-color: #667eea;
    transform: translateY(-3px);
}

.kobold-card.selected {
    border-color: #27ae60;
    background: #eafef0;
}

.kobold-sprite {
    width: 80px;
    height: 80px;
    background: #ddd;
    margin: 0 auto 10px;
    border-radius: 3px;
}

.kobold-stats {
    font-size: 0.8em;
    color: #666;
    text-align: left;
    line-height: 1.4;
}

.counter {
    text-align: center;
    font-size: 1.1em;
    color: #666;
    margin-bottom: 20px;
}

.full-width {
    width: 100%;
}

/* Game Screen */
.game-container {
    background: white;
    width: 95%;
    max-width: 1260px;
    height: 90vh;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.game-header {
    padding: 20px;
    border-bottom: 2px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-header h1 {
    color: #667eea;
}

.game-time {
    font-size: 1.1em;
    color: #666;
}

.game-time span {
    margin-left: 20px;
}

.game-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.game-left {
    border-right: 2px solid #eee;
    overflow-y: auto;
    padding: 15px;
    gap: 15px;
}

.environment {
    flex: 0 0 auto;
    width: 725px;
    aspect-ratio: 1 / 1;
    background: linear-gradient(to bottom, #87ceeb, #90ee90);
    background-size: 100% 100%;
    background-repeat: no-repeat;
    background-position: center;
    position: relative;
    overflow: hidden;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.placements {
    position: absolute;
    inset: 0;
    pointer-events: auto;
}

.kobold-placement {
    position: absolute;
    width: 80px;
    height: 80px;
    transform: translate(-50%, -66.666%);
    pointer-events: auto;
    cursor: pointer;
    image-rendering: pixelated;
}

.kobold-placement.flipped {
    transform: translate(-50%, -66.666%) scaleX(-1);
}

.placement {
    width: 60px;
    height: 60px;
    background: #ddd;
    border-radius: 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 0.8em;
    text-align: center;
    padding: 5px;
    transition: all 0.3s;
}

.placement:hover {
    background: #ccc;
    transform: scale(1.05);
}

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

.environment-select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 1em;
}

.environment-preview {
    width: 50%;
    aspect-ratio: 1 / 1;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #f9f9f9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.environment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.environment-description {
    color: #666;
    font-size: 0.95em;
}

.game-right {
    width: 500px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 15px;
    gap: 15px;
}

.panel {
    background: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 15px;
    overflow-y: clip;
    min-height: 200px;
}

.panel h3 {
    color: #667eea;
    margin-bottom: 10px;
}

.events-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tribe-list {
    max-height: -webkit-fill-available;
    overflow-y: auto;
}

.tribe-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.tribe-table td {
    width: 50%;
    vertical-align: top;
    padding: 0 6px 10px;
}

.tribe-item-content {
    display: flex;
    align-items: center;
}

.tribe-cell-empty {
    padding: 0 6px 10px;
}

.event-item,
.tribe-item {
    background: white;
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.3s;
    max-height: 50px;
}

.event-item:hover,
.tribe-item:hover {
    background: #f0f0f0;
    border-color: #667eea;
}

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

.tribe-item-name {
    font-weight: bold;
    color: #333;
}

.tribe-item-title {
    font-size: 0.85em;
    color: #666;
}

.tribe-item-age {
    font-size: 0.8em;
    color: #999;
}

.tribe-item.injured {
    background: #ffe6e6;
    border-color: #ff9999;
}

.tribe-item.injured:hover {
    background: #ffcccc;
    border-color: #ff6666;
}

.kobold-list-sprite {
    max-height: 45px;
}

/* Modal */
.modal {
    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;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 10px;
    padding: 40px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: #999;
}

.modal-close:hover {
    color: #333;
}

.event-story {
    font-size: 1.1em;
    line-height: 1.6;
    color: #333;
    margin-bottom: 20px;
    white-space: pre-wrap;
}

/* Storage Window */
.storage-header {
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.food-display {
    font-size: 0.8em;
    font-weight: bold;
    color: #667eea;
}

.storage-items {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 100px;
    overflow-y: auto;
    overflow-x: hidden;
}

.storage-item {
    background: #f9f9f9;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
}

.storage-item:hover {
    background: #efe;
    transform: translateX(5px);
}

.storage-item-name {
    font-weight: bold;
    color: #333;
}

/* Item Modal */
.item-modal {
    max-width: 400px;
}

.item-modal-header {
    margin-bottom: 15px;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.item-modal-header h2 {
    color: #667eea;
    margin: 0;
}

.item-description {
    margin-bottom: 15px;
    line-height: 1.5;
    color: #555;
}

.item-stat-mods {
    margin-bottom: 15px;
    padding: 10px;
    background: #f5f5f5;
    border-radius: 5px;
}

.stat-mod {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 0.9em;
}

.stat-mod.positive {
    color: #28a745;
}

.stat-mod.negative {
    color: #dc3545;
}

.stat-mod.neutral {
    color: #999;
}

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

.kobold-select {
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1em;
}

#giveItemBtn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Kobold Modal */
.kobold-modal {
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
}

.kobold-modal-header {
    margin-bottom: 15px;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.kobold-modal-header h2 {
    color: #667eea;
    margin: 0 0 5px 0;
}

.kobold-age {
    color: #999;
    margin: 0;
    font-size: 0.9em;
}

.kobold-description {
    margin-bottom: 15px;
    line-height: 1.5;
    color: #555;
}

.kobold-tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
}

.kobold-tab-btn {
    padding: 10px 15px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1em;
    color: #999;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.kobold-tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

.kobold-tab-btn:hover {
    color: #667eea;
}

.kobold-tab-content {
    display: none;
}

.kobold-tab-content.active {
    display: block;
}

.kobold-stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-item {
    padding: 10px;
    background: #f9f9f9;
    border-radius: 5px;
}

.stat-name {
    font-weight: bold;
    color: #333;
    font-size: 0.85em;
    text-transform: capitalize;
}

.stat-value {
    color: #667eea;
    font-size: 1.2em;
    margin-top: 5px;
}

.stat-label {
    color: #999;
    font-size: 0.75em;
}

.kobold-inventory-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.kobold-inventory-item {
    padding: 10px;
    background: #f9f9f9;
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.2s;
}

.kobold-inventory-item:hover {
    background: #fef;
    transform: translateX(5px);
}

.kobold-item-name {
    font-weight: bold;
    color: #333;
}

.kobold-inventory-empty {
    padding: 20px;
    text-align: center;
    color: #999;
    font-style: italic;
}

.kobold-injuries-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.injury-item {
    padding: 10px;
    background: #fff7f7;
    border: 1px solid #f2dede;
    border-radius: 5px;
}

.injury-name {
    font-weight: bold;
    color: #b94a48;
}

.injury-desc {
    color: #666;
    font-size: 0.95em;
}

.injury-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
}

.kobold-relationships-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.relationships-section {
    padding: 12px;
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
}

.relationships-section h4 {
    margin-bottom: 10px;
    color: #667eea;
    font-size: 1em;
}

.relationship-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: white;
    border-radius: 4px;
    margin-bottom: 6px;
}

.relationship-item:last-child {
    margin-bottom: 0;
}

.relationship-name {
    font-weight: 500;
    color: #333;
}

.relationship-descriptor {
    font-weight: bold;
    font-size: 0.9em;
}

/* Config Screen */
.config-container {
    background: white;
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 100%;
}

.config-container h2 {
    color: #667eea;
    margin-bottom: 30px;
}

.config-section {
    margin-bottom: 30px;
}

.config-section h3 {
    color: #333;
    margin-bottom: 15px;
}

.config-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.config-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #f9f9f9;
    border-radius: 5px;
}

.config-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.config-item label {
    flex: 1;
    cursor: pointer;
}

/* Participant Selection */
.participants-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 5px;
}

.participant-row {
    display: flex;
    align-items: center;
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    background: #fafafa;
}

.participant-row.eligible {
    background: #f0f8ff;
    border-color: #667eea;
}

.participant-row.eligible label {
    cursor: pointer;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.participant-row.eligible input[type="checkbox"] {
    cursor: pointer;
    width: 18px;
    height: 18px;
}

.participant-row.ineligible {
    background: #f5f5f5;
    border-color: #ccc;
    opacity: 0.6;
}

.participant-disabled {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex: 1;
}

.disabled-reason {
    font-size: 0.85em;
    color: #999;
    font-style: italic;
    margin-left: 10px;
}

.participant-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    gap: 10px;
}

.participant-footer .counter {
    font-size: 0.9em;
    color: #666;
}

.participant-footer button {
    flex: 1;
    max-width: 150px;
}

/* Responsive */
@media (max-width: 768px) {
    .game-main {
        flex-direction: column;
    }

    .game-right {
        width: 100%;
        border-right: none;
        border-top: 2px solid #eee;
    }

    .kobold-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }
}