/* Theme variables */
:root {
    --bg: #f5f5f5;
    --bg-tg: #f0f0f0;
    --card-bg: #fff;
    --card-shadow: rgba(0,0,0,0.08);
    --card-shadow-light: rgba(0,0,0,0.06);
    --heading: #1a1a2e;
    --text: #333;
    --text-secondary: #555;
    --hint: #888;
    --hint-light: #aaa;
    --border: #e8e8e8;
    --border-light: #f0f0f0;
    --placeholder: #b0b0b0;
    --hover-bg: #f5f9ff;
    --active-bg: #e8f0fe;
    --link: #2196F3;
    --link-hover: #1565C0;
    --cta-hover: #1976D2;
    --clear-bg: #ccc;
    --clear-hover: #aaa;
    --arrow-color: #ccc;
    --detecting: #666;
    --skeleton-bg: #e8e8e8;
    --check-bg: #fffbf0;
    --check-border: #f5e6c8;
    --apple-bg: #f0f5ff;
    --apple-text: #4a6fa5;
    --scrollbar: #ccc;
    --scrollbar-hover: #aaa;
    --debug-bg: #1a1a2e;
    --debug-toggle-bg: #eee;
    --debug-toggle-color: #999;
    --debug-text: #a0e0a0;
    --toggle-bg: #ddd;
    --toggle-knob: #fff;
    --sun-color: #aaa;
    --moon-color: #555;
}

[data-theme="dark"] {
    --bg: #1a1a1a;
    --bg-tg: #1a1a1a;
    --card-bg: #2a2a2a;
    --card-shadow: rgba(0,0,0,0.3);
    --card-shadow-light: rgba(0,0,0,0.2);
    --heading: #f0f0f0;
    --text: #ddd;
    --text-secondary: #bbb;
    --hint: #999;
    --hint-light: #777;
    --border: #444;
    --border-light: #3a3a3a;
    --placeholder: #666;
    --hover-bg: #333;
    --active-bg: #3a3a3a;
    --link: #64b5f6;
    --link-hover: #90caf9;
    --cta-hover: #1976D2;
    --clear-bg: #555;
    --clear-hover: #777;
    --arrow-color: #666;
    --detecting: #999;
    --skeleton-bg: #3a3a3a;
    --check-bg: #2a2518;
    --check-border: #4a3f2e;
    --apple-bg: #1e2a3a;
    --apple-text: #7aa3d4;
    --scrollbar: #555;
    --scrollbar-hover: #777;
    --debug-bg: #111;
    --debug-toggle-bg: #333;
    --debug-toggle-color: #888;
    --debug-text: #a0e0a0;
    --toggle-bg: #555;
    --toggle-knob: #ddd;
    --sun-color: #999;
    --moon-color: #ccc;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 16px 48px;
    -webkit-font-smoothing: antialiased;
    transition: background 0.3s, color 0.3s;
}

body.tg-mode {
    background: var(--bg-tg);
    padding: 8px 12px;
}

/* Theme toggle — slider switch */
.theme-toggle {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    border-radius: 14px;
    background: var(--toggle-bg);
    border: none;
    cursor: pointer;
    transition: background 0.3s;
    padding: 0;
    vertical-align: middle;
    flex-shrink: 0;
}

.theme-toggle .toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--toggle-knob);
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

[data-theme="dark"] .theme-toggle .toggle-knob {
    transform: translateX(24px);
}

.theme-toggle-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    line-height: 1;
    pointer-events: none;
}

.theme-toggle-icon.sun {
    left: 6px;
}

.theme-toggle-icon.moon {
    right: 5px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 24px;
    width: 100%;
    max-width: 480px;
}

header h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--heading);
    transition: color 0.3s;
}

.tg-mode header {
    display: none;
}

/* Search section */
.search-section {
    width: 100%;
    max-width: 480px;
    margin-bottom: 20px;
    position: relative;
}

.tg-mode .search-section {
    margin-bottom: 12px;
}

#device-search {
    width: 100%;
    padding: 14px 44px 14px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, background 0.3s, color 0.3s;
    background: var(--card-bg);
    color: var(--text);
}

#device-search:focus {
    border-color: var(--link);
}

#device-search::placeholder {
    color: var(--placeholder);
}

.search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: var(--clear-bg);
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s;
}

.search-clear:hover {
    background: var(--clear-hover);
}

.search-clear.hidden {
    display: none;
}

/* States */
.state {
    width: 100%;
    max-width: 480px;
    animation: fadeIn 0.3s ease;
}

.state.hidden {
    display: none;
}

