:root {
    /* Pokemon type colors */
    --color-normal: #a8a878;
    --color-fire: #f08030;
    --color-water: #6890f0;
    --color-electric: #f8d030;
    --color-grass: #78c850;
    --color-ice: #98d8d8;
    --color-fighting: #c03028;
    --color-poison: #a040a0;
    --color-ground: #e0c068;
    --color-flying: #a890f0;
    --color-psychic: #f85888;
    --color-bug: #a8b820;
    --color-rock: #b8a038;
    --color-ghost: #705898;
    --color-dragon: #7038f8;
    --color-dark: #705848;
    --color-steel: #b8b8d0;
    --color-fairy: #ee99ac;

    /* UI colors */
    --color-bg: #000;
    --color-text: #fff;
    --color-text-secondary: #fff5e0;
    --color-pokedex: #e61515;
    --color-pokedex-border: #b00000;
    --color-shadow-yellow: rgba(255, 204, 0, 0.7);

    /* Common values */
    --border-radius-standard: 5px;
    --box-shadow-standard: 0 5px 10px rgba(0, 0, 0, 0.3);

    /* Typography */
    --font-family-main:
        -apple-system, BlinkMacSystemFont, "avenir next", avenir, "segoe ui",
        "helvetica neue", "Adwaita Sans", Cantarell, Ubuntu, Roboto, Noto,
        helvetica, arial, sans-serif;
}

html {
    font-size: clamp(12px, 2vw, 18px);
}

body {
    box-sizing: border-box;
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: var(--font-family-main);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 20px;
}

/* Title styling */
.pokedex-title {
    color: #ffcc00;
    font-size: 3rem;
    text-transform: uppercase;
    margin-bottom: 20px;
    letter-spacing: 4px;
    text-shadow:
        0 0 10px var(--color-shadow-yellow),
        0 0 20px rgba(255, 204, 0, 0.5),
        0 0 30px rgba(255, 204, 0, 0.3);
    animation: pulsate 1.5s infinite alternate;
    font-weight: bold;
    max-width: 100%;
    text-align: center;
    transition: all 0.3s ease;
}

/* Pokédex container - base styling */
.pokedex {
    width: 300px;
    height: 500px;
    position: relative;
    perspective: 2000px;
    transform-style: preserve-3d;
    margin: 50px auto;
    transition: width 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border-radius: 0 0 10px 10px;
    background-color: transparent;
}

.pokedex.open {
    width: 600px;
}

.pokedex.closed {
    width: 300px;
}

/* Indicator lights */
.indicator-lights {
    position: absolute;
    top: 12px;
    left: 85px;
    display: flex;
    gap: 10px;
}

.light {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #333;
}

