:root {
  /* Device shell */
  --pokedex-red: #cc322a;
  --pokedex-red-dark: #991f1a;
  --pokedex-maroon: #642c34;
  --pokedex-gold: #e6d596;
  --pokedex-pink: #b45c64;
  --pokedex-steel-blue: #a7b9d3;
  --pokedex-dark: #4c3434;

  /* Screen */
  --screen-bg-start: #0f2b3a;
  --screen-bg-end: #06141f;
  --screen-text: #e8f4ff;

  /* Status lights */
  --light-ok: #4cd964;
  --light-warn: #ffd60a;
  --light-error: #ff3b30;

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

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background-color: #222;
    color: white;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.pokedex-device {
    background-color: var(--pokedex-red);
    border: 4px solid var(--pokedex-red-dark);
    border-radius: 16px;
    padding: 16px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5), inset 0 0 10px rgba(255,255,255,0.2);
    box-sizing: border-box;
}

.pokedex-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--pokedex-maroon);
    padding-bottom: 10px;
}

.brand {
    font-family: 'Press Start 2P', cursive;
    font-size: 1.2rem;
    color: var(--pokedex-gold);
    text-shadow: 1px 1px 0 var(--pokedex-dark);
    letter-spacing: 2px;
}

.status-lights {
    display: flex;
    gap: 8px;
}

.light {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--pokedex-dark);
    background-color: #555;
    box-shadow: inset -2px -2px 4px rgba(0,0,0,0.5);
    opacity: 0.3;
}

.light.active {
    opacity: 1;
    box-shadow: 0 0 8px currentColor, inset -2px -2px 4px rgba(0,0,0,0.2);
}

.light-ok { color: var(--light-ok); background-color: var(--light-ok); }
.light-warn { color: var(--light-warn); background-color: var(--light-warn); }
.light-error { color: var(--light-error); background-color: var(--light-error); }

.screen-area {
    background-color: var(--pokedex-red);
    border: 16px solid #e0e0e0;
    border-bottom-width: 32px;
    border-radius: 8px 8px 8px 32px;
    padding: 2px;
    margin-bottom: 20px;
    position: relative;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.5);
}

.screen-area::before {
    content: '';
    position: absolute;
    bottom: -24px;
    left: 20px;
    width: 12px;
    height: 12px;
    background-color: var(--pokedex-red);
    border-radius: 50%;
    border: 1px solid var(--pokedex-dark);
}

.screen-content {
    background: linear-gradient(to bottom, var(--screen-bg-start), var(--screen-bg-end));
    border-radius: 4px;
    height: 420px;
    overflow-y: auto;
    color: var(--screen-text);
    padding: 16px;
    box-sizing: border-box;
    position: relative;
}

.state-panel {
    display: none;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    padding-top: 8px;
    overflow-y: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

.state-panel::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.state-panel.active {
    display: flex;
}

.hint-text {
    font-size: 1rem;
    color: var(--pokedex-steel-blue);
}

.preview-container {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

#image-preview {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border: 2px solid var(--pokedex-steel-blue);
    border-radius: 4px;
}

.scanning-animation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.pulsing-bar {
    width: 80%;
    height: 8px;
    background-color: var(--light-ok);
    border-radius: 4px;
    animation: pulse 1s infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.3; transform: scaleX(0.8); }
    to { opacity: 1; transform: scaleX(1); box-shadow: 0 0 10px var(--light-ok); }
}

.pokemon-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--pokedex-steel-blue);
    padding-bottom: 6px;
}

.card-header h2 {
    margin: 0;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.85rem;
    text-transform: capitalize;
    color: var(--pokedex-gold);
}

.id-badge {
    font-family: 'Press Start 2P', cursive;
    font-size: 0.7rem;
    color: var(--pokedex-gold);
}

.sprite-container {
    height: 140px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 12px;
}

#pokemon-sprite {
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
    image-rendering: pixelated;
}

.types-container {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.type-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    color: #fff;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.5);
    border: 1px solid rgba(0,0,0,0.3);
}

.stats-container {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

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

.stat-label {
    width: 45px;
    text-align: right;
    font-weight: bold;
    color: var(--pokedex-steel-blue);
}

.stat-bar-bg {
    flex-grow: 1;
    height: 8px;
    background-color: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar-fill {
    height: 100%;
    background-color: var(--light-ok);
    width: 0%;
    transition: width 0.5s ease-out;
}

.stat-value {
    width: 25px;
    text-align: right;
}

.physical-traits {
    display: flex;
    justify-content: space-around;
    font-size: 0.8rem;
    color: var(--pokedex-steel-blue);
    border-top: 1px dashed rgba(255,255,255,0.2);
    padding-top: 8px;
}

.debug-info {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.7);
    text-align: center;
    margin-top: 8px;
}

.debug-info p {
    margin: 2px 0;
}

.error-message {
    color: var(--light-error);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.error-icon {
    font-size: 3rem;
}

.secondary-btn {
    background-color: var(--pokedex-maroon);
    color: white;
    border: 2px solid var(--pokedex-dark);
    padding: 8px 16px;
    border-radius: 4px;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    margin-top: 16px;
}

.secondary-btn:hover {
    background-color: var(--pokedex-red-dark);
}

.secondary-btn:focus-visible {
    outline: 2px solid var(--pokedex-gold);
    outline-offset: 2px;
}

.controls-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

.input-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.input-btn {
    background-color: var(--pokedex-dark);
    color: white;
    border: 2px solid #222;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: bold;
    text-align: center;
    cursor: pointer;
    text-transform: uppercase;
    box-shadow: 0 4px 0 #222;
}

.input-btn:active {
    transform: translateY(4px);
    box-shadow: none;
}

.input-btn:has(input:focus-visible) {
    outline: 2px solid var(--pokedex-gold);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.scan-btn {
    width: 80px;
    border-radius: 50%;
    background-color: var(--pokedex-red);
    border: 4px solid var(--pokedex-gold);
    padding: 0;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 6px 0 #999;
    transition: all 0.1s;
    height: 80px;
}

.scan-btn:active:not(:disabled) {
    transform: translateY(4px);
    box-shadow: 0 2px 0 #999;
}

.scan-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

.scan-btn:focus-visible {
    outline: 2px solid var(--pokedex-gold);
    outline-offset: 4px;
}

.scan-btn-inner {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--pokedex-steel-blue);
    border: 2px solid var(--pokedex-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 0.9rem;
    color: var(--pokedex-dark);
}

.legal-footer {
    margin-top: 20px;
    font-size: 0.7rem;
    color: #888;
    text-align: center;
    max-width: 400px;
    padding: 0 16px;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .pokedex-device {
        margin: 16px;
        width: calc(100% - 32px);
    }
}