/* Loading skeleton */
.loading-skeleton {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px 24px;
    text-align: center;
    box-shadow: 0 2px 12px var(--card-shadow-light);
    transition: background 0.3s, box-shadow 0.3s;
}

.skeleton-image {
    width: 120px;
    height: 120px;
    border-radius: 20px;
    background: var(--skeleton-bg);
    margin: 0 auto 16px;
}

.skeleton-text {
    height: 20px;
    background: var(--skeleton-bg);
    border-radius: 10px;
    margin: 8px auto;
    width: 60%;
}

.skeleton-text.short {
    width: 40%;
}

.pulse {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

#detecting-text {
    text-align: center;
    margin-top: 16px;
    color: var(--detecting);
    font-size: 14px;
    transition: color 0.3s;
}

/* Result Card */
.result-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 2px 16px var(--card-shadow);
    transition: background 0.3s, box-shadow 0.3s;
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.result-card.result-yes {
    border-top: 4px solid #27ae60;
}

.result-card.result-no {
    border-top: 4px solid #e74c3c;
}

.result-card.result-check {
    border-top: 4px solid #f39c12;
}

/* Device image */
.device-image-wrap {
    margin-bottom: 16px;
}

.device-image-wrap img {
    width: 100px;
    height: 100px;
    object-fit: contain;
    border-radius: 12px;
}

/* Device info */
.device-vendor {
    font-size: 14px;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
    transition: color 0.3s;
}

.device-model {
    font-size: 22px;
    font-weight: 700;
    color: var(--heading);
    margin-bottom: 20px;
    transition: color 0.3s;
}

/* Result badge */
.result-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

.result-badge.badge-yes {
    background: #e8f8ef;
    color: #27ae60;
}

.result-badge.badge-no {
    background: #fde8e8;
    color: #e74c3c;
}

.result-badge.badge-check {
    background: #fef5e7;
    color: #e67e22;
}

[data-theme="dark"] .result-badge.badge-yes {
    background: #1a3a25;
    color: #4cdb80;
}

[data-theme="dark"] .result-badge.badge-no {
    background: #3a1a1a;
    color: #f87171;
}

[data-theme="dark"] .result-badge.badge-check {
    background: #3a2f1a;
    color: #f5b041;
}

/* Result icon animations */
.result-icon {
    display: inline-block;
    font-size: 20px;
    line-height: 1;
}

.result-icon.icon-yes {
    animation: drawCheck 0.5s ease 0.2s both;
}

.result-icon.icon-no {
    animation: fadeInIcon 0.4s ease 0.2s both;
}

.result-icon.icon-check {
    animation: pulseIcon 2s ease infinite;
}

@keyframes drawCheck {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes fadeInIcon {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes pulseIcon {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Check instructions */
.check-instructions {
    text-align: left;
    margin-top: 16px;
    padding: 16px;
    background: var(--check-bg);
    border-radius: 12px;
    border: 1px solid var(--check-border);
    transition: background 0.3s, border-color 0.3s;
}

.check-instructions.hidden {
    display: none;
}

.check-instructions h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
    transition: color 0.3s;
}

.instruction-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    transition: color 0.3s;
}

.instruction-item:last-child {
    margin-bottom: 0;
}

.instruction-icon {
    flex-shrink: 0;
    font-size: 16px;
}

/* Apple note */
.apple-note {
    margin-top: 12px;
    padding: 12px 16px;
    background: var(--apple-bg);
    border-radius: 10px;
    font-size: 13px;
    color: var(--apple-text);
    line-height: 1.5;
    transition: background 0.3s, color 0.3s;
}

.apple-note.hidden {
    display: none;
}

/* CTA Button */
.cta-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding: 14px 32px;
    background: var(--link);
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.cta-button:hover {
    background: var(--cta-hover);
}

.cta-button:active {
    transform: scale(0.98);
}

.cta-button.hidden {
    display: none;
}

.cta-arrow {
    font-size: 18px;
    transition: transform 0.2s;
}

.cta-button:hover .cta-arrow {
    transform: translateX(3px);
}

/* Not your phone */
.not-your-phone {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--hint);
    transition: color 0.3s;
}

.tg-mode .not-your-phone {
    margin-top: 12px;
}

.link-button {
    background: none;
    border: none;
    color: var(--link);
    font-size: 14px;
    cursor: pointer;
    text-decoration: underline;
    padding: 4px 0;
    margin-left: 4px;
}

.link-button:hover {
    color: var(--link-hover);
}

/* Vendor item with logo */
.vendor-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.vendor-logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vendor-logo img {
    max-width: 28px;
    max-height: 28px;
    object-fit: contain;
    transition: filter 0.3s;
}

