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

:root {
    --primary-color: #edd7c1;
    --primary-dark: #4f46e5;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--primary-color);
    color: white;
    padding: 16px;
    text-align: center; /* center everything inside the header */
}

header .logo {
    display: block;
    margin: 0 auto 12px auto; /* centers logo horizontally */
    max-width: 100%;           /* prevents it from overflowing the header */
    height: auto;              /* keeps original aspect ratio */
}
}



#student-info {
    display: flex;
    gap: 8px;
}

#student-info input {
    flex: 1;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    background: rgba(255, 255, 255, 0.9);
}

#student-info input:focus {
    outline: 2px solid var(--primary-dark);
}

#tab-nav {
    display: flex;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.tab-btn {
    flex: 1;
    padding: 14px;
    border: none;
    background: none;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
}

.tab-btn.active {
    color: var(--primary-color);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
}

.tab-btn span {
    background: var(--primary-color);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    margin-left: 4px;
}

main {
    flex: 1;
    padding: 16px;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

#scanner-container {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin-bottom: 16px;
}

#reader {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
}

#reader video {
    border-radius: 12px;
}

#scan-status {
    text-align: center;
    margin-top: 12px;
    color: var(--text-secondary);
    font-size: 14px;
}

#scan-status.success {
    color: var(--success-color);
    font-weight: 500;
}

#scan-status.error {
    color: var(--error-color);
    font-weight: 500;
}

#last-scanned {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

#last-scanned h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

#last-character {
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    animation: popIn 0.3s ease;
}

@keyframes popIn {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.character-card img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 8px;
}

.character-card .name {
    font-weight: 600;
    font-size: 16px;
    color: var(--text-primary);
}

.character-card .description {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.empty-state {
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    padding: 20px;
}

#collection-header {
    margin-bottom: 16px;
}

#collection-header h2 {
    font-size: 1.25rem;
    margin-bottom: 4px;
}

#progress-text {
    color: var(--text-secondary);
    font-size: 14px;
}

#character-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 12px;
}

.collection-item {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    transition: transform 0.2s;
    min-height: 160px;
}

.collection-item:active {
    transform: scale(0.95);
}

.collection-item img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 8px;
}

.collection-item .name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-word;
    margin-bottom: 4px;
}

.collection-item .description {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
    word-break: break-word;
}

.collection-item.locked {
    opacity: 0.4;
    background: var(--border-color);
}

.collection-item.locked img {
    filter: grayscale(100%);
}

#toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1000;
    transition: opacity 0.3s, transform 0.3s;
}

#toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
}

#toast.success {
    background: var(--success-color);
}

#toast.error {
    background: var(--error-color);
}

#toast.warning {
    background: var(--warning-color);
}

@media (min-width: 480px) {
    #character-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .collection-item img {
        width: 80px;
        height: 80px;
    }
}


#character-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;
    padding: 20px;
}

#character-modal.hidden {
    display: none;
}

.character-modal-content {
    position: relative;
    background: white;
    border-radius: 16px;
    padding: 32px 24px 24px;
    max-width: 400px;
    width: 100%;
    max-height: 85vh;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    overflow-y: auto;
    overflow-x: hidden;
}

.character-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    border: none;
    font-size: 32px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.2s;
}

.character-modal-close:hover {
    background: rgba(0, 0, 0, 0.7);
}


#character-modal-name {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 8px 0 0;
}

#character-modal-type {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 4px 0;
    font-weight: 500;
    text-align: left;
}

#character-modal-powers {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 8px 0;
    line-height: 1.8;
    text-align: left;
}

#character-modal-story {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 8px 0;
    line-height: 1.8;
    text-align: left;
}

.modal-detail {
    display: flex;
    flex-direction: column;
    margin-bottom: 6px;
}

.detail-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.detail-value {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

.collection-item {
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.collection-item:not(.locked):hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
}

.collection-item:not(.locked):active {
    transform: translateY(-2px);
}


/* QR page */
#qr-display-header {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    margin-bottom: 16px;
}
#qr-display-header h2 { font-size: 1.25rem; margin-bottom: 4px; }
#qr-display-header p { color: var(--text-secondary); font-size: 14px; margin-bottom: 12px; }
#display-session-code {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    margin-bottom: 12px;
    box-sizing: border-box;
}
#display-session-code:focus { outline: 2px solid var(--primary-color); border-color: transparent; }
#qr-button-group { display: flex; gap: 10px; }
#generate-qrs-btn, #print-qrs-btn {
    flex: 1;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}
#generate-qrs-btn:active, #print-qrs-btn:active { background: var(--primary-dark); }
#qr-display-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 16px;
}
.qr-display-item {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 12px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.qr-display-item h3 { font-size: 14px; color: var(--text-primary); margin-bottom: 8px; word-break: break-word; }
.qr-code-img {
    width: 150px; height: 150px;
    margin: 0 auto; display: block;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s;
}
.qr-code-img:hover { transform: scale(1.05); }
.qr-char-img { width: 40px; height: 40px; margin-top: 8px; object-fit: contain; }

/* QR Modal */
#qr-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; padding: 20px;
}
#qr-modal.hidden { display: none; }
.qr-modal-content {
    position: relative; background: white;
    border-radius: 12px; padding: 20px;
    max-width: 90vw; max-height: 90vh;
    display: flex; align-items: center; justify-content: center;
}
#qr-modal-img { max-width: 100%; max-height: 100%; width: 800px; height: 800px; }
.qr-modal-close {
    position: absolute; top: 10px; right: 10px;
    background: rgba(0,0,0,0.5); color: white; border: none;
    font-size: 32px; width: 40px; height: 40px;
    border-radius: 50%; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0; transition: background 0.2s;
}
.qr-modal-close:hover { background: rgba(0,0,0,0.7); }

@media print {
    #tab-nav, header, #qr-display-header, #qr-modal { display: none; }
    .qr-display-item { page-break-inside: avoid; break-inside: avoid; margin-bottom: 20px; }
    .qr-code-img { width: 900px; height: 900px; border: 1px solid #000; }
}

@media (min-width: 768px) {
    header h1 { font-size: 2rem; }
    main { padding: 24px; }
    #qr-display-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
/* Center image, name, trainer, and number */
#character-modal img,
#character-modal h2,
#character-modal-trainer,
#character-modal-number {
    text-align: center;
    margin-left: auto;
    margin-right: auto;
    display: block;
}

/* Left-align detail text */
#character-modal-type,
#character-modal-powers,
#character-modal-story {
    text-align: left;
    width: 100%;
}
/* Center the Trainer | Number line (the first <p> after the name) */
#character-modal-name + p {
    text-align: center;
    width: 100%;
}

/* Character modal image */
.character-modal-img {
    width: 200px;
    height: 200px;
    object-fit: cover;
    border-radius: 12px;
    display: block;
    margin: 0 auto 12px;
}

/* QR password modal */
#qr-password-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
#qr-password-modal.hidden { display: none; }

.qr-password-content {
    background: #fff;
    border-radius: 16px;
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    min-width: 260px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.qr-password-content h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-primary);
}
.qr-password-content input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    box-sizing: border-box;
}
.qr-password-content button {
    width: 100%;
    padding: 10px;
    background: var(--primary-color, #e8a87c);
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}
#qr-password-cancel {
    background: #e2e8f0;
    color: #555;
}
#qr-password-error {
    color: #e53e3e;
    font-size: 0.9rem;
    margin: 0;
}
#qr-password-error.hidden { display: none; }