/* === Custom Fonts (for PDF preview) === */
@font-face { font-family: 'Bangers'; src: url('fonts/Bangers-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'PermanentMarker'; src: url('fonts/PermanentMarker-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'PatrickHand'; src: url('fonts/PatrickHand-Regular.ttf') format('truetype'); font-display: swap; }

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

:root {
    --primary: #3B82F6;
    --primary-dark: #2563EB;
    --primary-light: #DBEAFE;
    --bg: #F0F2F5;
    --card: #FFFFFF;
    --text: #1F2937;
    --text-secondary: #6B7280;
    --border: #E5E7EB;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --success: #10B981;

    --gold: #D4A637;
    --gold-light: #FDE68A;
    --gold-dark: #92700C;
    --gold-bg: linear-gradient(145deg, #FFE066 0%, #D4AF37 50%, #B8860B 100%);

    --silver: #94A3B8;
    --silver-light: #CBD5E1;
    --silver-dark: #475569;
    --silver-bg: linear-gradient(145deg, #E2E8F0 0%, #94A3B8 50%, #64748B 100%);

    --bronze: #CD7F32;
    --bronze-light: #F0C88A;
    --bronze-dark: #7C4A1A;
    --bronze-bg: linear-gradient(145deg, #FBBF6E 0%, #CD7F32 50%, #8B5A2B 100%);

    --skull: #4B5563;
    --skull-light: #9CA3AF;
    --skull-dark: #1F2937;
    --skull-bg: linear-gradient(145deg, #9CA3AF 0%, #4B5563 50%, #1F2937 100%);

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.5;
}

/* === Views === */
.view {
    display: none;
    min-height: 100dvh;
}

.view.active {
    display: block;
    animation: view-enter 0.25s ease-out;
}

#view-landing.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.view-center {
    max-width: 480px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.view-form {
    max-width: 540px;
}

/* === Landing === */
.landing-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-medals {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.logo-medals .medal {
    width: 48px;
    height: 48px;
    font-size: 24px;
}

.landing-logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

.btn-text-link {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.9375rem;
    font-family: inherit;
    cursor: pointer;
    padding: 1rem 0;
    margin-top: 0.5rem;
    text-align: center;
    transition: color 0.15s;
}

.btn-text-link:hover {
    color: var(--primary);
}

/* === Recent Classes === */
.recent-classes {
    margin-bottom: 2rem;
}

.recent-classes-title {
    font-size: 0.8125rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-align: center;
}

.recent-class-card {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.875rem 1rem;
    background: var(--card);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: inherit;
    font-size: 1rem;
    text-align: left;
    transition: all 0.15s;
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
}

.recent-class-card:last-child {
    margin-bottom: 0;
}

.recent-class-card:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    background: var(--primary-light);
}

.recent-class-card:active {
    transform: scale(0.98);
}

.recent-class-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.recent-class-chevron {
    flex-shrink: 0;
    color: var(--text-secondary);
    margin-left: 0.5rem;
}

.recent-class-name {
    font-weight: 600;
    color: var(--text);
}

.recent-class-role {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: 99px;
}

.recent-class-role.badge-admin {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.recent-class-role.badge-teacher {
    background: #D1FAE5;
    color: #065F46;
}

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    padding: 0.625rem 1.25rem;
    transition: all 0.15s ease;
    text-decoration: none;
    white-space: nowrap;
    box-sizing: border-box;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

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

.btn-large {
    width: 100%;
    padding: 0.875rem 1.5rem;
    font-size: 1.1rem;
    border-radius: var(--radius);
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Back button — iOS-style chevron */
.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    background: none;
    border: none;
    color: var(--primary);
    padding: 0.5rem 0.75rem;
    margin-left: -0.5rem;
    font-size: 0.9375rem;
    font-family: inherit;
    cursor: pointer;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    transition: background 0.15s;
}

.btn-back:hover {
    background: var(--primary-light);
}

.btn-back svg {
    flex-shrink: 0;
}

/* Header icon buttons */
.btn-icon-header {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.btn-icon-header:hover {
    background: var(--bg);
    color: var(--text);
}

.btn-icon-header:active {
    transform: scale(0.93);
}

/* Close button (panel/modal) */
.btn-icon-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.btn-icon-close:hover {
    background: var(--bg);
    color: var(--text);
}

/* Per-page PDF button */
.btn-page-pdf {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.15s;
}

.btn-page-pdf:hover {
    background: var(--bg);
    color: var(--primary);
}

/* === Forms === */
input[type="text"],
input[type="password"],
input[type="number"] {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label:not(.btn) {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
}

.form-group small {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    margin-top: 0.375rem;
}

/* Checkbox grid (setup form) */
.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9375rem;
    transition: border-color 0.15s;
}

.checkbox-label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}

.inline-add {
    display: flex;
    gap: 0.5rem;
}

.inline-add input {
    flex: 1;
}

/* Tags */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.75rem;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 99px;
    font-size: 0.875rem;
    font-weight: 500;
}

.tag button {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 1.125rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* === Medals (display) === */
.medal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    cursor: default;
    position: relative;
}

.medal-img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    pointer-events: none;
}

.medal-small {
    width: 28px;
    height: 28px;
    cursor: pointer;
    transition: transform 0.15s;
}

.medal-small:hover {
    transform: scale(1.15);
}

.medal-small:active {
    transform: scale(0.9);
}

.medal-small.no-delete {
    cursor: default;
}

.medal-small.no-delete:hover {
    transform: none;
}

/* Kreuz-Overlay (Entwertung) */
.medal-crossed .medal-img {
    opacity: 0.45;
    filter: grayscale(0.4);
}

.medal-cross-overlay {
    position: absolute;
    top: 10%;
    left: 10%;
    width: 80%;
    height: 80%;
    object-fit: contain;
    pointer-events: none;
}

/* Medal context menu */
.medal-menu {
    position: fixed;
    z-index: 500;
    background: var(--card);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,0.15), 0 1px 4px rgba(0,0,0,0.08);
    border: 1px solid var(--border);
    min-width: 160px;
    overflow: hidden;
}

.medal-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.625rem 1rem;
    background: none;
    border: none;
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}

.medal-menu-item:hover {
    background: var(--bg);
}

.medal-menu-item.danger {
    color: var(--danger);
}

.medal-menu-item.danger:hover {
    background: var(--danger-light);
}

/* === Main Header === */
.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.625rem 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    min-height: 48px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
    flex: 1;
}

.header-class-name {
    font-size: 1.125rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.header-class-name.editable {
    cursor: text;
    border-radius: 4px;
    padding: 0 4px;
    margin: 0 -4px;
    outline: none;
    transition: background 0.15s;
}

.header-class-name.editable:hover {
    background: var(--bg);
}

.header-class-name.editable:focus {
    background: var(--primary-light);
    box-shadow: 0 0 0 2px var(--primary);
}

.header-right {
    display: flex;
    gap: 0.125rem;
    flex-shrink: 0;
}

/* Badge / Period trigger */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    border: none;
    font-family: inherit;
    white-space: nowrap;
    flex-shrink: 0;
}

.period-trigger {
    cursor: pointer;
    transition: all 0.15s;
}

.period-trigger:hover {
    background: var(--primary);
    color: white;
}

.period-trigger svg {
    transition: transform 0.2s;
}

/* Badge viewing state — grey when showing a non-active period */
.badge.viewing {
    background: var(--bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.badge.viewing:hover {
    background: var(--border);
    color: var(--text);
}

/* === Period Popover === */
.popover {
    position: fixed;
    z-index: 200;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.06);
    min-width: 220px;
    max-width: 320px;
    border: 1px solid var(--border);
    overflow: hidden;
}

.popover-list {
    padding: 0.375rem 0;
}

/* Popover item row — wraps button + optional activate btn */
.popover-item-row {
    display: flex;
    align-items: center;
    gap: 0;
}

.popover-item-row.viewed {
    background: var(--primary-light);
}

.popover-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    padding: 0.625rem 1rem;
    background: none;
    border: none;
    font-size: 0.9375rem;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}

.popover-item:hover {
    background: var(--bg);
}

.popover-item-row.viewed .popover-item {
    font-weight: 600;
    color: var(--primary);
}

.popover-check-space {
    display: inline-block;
    width: 14px;
}

/* Green "aktiv" label for server-active period */
.popover-active-dot {
    display: inline-flex;
    align-items: center;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--success);
    background: #D1FAE5;
    padding: 0.125rem 0.5rem;
    border-radius: 99px;
    margin-left: auto;
    flex-shrink: 0;
}

