/* ==========================================
   PokéPal Tracker - Styles
   ========================================== */

/* === CSS Variables === */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: linear-gradient(180deg, #3d5a80 0%, #293241 100%);
    --bg-slot: rgba(255, 255, 255, 0.1);
    --bg-slot-hover: rgba(255, 255, 255, 0.2);
    --bg-modal: #293241;
    --bg-input: #1a1a2e;
    --text-primary: #fff;
    --text-secondary: #a0a0a0;
    --text-gold: #ffd700;
    --border-color: #3d5a80;
}

/* === Reset & Base === */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
        sans-serif;
    background: linear-gradient(
        135deg,
        var(--bg-primary) 0%,
        var(--bg-secondary) 100%
    );
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
}

/* === Light Theme === */
body.light-theme {
    --bg-primary: #f5f5f5;
    --bg-secondary: #e0e0e0;
    --bg-card: linear-gradient(180deg, #ffffff 0%, #f0f0f0 100%);
    --bg-slot: rgba(0, 0, 0, 0.05);
    --bg-slot-hover: rgba(0, 0, 0, 0.1);
    --bg-modal: #ffffff;
    --bg-input: #f9f9f9;
    --text-primary: #333;
    --text-secondary: #666;
    --text-gold: #b8860b;
    --border-color: #ccc;
}

body.light-theme h1 {
    color: var(--text-primary);
    text-shadow: none;
}

body.light-theme h2 {
    color: var(--text-gold);
}

body.light-theme a {
    color: var(--text-gold);
}

body.light-theme .save-card {
    background: var(--bg-card);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

body.light-theme .save-card-title {
    color: var(--text-gold);
}

body.light-theme .save-card-trainer {
    color: var(--text-secondary);
}

body.light-theme .save-card-game {
    background: rgba(0, 0, 0, 0.05);
    color: #555;
}

body.light-theme .save-card.new-save {
    border-color: rgba(0, 0, 0, 0.2);
    color: var(--text-secondary);
}

body.light-theme .save-card.new-save:hover {
    border-color: var(--text-gold);
    color: var(--text-gold);
}

body.light-theme .box {
    background: var(--bg-card);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

body.light-theme .box-title {
    color: var(--text-gold);
    text-shadow: none;
}

body.light-theme .box-header:hover {
    background: linear-gradient(
        90deg,
        rgba(120, 86, 255, 0.06),
        rgba(72, 123, 255, 0.04)
    );
    border-color: rgba(72, 123, 255, 0.12);
}

body.light-theme .pokemon-slot {
    background: var(--bg-slot);
}

body.light-theme .pokemon-slot:hover {
    background: var(--bg-slot-hover);
}

body.light-theme .pokemon-slot.empty {
    background: rgba(0, 0, 0, 0.03);
}

/* Ensure marked / shiny fill the entire slot in light theme (override base light slot bg) */
body.light-theme .pokemon-slot.marked {
    background: linear-gradient(
        135deg,
        rgba(76, 175, 80, 0.95) 0%,
        rgba(139, 195, 74, 0.95) 100%
    );
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.9);
    border: 1px solid rgba(76, 175, 80, 0.65);
}

body.light-theme .pokemon-slot.marked:hover {
    background: linear-gradient(
        135deg,
        rgba(76, 175, 80, 1) 0%,
        rgba(139, 195, 74, 1) 100%
    );
}

/* Shiny should also be solid on light cards */
body.light-theme .pokemon-slot.shiny-marked {
    background: linear-gradient(
        135deg,
        rgba(255, 215, 0, 0.98) 0%,
        rgba(255, 236, 179, 0.98) 100%
    );
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.9);
    border: 1px solid rgba(255, 200, 0, 0.7);
}

body.light-theme .pokemon-slot.shiny-marked::before {
    color: #b8860b;
    text-shadow: 0 0 6px rgba(255, 215, 0, 0.8);
}

/* Both normal + shiny */
body.light-theme .pokemon-slot.marked.shiny-marked {
    background: linear-gradient(
        135deg,
        rgba(102, 187, 106, 0.98) 0%,
        rgba(255, 215, 0, 0.98) 100%
    );
    box-shadow:
        0 0 10px rgba(76, 175, 80, 0.6),
        0 0 14px rgba(255, 215, 0, 0.9);
    border: 1px solid rgba(255, 200, 0, 0.6);
}

body.light-theme .pokemon-name {
    color: #555;
}

body.light-theme .save-info {
    background: rgba(0, 0, 0, 0.05);
}

body.light-theme .save-info-title {
    color: var(--text-gold);
}

body.light-theme .save-info-trainer {
    color: var(--text-secondary);
}

body.light-theme .modal-content {
    background: var(--bg-modal);
    color: var(--text-primary);
}

body.light-theme .modal-content h2 {
    color: var(--text-gold);
}

body.light-theme .modal-content p {
    color: var(--text-secondary);
}

body.light-theme .form-group input,
body.light-theme .form-group select {
    background: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-color);
}