.light.red {
    background: radial-gradient(circle at 40% 40%, #ff9999 0%, #cc0000 100%);
}

.light.yellow {
    background: radial-gradient(circle at 40% 40%, #ffff99 0%, #cccc00 100%);
}

.light.green {
    background: radial-gradient(circle at 40% 40%, #99ff99 0%, #00cc00 100%);
}

.spine {
    position: absolute;
    top: 13%;
    left: 0;
    width: 300px;
    height: 2.5px;
    background-color: #222;
    z-index: 3;
}

/* Hide/Show content based on open/closed state */
/* Panel visibility states */
.pokedex .right-panel {
    visibility: visible;
}

.pokedex.open .right-panel-content,
.pokedex.closed .right-panel-back {
    transition: opacity 0.6s 0.5s;
    opacity: 1;
}

.pokedex.closed .right-panel-content,
.pokedex.open .right-panel-back {
    transition: opacity 0.2s 0.5s ease-in-out;
    opacity: 0;
}

/* Add initial state for right-panel-content to hide it on page load */
.right-panel-content {
    opacity: 0;
}

/* Inner contents styling */
.left-panel-content {
    padding: 20px;
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    visibility: visible;
    transition: clip-path 1.2s ease-in-out;
}

.right-panel-content {
    padding: 20px;
    position: relative;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    perspective: 1px;
    transform-style: preserve-3d;
    transform: rotateY(180deg);
    transition: clip-path 1.2s ease-in-out;
}

.right-panel-back {
    backface-visibility: hidden;
    transition: clip-path 1.2s ease-in-out;
}

/* Pokemon details styling */
.pokemon-name {
    font-size: 20px;
    text-transform: capitalize;
    margin: auto auto 0.5em;
    color: ivory;
}

.pokemon-id {
    margin: auto;
}

.pokemon-entry {
    font-size: 14px;
    margin: 0.5em auto;
}

/* Semantic status messages: colour + left accent bar + monochrome icon.
   Colour is never the only signal (icon + role/aria-live also convey meaning). */
.pokemon-details-area.details-error,
.pokemon-details-area.details-notice,
.pokemon-details-area.details-info,
.pokemon-details-area.details-loading {
    font-weight: 600;
    padding-left: 10px;
    border-left: 3px solid currentColor;
}
.pokemon-details-area.details-error   { color: #ff5a5a; }  /* system failure */
.pokemon-details-area.details-notice  { color: #ffcb05; }  /* user-input issue */
.pokemon-details-area.details-info    { color: #8fd3ff; }  /* prompt / guidance */
.pokemon-details-area.details-loading { color: #4dff4d; }  /* in progress */

.pokemon-details-area.details-error::before   { content: "\2715  "; }        /* X  */
.pokemon-details-area.details-notice::before  { content: "\26A0\FE0E  "; }   /* !  */
.pokemon-details-area.details-info::before    { content: "\2139\FE0E  "; }   /* i  */
.pokemon-details-area.details-loading::before { content: "\27F3  "; }        /* loop */

.pokemon-types,
.pokemon-abilities,
.pokemon-moves,
.pokemon-evolutions {
    font-size: 13px;
    margin: auto;
    text-transform: capitalize;
}

/* Evolution names are clickable buttons styled as inline links */
.evolution-node {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    text-transform: capitalize;
    cursor: pointer;
}
.evolution-node:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
    filter: brightness(1.35);
}


/* Type chips styling */
.type-chip {
    display: inline-block;
    padding: 3px 8px;
    margin: 2px;
    border-radius: 12px;
    text-transform: capitalize;
    font-size: 13px;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
    background-color: var(--type-color, #ccc); /* Default fallback */
}

/* Use CSS variables for type chips */
.type-chip.normal {
    --type-color: var(--color-normal);
}
.type-chip.fire {
    --type-color: var(--color-fire);
}
.type-chip.water {
    --type-color: var(--color-water);
}
.type-chip.electric {
    --type-color: var(--color-electric);
}
.type-chip.grass {
    --type-color: var(--color-grass);
}
.type-chip.ice {
    --type-color: var(--color-ice);
}
.type-chip.fighting {
    --type-color: var(--color-fighting);
}
.type-chip.poison {
    --type-color: var(--color-poison);
}
.type-chip.ground {
    --type-color: var(--color-ground);
}
.type-chip.flying {
    --type-color: var(--color-flying);
}
.type-chip.psychic {
    --type-color: var(--color-psychic);
}
.type-chip.bug {
    --type-color: var(--color-bug);
}
.type-chip.rock {
    --type-color: var(--color-rock);
}
.type-chip.ghost {
    --type-color: var(--color-ghost);
}
.type-chip.dragon {
    --type-color: var(--color-dragon);
}
.type-chip.dark {
    --type-color: var(--color-dark);
}
.type-chip.steel {
    --type-color: var(--color-steel);
}
.type-chip.fairy {
    --type-color: var(--color-fairy);
}

/* Panel Styling */
.left-panel,
.right-panel {
    position: absolute;
    top: 0;
    height: 100%;
    width: 300px;
    box-sizing: border-box;
    transform-style: preserve-3d;
    background-color: var(--color-pokedex);
    border: 3px solid var(--color-pokedex-border);
    box-shadow: var(--box-shadow-standard);
    overflow: hidden;
}

.left-panel {
    left: 0;
    z-index: 1;
    /* Lower z-index so right panel can overlap */
    border-radius: 10px 10px 0 10px;
    transform-origin: right; /* Default origin */
}

.right-panel {
    left: 0;
    top: auto;
    bottom: 0;
    height: calc(87% - 2.5px);
    perspective: 1px;
    transform-origin: bottom right;
    border-radius: 0 0 0 10px;
    border-top: 2px #b00000 solid;
    z-index: 1;
    transition: transform 1.2s ease-in-out;
}

/* When Pokédex is open, rotate the right panel to show content */
.pokedex.open .right-panel {
    transform: rotateY(180deg);
}

/* Camera lens */
.camera-lens {
    position: absolute;
    top: 10px;
    left: 20px;
    width: 30px;
    height: 30px;
    background: radial-gradient(circle at 40% 40%, #7db9e8 0%, #1e5799 100%);
    border-radius: 50%;
    border: 4px solid #fff;
    box-shadow: 0 0 15px rgba(30, 87, 153, 0.7);
    z-index: 10;
    cursor: pointer;
    transition:
        background 0.3s ease,
        box-shadow 0.3s ease,
        transform 0.1s ease;
}

.pokedex.open .camera-lens {
    background: radial-gradient(circle at 40% 40%, #99ff99 0%, #00cc00 100%);
    box-shadow: 0 0 15px rgba(0, 204, 0, 0.7);
}

.camera-lens:active {
    transform: translateY(1px) scale(0.99);
    background: radial-gradient(circle at 40% 40%, #99ff99 0%, #00cc00 100%);
    box-shadow:
        0 0 10px rgba(53, 63, 53, 0.5),
        inset 0 0 15px rgba(0, 204, 0, 0.3);
}

/* Main screen styling */
.main-screen {
    position: relative;
    background-color: #111;
    overflow: hidden;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.8);
    border: 3px solid #222;
    border-radius: 5px;
    width: 80%;
    height: 45%;
    margin: 85px auto 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Pokemon image fullscreen styling */
.pokemon-image {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    cursor: pointer;
    object-fit: contain;
    /* Crisp nearest-neighbour upscaling for the pixel-art sprites */
    image-rendering: -webkit-optimize-contrast;
    image-rendering: pixelated;
}

.pokemon-image.fullscreen {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Loading indicator */
.loading {
    color: #00ff00;
    text-align: center;
}

/* Sprite skeleton: perceived-speed placeholder shown until the sprite paints */
.sprite-skeleton {
    position: absolute;
    inset: 8%;
    border-radius: 8px;
    background-image: linear-gradient(
        100deg,
        rgba(255, 255, 255, 0.05) 30%,
        rgba(255, 255, 255, 0.18) 50%,
        rgba(255, 255, 255, 0.05) 70%
    );
    background-size: 200% 100%;
    animation: sprite-shimmer 1.1s ease-in-out infinite;
    z-index: 5;
    pointer-events: none;
}

.sprite-skeleton.failed {
    animation: none;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #00ff00;
    font-size: 0.9em;
    background-image: none;
    background-color: rgba(0, 0, 0, 0.6);
}

@keyframes sprite-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Search area styling */
.pokemon-search-area {
    display: flex;
    margin-bottom: 10px;
    width: 100%;
    flex-shrink: 0; /* Prevent search area from shrinking */
}

.pokemon-search-input {
    background-color: #222;
    border: 1px solid #444;
    color: ivory;
    padding: 5px;
    flex-grow: 1;
    border-radius: 5px 0 0 5px;
    min-width: 0;
}

.pokemon-search-input:focus {
    outline: none;
}

/* Visible keyboard focus ring on every interactive control (Pokédex yellow,
   readable on both the red shell and the dark screen). */
.pokemon-name-link:focus-visible,
.pokemon-search-input:focus-visible,
.pokemon-search-button:focus-visible,
.blue-button:focus-visible,
.camera-lens:focus-visible,
.yellow-button:focus-visible,
.d-pad-up:focus-visible,
.d-pad-down:focus-visible,
.d-pad-left:focus-visible,
.d-pad-right:focus-visible,
.d-pad-center:focus-visible,
.shortcuts-close:focus-visible,
.evolution-node:focus-visible,
.suggestions-list button:focus-visible,
.suggestions-list [role="option"]:focus-visible {
    outline: 3px solid #ffcb05;
    outline-offset: 2px;
}

.pokemon-search-button {
    background-color: #222;
    border: 1px solid #444;
    color: #d895da;
    cursor: pointer;
    border-radius: 0 5px 5px 0;
    padding: 5px 10px; /* Added padding */
    flex-shrink: 0;
}

.pokemon-search-input,
.pokemon-search-button {
    font-size: 12px;
}

.pokemon-search-button:active {
    background-color: #333;
}

/* Pokemon details display area */
.pokemon-details-area {
    flex-grow: 3;
    overflow-y: auto;
    padding: 5px;
    color: var(--color-text-secondary);
    font-size: 14px;
    max-height: 230px;
    background-color: #181818;
    border-radius: var(--border-radius-standard);
    border: 1px solid #333;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scrollbar-width: thin;
    scrollbar-color: #444 #222;
}

/* Webkit browsers (Chrome, Safari, Edge) */
.pokemon-details-area::-webkit-scrollbar {
    width: 5px;
}

.pokemon-details-area::-webkit-scrollbar-track {
    background: #222;
    border-radius: 5px;
}

.pokemon-details-area::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 5px;
}

.pokemon-details-area::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* D-pad styling */
.d-pad {
    position: relative;
    width: 80px;
    height: 80px;
    background-color: #222;
    border-radius: 50%;
    margin: 45px auto;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.5);
    display: grid;
    grid-template-areas:
        ". up ."
        "left center right"
        ". down .";
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    cursor: pointer;
}

.d-pad-up,
.d-pad-right,
.d-pad-down,
.d-pad-left,
.d-pad-center {
    background-color: #333;
    border: 1px solid #444;
    transition: all 0.1s ease;
}

.d-pad-up {
    grid-area: up;
    border-radius: 5px 5px 0 0;
}

.d-pad-right {
    grid-area: right;
    border-radius: 0 5px 5px 0;
}

.d-pad-down {
    grid-area: down;
    border-radius: 0 0 5px 5px;
}

.d-pad-left {
    grid-area: left;
    border-radius: 5px 0 0 5px;
}

.d-pad-center {
    grid-area: center;
    background-color: #444;
    border-radius: 2px;
}

/* D-pad active state indicators */
.d-pad-up:active,
.d-pad-right:active,
.d-pad-down:active,
.d-pad-left:active,
.d-pad-center:active {
    background-color: #555;
    transform: scale(0.95);
}

/* Yellow corner triangle */
.yellow-button {
    position: absolute;
    top: 40%;
    border-style: solid;
    border-width: 0 30px 30px 30px;
    transform: rotate(90deg);
    border-color: transparent transparent #ffcb05 transparent;
    cursor: pointer;
    width: 0;
    height: 0;
    padding: 15px;
    box-sizing: content-box;
    z-index: 10;
    transition:
        filter 0.2s ease,
        transform 0.1s ease;
}

.yellow-button:hover {
    filter: brightness(1.2);
}

.yellow-button:active {
    transform: scale(0.95) rotate(90deg) translateY(3px);
    filter: brightness(1.1);
}

/* Blue buttons for right panel */
.blue-button-grid {
    display: grid;
    position: absolute;
    bottom: 38px;
    left: 15px;
    right: 15px;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 10px;
    padding: 15px;
    margin-top: 20px;
}

.blue-button {
    height: 30px;
    background: linear-gradient(to bottom, #3498db, #2980b9);
    border: none;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}

.blue-button:active {
    transform: translateY(2px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    background: linear-gradient(to bottom, #2980b9, #2173a8);
}

/* Bottom edge styling */
.bottom-edge {
    position: absolute;
    bottom: 35px;
    left: 80px;
    width: 140px;
    height: 8px;
    background: linear-gradient(to right, #990000, #cc0000, #990000);
    border-radius: 8px;
    z-index: 5;
}

/* Current evolution styling - already styled via JavaScript */
.current-evolution {
    border-radius: 4px;
}

/* Responsive scaling for mobile devices */
@media (max-width: 620px) {
    html {
        zoom: 0.8;
    }
    .pokedex-title {
        margin-top: 25vh;
    }
}
@media (max-width: 500px) {
    html {
        zoom: 0.65;
    }
}

@media (max-width: 400px) {
    html {
        zoom: 0.55;
    }
}

/* Animations */
@keyframes pulsate {
    from {
        text-shadow:
            0 0 10px rgba(255, 204, 0, 0.7),
            0 0 20px rgba(255, 204, 0, 0.5),
            0 0 30px rgba(255, 204, 0, 0.3);
    }
    to {
        text-shadow:
            0 0 15px rgba(255, 204, 0, 0.9),
            0 0 25px rgba(255, 204, 0, 0.7),
            0 0 35px rgba(255, 204, 0, 0.5);
    }
}

/* Offline indicator styling */
.offline-indicator {
    position: fixed;
    top: 10px;
    right: 10px;
    background: linear-gradient(45deg, #ff4444, #cc0000);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    animation: pulse 2s infinite;
    border: 1px solid #aa0000;
}

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

.offline-indicator::before {
    content: "📡";
    margin-right: 5px;
}

/* Specific smooth transitions for interactive elements */
.pokemon-image,
.pokemon-search-input,
.pokemon-search-button,
.type-chip,
.suggestion-button,
.d-pad > div,
.blue-button,
.yellow-button,
.camera-lens {
    transition: all 0.2s ease;
}

/* Enhanced transitions for the modal */
.shortcuts-modal {
    transition:
        transform 0.3s ease,
        opacity 0.3s ease;
}

.shortcuts-overlay {
    transition: all 0.3s ease;
}

/* Keyboard shortcuts help overlay */
.shortcuts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    display: none;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.shortcuts-overlay.active {
    display: flex;
}

.shortcuts-modal {
    background: #1a1a1a;
    border: 2px solid #444;
    border-radius: 10px;
    padding: 25px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 0 30px rgba(255, 204, 0, 0.4);
    color: #fff;
    font-family: var(--font-family-main);
}

.shortcuts-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid #444;
}

.shortcuts-title {
    font-size: 1.5em;
    font-weight: bold;
    color: #f8d030; /* Electric type color for visibility */
    margin: 0;
}

.shortcuts-close {
    background: #777;
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.shortcuts-close:hover {
    background: #999;
}

.shortcuts-content {
    max-height: 70vh;
    overflow-y: auto;
}

.shortcuts-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.shortcuts-list li {
    padding: 10px 0;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
}

.shortcuts-key {
    background: #333;
    padding: 5px 10px;
    border-radius: 4px;
    font-family: monospace;
    min-width: 100px;
    text-align: center;
}

.shortcuts-description {
    flex: 1;
    padding-left: 15px;
    align-self: center;
}

.shortcuts-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.8em;
    color: #aaa;
}

/* Suggestion container and buttons */
.suggestions-container {
    width: 100%;
}

.suggestions-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.suggestion-item {
    margin: 0;
    padding: 0;
}

.suggestion-button {
    width: 100%;
    padding: 10px 15px;
    text-align: left;
    background-color: #2a2a2a;
    border: 1px solid #444;
    color: #d895da;
    cursor: pointer;
    border-radius: 5px;
    font-size: 14px;
    transition: all 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-sizing: border-box;
    min-height: 40px; /* Ensure minimum touch-friendly size */
}

.suggestion-button:hover {
    background-color: #3a3a3a;
    border-color: #666;
}

.suggestion-button:active {
    background-color: #4a4a4a;
    transform: scale(0.98);
}

/* Responsive grid layout for suggestions on larger screens */
@media (min-width: 480px) {
    .suggestions-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 10px;
    }

    .suggestion-button {
        text-align: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

/* Responsive adjustments for suggestion buttons */
@media (max-width: 620px) {
    .suggestion-button {
        font-size: 13px;
        padding: 8px 12px;
        min-height: 36px;
    }
}

/* Respect users who prefer reduced motion: disable the title pulse, sprite
   shimmer, offline-badge pulse, and all transitions/animations. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
}

/* External link on the Pokémon name -> its PokémonDB page */
.pokemon-name-link {
    color: inherit;
    -webkit-text-fill-color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.pokemon-name-link:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

.pokemon-name-link::after {
    content: " \2197"; /* up-right arrow: signals external link */
    font-size: 0.6em;
    vertical-align: super;
    opacity: 0.7;
}