/* Activate button inside popover */
.btn-activate {
    padding: 0.25rem 0.625rem;
    margin-right: 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--primary);
    background: none;
    border: 1.5px solid var(--primary);
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.15s;
}

.btn-activate:hover {
    background: var(--primary);
    color: white;
}

.popover-footer {
    padding: 0.625rem;
    border-top: 1px solid var(--border);
}

.popover-footer .inline-add input {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
}

/* === A4 Pages === */
.student-list {
    padding: 2rem 1rem;
    max-width: 720px;
    margin: 0 auto;
}

.a4-page {
    background: var(--card);
    border-radius: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.03);
    margin-bottom: 2rem;
    max-width: 680px;
    margin-left: auto;
    margin-right: auto;
}

.a4-page:last-child {
    margin-bottom: 0;
}

/* PDF Export All Button (below all A4 pages) */
.pdf-export-all-wrapper {
    display: flex;
    justify-content: center;
    margin: 2rem auto 0;
}

.pdf-export-all-wrapper .btn {
    gap: 0.5rem;
}

/* Side-by-side PDF action buttons */
.pdf-actions-row {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin: 2rem auto 0;
    max-width: 680px;
}

.pdf-actions-row .btn {
    gap: 0.5rem;
}

.a4-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 1.25rem 1.25rem 0.5rem;
}