body.light-theme .form-group input:disabled {
    background: #eee;
    color: #999;
}

body.light-theme .form-hint,
body.light-theme .hint {
    color: #888;
}

body.light-theme .back-link {
    color: var(--text-secondary);
}

body.light-theme .back-link:hover {
    color: var(--text-gold);
}

body.light-theme .preset-info {
    color: var(--text-secondary);
}

body.light-theme .stats {
    color: var(--text-secondary);
}

body.light-theme .empty-state {
    color: var(--text-secondary);
}

body.light-theme .empty-state h3 {
    color: var(--text-primary);
}

body.light-theme .progress-bar {
    background: rgba(0, 0, 0, 0.1);
}

body.light-theme .progress-text {
    color: var(--text-secondary);
}

body.light-theme .sync-status.disconnected {
    background: rgba(255, 152, 0, 0.1);
}

body.light-theme .box-toggle {
    color: var(--text-secondary);
}

a {
    color: #ffd700;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* === Typography === */
h1 {
    text-align: center;
    margin-bottom: 20px;
    color: #fff;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

h2 {
    color: #ffd700;
    margin-bottom: 16px;
}

/* === Layout === */
.container {
    max-width: 1200px;
    margin: 0 auto;
}

/* === Header === */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

.header h1 {
    margin: 0;
}

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

/* === Buttons === */
.btn {
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: #4caf50;
    color: white;
}

.btn-primary:hover {
    background: #43a047;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-danger {
    background: #ff6b6b;
    color: white;
}

.btn-danger:hover {
    background: #ff5252;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    padding: 8px;
    min-width: 36px;
    justify-content: center;
}

/* === Sync Status === */
.sync-status {
    text-align: center;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    display: inline-block;
}

.sync-status.connected {
    background: rgba(76, 175, 80, 0.2);
    color: #4caf50;
}

.sync-status.disconnected {
    background: rgba(255, 152, 0, 0.2);
    color: #ff9800;
}

.sync-status.syncing {
    background: rgba(33, 150, 243, 0.2);
    color: #2196f3;
}

.sync-status.error {
    background: rgba(255, 107, 107, 0.2);
    color: #ff6b6b;
}

/* === Save Cards Grid (Home Page) === */
.saves-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.save-card {
    background: linear-gradient(180deg, #3d5a80 0%, #293241 100%);
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
    cursor: pointer;
    position: relative;
}

.save-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.save-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.save-card-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: #ffd700;
}

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

.save-card-trainer {
    color: #a0a0a0;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.save-card-game {
    display: inline-block;
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    color: #ddd;
    margin-bottom: 12px;
}

.save-card-progress {
    margin-top: 12px;
}

/* Container is relative so we can position an overlay (shiny) bar on top of the normal fill */
.progress-bar {
    height: 8px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
    position: relative; /* allow absolute fills */
}

/* When toggle inputs are disabled (for example, Box Mark control while Mark Mode is off),
   visually grey them out so the user sees they're unavailable. */
.toggle-switch input:disabled + .toggle-slider {
    background: #3b3b3b;
    opacity: 0.45;
    cursor: not-allowed;
}

.toggle-switch input:disabled + .toggle-slider::after {
    background: #ddd;
    transform: none;
}

.toggle-switch input:disabled ~ .toggle-label {
    color: #777;
    opacity: 0.6;
    cursor: not-allowed;
}

/* Make the slider itself indicate disabled state (reduced contrast) while keeping layout */
.toggle-switch input:disabled + .toggle-slider,
.toggle-switch input:disabled + .toggle-slider::after {
    pointer-events: none;
}

/* Normal filled portion (regular catches) */
.progress-bar-fill {
    position: relative;
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    border-radius: 4px;
    transition: width 0.3s ease;
    z-index: 1;
}

/* Shiny overlay: positioned absolutely on top of the normal fill.
   It is semi-transparent and uses gold tones. Its width should be set
   independently (e.g. via inline style width: ${shinyPercentage}% when rendering). */
.progress-bar-fill.shiny {
    position: absolute;
    left: 0;
    top: 0;
    height: 100%;
    background: linear-gradient(90deg, #ffd700, #ffecb3);
    border-radius: 4px;
    transition:
        width 0.3s ease,
        opacity 0.3s ease;
    opacity: 0.95;
    z-index: 2;
    pointer-events: none;
}

/* Add a subtle glossy highlight on the shiny overlay */
.progress-bar-fill.shiny::after {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        180deg,
        rgba(255, 255, 255, 0.15) 0%,
        rgba(255, 255, 255, 0.03) 40%,
        rgba(255, 255, 255, 0) 100%
    );
    border-radius: 4px;
    mix-blend-mode: overlay;
    pointer-events: none;
}

/* Text next to the bar */
.progress-text {
    font-size: 0.85rem;
    color: #a0a0a0;
    text-align: right;
}

/* New Save Card */
.save-card.new-save {
    border: 2px dashed rgba(255, 255, 255, 0.3);
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    color: #a0a0a0;
}

.save-card.new-save:hover {
    border-color: #ffd700;
    color: #ffd700;
}

.save-card.new-save .icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

/* === Controls Bar (Viewer Page) === */
.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
}

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

.controls label {
    font-weight: 500;
}

.controls select {
    padding: 8px 16px;
    font-size: 14px;
    border-radius: 8px;
    border: none;
    background: #fff;
    cursor: pointer;
    min-width: 200px;
}

/* === Save Info Bar === */
.save-info {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 16px 24px;
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.save-info-main {
    display: flex;
    align-items: center;
    gap: 20px;
}

.save-info-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: #ffd700;
}

.save-info-trainer {
    color: #a0a0a0;
    font-size: 0.9rem;
}

.save-info-stats {
    display: flex;
    align-items: center;
    gap: 20px;
}

/* === Boxes Container === */
.boxes-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.box {
    background: linear-gradient(180deg, #3d5a80 0%, #293241 100%);
    border-radius: 10px;
    padding: 10px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.box-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    cursor: pointer;
    padding: 10px 14px; /* slightly taller for a clearer banner feel */
    border-radius: 6px;
    transition:
        background 0.18s,
        border-color 0.18s,
        box-shadow 0.18s;
    width: 100%;
    box-sizing: border-box;
    /* Stronger purply-blue banner so the header is clearly a distinct part */
    background: linear-gradient(
        90deg,
        rgba(120, 86, 255, 0.22),
        rgba(50, 36, 110, 0.06)
    );
    border: 2px solid rgba(120, 86, 255, 0.28); /* a tad thicker, more visible */
    box-shadow:
        0 1px 0 rgba(255, 255, 255, 0.02) inset,
        0 3px 10px rgba(24, 12, 64, 0.18);
}
/* Ensure the toggle (right-side control) stays visually to the right while the whole header is clickable */
/* .box-header .box-toggle removed — header is now the full clickable target and the small icon has been removed */

.box-header:hover {
    /* stronger purply-blue highlight on hover */
    background: linear-gradient(
        180deg,
        rgba(160, 120, 255, 0.16),
        rgba(100, 80, 220, 0.06)
    );
    border-color: rgba(160, 120, 255, 0.22);
    box-shadow: 0 6px 18px rgba(24, 16, 48, 0.28);
}

.box-title {
    text-align: center;
    font-size: 1rem;
    font-weight: 600;
    color: #ffd700;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    flex: 1;
}

/* .box-toggle rules removed (icon removed from DOM) */

/* collapsed .box-toggle rule removed (no toggle element to rotate) */

.box.collapsed .box-grid {
    display: none;
}

.box.completed {
    position: relative;
}

.box.completed::after {
    content: "✓";
    position: absolute;
    top: 8px;
    right: 40px;
    font-size: 1.2rem;
    color: #4caf50;
}

.box.completed .box-title {
    color: #4caf50;
}

.box-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 4px;
}

/* === Pokemon Slots === */
.pokemon-slot {
    aspect-ratio: 1;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3px;
    transition: all 0.2s ease;
    position: relative;
    cursor: pointer;
}

.pokemon-slot:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.pokemon-slot.empty {
    background: rgba(0, 0, 0, 0.2);
    cursor: default;
}

.pokemon-slot.empty:hover {
    transform: none;
}

.pokemon-slot.marked {
    background: rgba(76, 175, 80, 0.6);
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.8);
}