[data-theme="dark"] .vendor-logo-dark img {
    filter: brightness(0) invert(0.75);
}

.vendor-item-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}

.model-item-count {
    font-size: 13px;
    color: var(--hint-light);
    min-width: 20px;
    text-align: right;
    transition: color 0.3s;
}

.model-item-arrow {
    font-size: 18px;
    color: var(--arrow-color);
    transition: color 0.3s;
}

/* Back item */
.model-item-back {
    color: var(--link);
    font-weight: 500;
}

.back-arrow {
    font-size: 18px;
    margin-right: 6px;
}

.model-list {
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px var(--card-shadow-light);
    max-height: calc(100vh - 200px);
    max-height: calc(100dvh - 200px);
    overflow-y: auto;
    transition: background 0.3s, box-shadow 0.3s;
}

.model-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    transition: background 0.15s;
}

.model-item:last-child {
    border-bottom: none;
}

.model-item:hover {
    background: var(--hover-bg);
}

.model-item:active {
    background: var(--active-bg);
}

.model-item-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.model-item-name {
    font-size: 15px;
    color: var(--text);
    transition: color 0.3s;
}

.model-item-vendor {
    font-size: 12px;
    color: var(--hint);
    margin-top: 2px;
    transition: color 0.3s;
}

.model-item-status {
    font-size: 18px;
    flex-shrink: 0;
}

.no-models {
    text-align: center;
    padding: 24px;
    color: var(--hint);
    font-size: 14px;
    transition: color 0.3s;
}

.no-models.hidden {
    display: none;
}

/* Debug panel */
.debug-panel {
    width: 100%;
    max-width: 480px;
    margin-top: 16px;
}

.debug-panel.hidden {
    display: none;
}

.debug-toggle {
    text-align: center;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1px;
    color: var(--debug-toggle-color);
    cursor: pointer;
    padding: 6px;
    background: var(--debug-toggle-bg);
    border-radius: 8px;
    user-select: none;
    transition: background 0.3s, color 0.3s;
}

.debug-details {
    margin-top: 6px;
    background: var(--debug-bg);
    border-radius: 10px;
    padding: 12px;
    overflow-x: auto;
    transition: background 0.3s;
}

.debug-details.hidden {
    display: none;
}

.debug-details pre {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 11px;
    color: var(--debug-text);
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    line-height: 1.6;
}

/* Bottom bar — always visible */
.bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg);
    font-size: 12px;
    color: var(--hint-light);
    transition: background 0.3s, color 0.3s;
    z-index: 10;
}

.bottom-bar-text {
    transition: color 0.3s;
}

/* Responsive: small phones */
@media (max-width: 380px) {
    body {
        padding: 12px 10px 48px;
    }

    .result-card {
        padding: 24px 16px;
    }

    .device-model {
        font-size: 20px;
    }

    .model-item {
        padding: 12px 12px;
    }

    #device-search {
        padding: 12px 40px 12px 14px;
        font-size: 15px;
    }

    .model-list {
        max-height: calc(100vh - 180px);
        max-height: calc(100dvh - 180px);
    }
}

/* Responsive: short landscape or small viewport height */
@media (max-height: 500px) {
    body {
        padding: 8px 12px 48px;
    }

    header {
        margin-bottom: 12px;
    }

    .search-section {
        margin-bottom: 10px;
    }

    .model-list {
        max-height: calc(100vh - 150px);
        max-height: calc(100dvh - 150px);
    }

    .result-card {
        padding: 20px 16px;
    }

    .device-image-wrap img {
        width: 72px;
        height: 72px;
    }
}

/* Responsive: tablets / wider screens */
@media (min-width: 600px) {
    .state {
        max-width: 520px;
    }

    .search-section {
        max-width: 520px;
    }

    header {
        max-width: 520px;
    }

    .model-list {
        max-height: calc(100vh - 220px);
        max-height: calc(100dvh - 220px);
    }
}

/* TG mode specific */
.tg-mode .result-card {
    box-shadow: none;
    border-radius: 12px;
}

.tg-mode .not-your-phone {
    font-size: 13px;
}

.tg-mode .model-list {
    max-height: calc(100vh - 120px);
    max-height: calc(100dvh - 120px);
}

.tg-mode body, body.tg-mode {
    padding-bottom: 48px;
}

/* Scrollbar styling */
.model-list::-webkit-scrollbar {
    width: 6px;
}

.model-list::-webkit-scrollbar-track {
    background: transparent;
}

.model-list::-webkit-scrollbar-thumb {
    background: var(--scrollbar);
    border-radius: 3px;
}

.model-list::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-hover);
}