.a4-page-header-left {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
    flex: 1;
}

.a4-student-name {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text);
}

.a4-student-name.clickable {
    cursor: pointer;
    transition: color 0.15s;
}

.a4-student-name.clickable:hover {
    color: var(--primary);
}

.a4-page-subtitle {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.a4-page-header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    padding-top: 0.25rem;
}

.a4-page-number {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.a4-page-body {
    padding: 0.5rem 0 0;
}

/* Subject rows inside A4 page */
.a4-subject-row {
    display: flex;
    align-items: center;
    padding: 0.625rem 1.25rem;
    gap: 0.75rem;
    min-height: 48px;
}

.a4-subject-row:nth-child(even) {
    background: #F8FAFC;
}

.a4-subject-row:last-child {
    border-radius: 0;
}

.a4-subject-row.readonly {
    opacity: 0.55;
}

.a4-subject-name {
    font-weight: 600;
    font-size: 0.9375rem;
    min-width: 110px;
    flex-shrink: 0;
}

.a4-subject-medals {
    flex: 1;
    display: flex;
    gap: 0.25rem;
    flex-wrap: wrap;
    min-height: 28px;
    align-items: center;
}

.no-medals {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* === Medal Action Buttons (rounded square) === */
.a4-medal-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.medal-btn-sm {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06), inset 0 1px 1px rgba(255,255,255,0.2);
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.medal-btn-img {
    width: 26px;
    height: 26px;
    object-fit: contain;
    pointer-events: none;
}

.medal-btn-sm:hover {
    transform: scale(1.08);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15), 0 4px 8px rgba(0,0,0,0.08), inset 0 1px 1px rgba(255,255,255,0.2);
}

.medal-btn-sm:active {
    transform: scale(0.93);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.05);
}

.medal-btn-gold { background: var(--gold-bg); color: var(--gold-dark); border-color: var(--gold); }
.medal-btn-silver { background: var(--silver-bg); color: var(--silver-dark); border-color: var(--silver); }
.medal-btn-bronze { background: var(--bronze-bg); color: var(--bronze-dark); border-color: var(--bronze); }
.medal-btn-skull { background: var(--skull-bg); color: #D1D5DB; border-color: var(--skull); }

/* === Student View (detail) === */
.panel-header {
    padding: 0.75rem 1rem;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.panel-header h2 {
    font-size: 1.25rem;
}

.panel-header .btn-back {
    margin-bottom: 0.25rem;
}

.student-view-content {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.student-subject-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--card);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow);
}

.subject-label {
    font-weight: 600;
    min-width: 100px;
    font-size: 0.9375rem;
}

.subject-medals {
    display: flex;
    gap: 0.375rem;
    flex-wrap: wrap;
    flex: 1;
}

/* === Share === */
.share-card-elevated {
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1), 0 1px 4px rgba(0,0,0,0.06);
    padding: 2rem 1.5rem;
}

.share-success {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 0.5rem;
}

.share-card-elevated h2 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.share-details {
    margin-bottom: 1.5rem;
}

.share-group {
    margin-bottom: 1.25rem;
}

.share-group-header {
    font-weight: 700;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.share-card {
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.share-item {
    padding: 0.5rem 0;
}

.share-item label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    margin-bottom: 0.25rem;
}

.share-value {
    font-size: 1.125rem;
    font-weight: 700;
    font-family: 'SF Mono', 'Fira Code', monospace;
    word-break: break-all;
    cursor: pointer;
    padding: 0.375rem 0.625rem;
    border-radius: 6px;
    background: var(--card);
    transition: background 0.15s;
}

.share-value:hover {
    background: var(--primary-light);
}

.share-value-small {
    font-size: 0.8125rem !important;
}

.share-explanation {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin: 0.5rem 0;
    line-height: 1.4;
}

.share-card-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.share-card-actions .btn {
    flex: 1;
}

/* === Teacher Subject Selection === */
.teacher-subject-container {
    margin-top: 1.5rem;
}

.teacher-subject-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.teacher-subject-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    background: var(--card);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.15s;
}