.pokemon-slot.marked:hover {
    background: rgba(76, 175, 80, 0.8);
}

/* Shiny marked - golden/sparkle appearance */
.pokemon-slot.shiny-marked {
    background: rgba(255, 215, 0, 0.5);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.8);
    position: relative;
}

.pokemon-slot.shiny-marked::before {
    content: "✨";
    position: absolute;
    top: 2px;
    left: 2px;
    font-size: 0.6rem;
    z-index: 5;
}

.pokemon-slot.shiny-marked:hover {
    background: rgba(255, 215, 0, 0.7);
}

/* Both normal and shiny marked */
.pokemon-slot.marked.shiny-marked {
    background: linear-gradient(
        135deg,
        rgba(76, 175, 80, 0.6) 0%,
        rgba(255, 215, 0, 0.6) 100%
    );
    box-shadow:
        0 0 8px rgba(76, 175, 80, 0.6),
        0 0 12px rgba(255, 215, 0, 0.6);
}

.pokemon-slot.marked.shiny-marked:hover {
    background: linear-gradient(
        135deg,
        rgba(76, 175, 80, 0.8) 0%,
        rgba(255, 215, 0, 0.8) 100%
    );
}

.pokemon-sprite {
    width: 48px;
    height: 48px;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

.pokemon-name {
    font-size: 0.55rem;
    text-align: center;
    color: #ddd;
    margin-top: 1px;
    word-break: break-word;
    line-height: 1.1;
}

/* === Modal === */
.modal-overlay,
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active,
.modal.active {
    display: flex;
}

.modal-content {
    background: #293241;
    border-radius: 12px;
    padding: 24px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content h2 {
    margin-bottom: 16px;
    color: #ffd700;
}

.modal-content p {
    margin-bottom: 12px;
    color: #a0a0a0;
    font-size: 0.9rem;
}

/* Danger Zone */
.danger-zone {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.3);
    border-radius: 8px;
    padding: 16px;
}

.danger-zone h3 {
    color: #ff6b6b;
    margin-bottom: 8px;
    font-size: 1rem;
}

.danger-zone p {
    font-size: 0.85rem;
    margin-bottom: 12px;
}

/* === Form Elements === */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group select {
    width: 100%;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #3d5a80;
    background: #1a1a2e;
    color: #fff;
    font-size: 14px;
}

.form-group input[type="text"]:focus,
.form-group input[type="email"]:focus,
.form-group input[type="password"]:focus,
.form-group select:focus {
    outline: none;
    border-color: #ffd700;
}

.form-group input:disabled,
.form-group input.input-disabled {
    background: #0d0d1a;
    color: #666;
    cursor: not-allowed;
    border-color: #2a2a4a;
}

.form-group .hint {
    font-size: 0.8rem;
    color: #666;
    margin-top: 4px;
}

.form-hint {
    font-size: 0.75rem;
    color: #666;
    margin-top: 4px;
    font-style: italic;
}

.modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* === Loading & Error States === */
.loading {
    text-align: center;
    font-size: 1.5rem;
    padding: 50px;
    grid-column: 1 / -1;
}

.error {
    text-align: center;
    color: #ff6b6b;
    padding: 50px;
    grid-column: 1 / -1;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #a0a0a0;
}

.empty-state .icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 1.3rem;
    margin-bottom: 8px;
    color: #fff;
}

.empty-state p {
    margin-bottom: 20px;
}

/* === Back Link === */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #a0a0a0;
    text-decoration: none;
    margin-bottom: 20px;
    transition: color 0.2s;
}

.back-link:hover {
    color: #ffd700;
    text-decoration: none;
}

/* === Preset Info === */
.preset-info {
    text-align: center;
    margin-bottom: 20px;
    color: #a0a0a0;
    font-style: italic;
}

/* === Stats === */
.stats {
    text-align: center;
    margin-bottom: 10px;
    color: #a0a0a0;
    font-size: 0.9rem;
}

/* === Responsive Design === */
@media (max-width: 800px) {
    .boxes-container {
        grid-template-columns: 1fr;
    }

    .saves-grid {
        grid-template-columns: 1fr;
    }

    .header {
        flex-direction: column;
        text-align: center;
    }

    .save-info {
        flex-direction: column;
        text-align: center;
    }

    .save-info-main {
        flex-direction: column;
    }
}

@media (max-width: 600px) {
    body {
        padding: 12px;
    }

    .box-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 2px;
    }

    .pokemon-sprite {
        width: 36px;
        height: 36px;
    }

    .pokemon-name {
        font-size: 0.45rem;
    }

    .controls {
        flex-direction: column;
    }

    .controls select {
        min-width: 100%;
    }

    .modal {
        padding: 16px;
        width: 95%;
    }

    .modal-buttons {
        flex-direction: column;
    }

    .modal-buttons .btn {
        width: 100%;
        justify-content: center;
    }
}

/* === Footer === */
.footer {
    margin-top: 3rem;
    padding: 1.5rem;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
}

.footer p {
    margin: 0.25rem 0;
}

.footer a {
    color: var(--text-secondary);
    text-decoration: underline;
}

.footer a:hover {
    color: var(--text-primary);
}

.footer .disclaimer {
    margin-top: 0.5rem;
    font-size: 0.65rem;
    opacity: 0.8;
}