.teacher-subject-label:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.teacher-subject-label input[type="checkbox"] {
    width: auto;
    accent-color: var(--primary);
}

/* === Settings Slide Panel === */
.panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 300;
    transition: background 0.3s ease;
}

.panel-overlay.active {
    background: rgba(0,0,0,0.3);
}

.slide-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: 100vw;
    background: var(--card);
    z-index: 301;
    box-shadow: -4px 0 24px rgba(0,0,0,0.12);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.slide-panel.active {
    transform: translateX(0);
}

.panel-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-top h2 {
    font-size: 1.125rem;
    font-weight: 700;
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
}

.settings-section {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.settings-section h3 {
    font-size: 0.9375rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-row .name {
    font-weight: 500;
}

.settings-row .name.text-muted {
    opacity: 0.5;
    text-decoration: line-through;
}

.subject-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.toggle-subject-btn,
.rename-subject-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-sm);
}

.toggle-subject-btn.toggled-off {
    opacity: 0.5;
}

.settings-danger {
    border: 1.5px solid var(--danger);
    background: var(--card);
}

.settings-danger h3 {
    color: var(--danger);
}

/* === Share Modal === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    transition: background 0.3s ease;
}

.modal-overlay.active {
    background: rgba(0,0,0,0.4);
}

.modal-content {
    background: var(--card);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.16);
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
    opacity: 1;
}

.modal-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.25rem 0.75rem;
    flex-shrink: 0;
}

.modal-top h2 {
    font-size: 1.125rem;
    font-weight: 700;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.25rem 1.25rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    padding: 0 1.25rem 1.25rem;
    justify-content: flex-end;
}

.modal-actions .btn {
    min-width: 100px;
}

.modal-message {
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.modal-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    transition: border-color 0.15s;
}

.modal-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* === Info Sheet Editor Form === */
.info-sheet-form textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: inherit;
    background: var(--card);
    color: var(--text);
    resize: vertical;
    transition: border-color 0.15s;
}

.info-sheet-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.info-sheet-medal-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.5rem;
}

.info-sheet-medal-row .medal-small {
    cursor: default;
    flex-shrink: 0;
}

.info-sheet-medal-row .medal-small:hover {
    transform: none;
}

.info-sheet-medal-label {
    font-weight: 700;
    font-size: 0.8125rem;
    min-width: 52px;
    flex-shrink: 0;
}

.info-sheet-medal-row input[type="text"] {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.9375rem;
}

/* === Toast === */
#toast-container {
    position: fixed;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    pointer-events: auto;
    max-width: 90vw;
    text-align: center;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast-info { background: var(--text); color: white; }
.toast-error { background: var(--danger); color: white; }
.toast-success { background: var(--success); color: white; }

/* === Loading === */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 0.5rem;
    vertical-align: middle;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 3rem 1rem;
    font-size: 1rem;
}

/* === Animations === */
@keyframes view-enter {
    from { opacity: 0.6; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes medal-pop {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}

.medal-new {
    animation: medal-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Responsive === */
@media (max-width: 600px) {
    .student-list {
        padding: 0.75rem 0;
    }

    .a4-page {
        margin: 0 0 0.75rem 0;
        box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    }

    .a4-page:last-child {
        margin-bottom: 0;
    }

    .a4-page-header {
        padding: 1rem 1rem 0.375rem;
    }

    .a4-student-name {
        font-size: 1.25rem;
    }

    .a4-subject-row {
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .a4-subject-name {
        min-width: 80px;
        font-size: 0.875rem;
    }

    .a4-subject-medals {
        flex: 1;
        min-width: 0;
    }

    .a4-medal-actions {
        flex-basis: 100%;
        justify-content: flex-end;
        padding-top: 0.25rem;
        gap: 8px;
    }

    .medal-btn-sm {
        width: 44px;
        height: 44px;
    }

    .medal-btn-img {
        width: 30px;
        height: 30px;
    }

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

    .teacher-subject-grid {
        grid-template-columns: 1fr;
    }

    .student-subject-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .subject-label {
        min-width: auto;
    }

    .slide-panel {
        width: 100vw;
    }
}

@media (min-width: 601px) {
    .a4-page {
        box-shadow: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.04), 0 0 0 1px rgba(0,0,0,0.03);
    }
}
