/* ===================================
   Reset and Base Styles
   =================================== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #fafafa;
    padding: 0;
    margin: 0;
}

main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px 40px;
}

/* ===================================
   Header Styles
   =================================== */

header {
    background: linear-gradient(135deg, #667eea 0%, #8fa2e0 100%);
    color: white;
    padding: 10px 20px 10px;
    text-align: center;
    margin-bottom: 40px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5em;
    font-weight: 600;
    margin-bottom: 10px;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1.1em;
    opacity: 1;  /* Full opacity for better visibility */
    font-weight: 400;  /* Slightly bolder for better readability */
    margin-top: 10px;
    color: white;  /* Explicit white color like the title */
}

/* ===================================
   Typography
   =================================== */

h1 {
    text-align: center;
    margin-bottom: 0;
}

h2 {
    color: #2c3e50;
    font-size: 1.8em;
    font-weight: 600;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid #667eea;
    display: inline-block;
}

h3 {
    color: #34495e;
    font-size: 1.3em;
    font-weight: 600;
    margin-bottom: 10px;
}

p {
    margin-bottom: 15px;
    color: #555;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ===================================
   Section Styles
   =================================== */

.intro {
    background: white;
    padding: 30px 40px;
    border-radius: 8px;
    margin-bottom: 50px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.intro h2 {
    margin-top: 0;
}

.intro p {
    font-size: 1.05em;
    line-height: 1.7;
}

.mode-selection {
    margin-top: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.mode-selection ul {
    margin: 15px 0 15px 25px;
}

.mode-selection li {
    margin-bottom: 10px;
    line-height: 1.7;
}

.mode-selection a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.mode-selection a:hover {
    text-decoration: underline;
}

.mode-selection em {
    color: #28a745;
    font-weight: 500;
}

/* Progress summary in gallery */
.progress-summary {
    margin-top: 25px;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #8fa2e0 100%);
    border-radius: 8px;
    color: white;
}

.progress-stats {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.progress-label {
    font-weight: 600;
    font-size: 1.1rem;
}

.progress-numbers {
    font-size: 1rem;
    opacity: 0.95;
}

.progress-bar-mini {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 5px;
}

.progress-fill-mini {
    height: 100%;
    background: white;
    transition: width 0.3s ease;
}

.level-section {
    margin-bottom: 60px;
}

.level-section h2 {
    margin-bottom: 30px;
}

/* ===================================
   Challenge Gallery (TurtleChallenges.html)
   =================================== */

.level-section > div {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 0;
}

figure {
    background: white;
    border-radius: 8px;
    padding: 20px;
    margin: 0;
    display: inline-block;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.08);
    position: relative;
}

figure:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3);
}

/* Completed challenge cards */
a.completed figure {
    background: linear-gradient(135deg, #f5fdf8 0%, #e8f5e9 100%);
    border: 1px solid #c8e6c9;
}

a.completed figure:hover {
    box-shadow: 0 5px 15px rgba(76, 175, 80, 0.25);
}

/* Completion badge: the student's own "I finished this", top right.
   24px, not 22px, because plenty of these Chromebooks are touchscreens and
   24px is the smallest comfortable target. */
.completion-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: #4caf50;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    z-index: 5;
}

/* Review pin: the teacher's verdict, top left. One per card, never two.
   The states are ranked in index.html so only one is ever drawn. Color alone
   does not carry the meaning: every pin gets a title and an aria-label. */
.review-pin {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: bold;
    line-height: 1;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    z-index: 5;
    cursor: help;
}

.review-pin.pin-unread {
    background: #ef4444;
}

.review-pin.pin-redo {
    background: #f59e0b;
}

.review-pin.pin-approved,
.review-pin.pin-reviewed {
    background: #3b82f6;
}

/* Unread is the one thing a student must not walk past */
.review-pin.pin-unread {
    animation: pin-pulse 2s ease-out 3;
}

@keyframes pin-pulse {
    0%, 100% { box-shadow: 0 2px 4px rgba(0,0,0,0.15); }
    50% { box-shadow: 0 2px 4px rgba(0,0,0,0.15), 0 0 0 6px rgba(239, 68, 68, 0.25); }
}

@media (prefers-reduced-motion: reduce) {
    .review-pin.pin-unread {
        animation: none;
    }
}

/* One line naming what needs attention, above the intro.
   Without it the pins are invisible on arrival: at 1366x610 the first card
   sits about 900px down the page. */
.feedback-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.85rem;
    margin-bottom: 1.5rem;
    padding: 0.85rem 1.25rem;
    background: #fff5f5;
    border: 1px solid #fecaca;
    border-left: 4px solid #ef4444;
    border-radius: 8px;
    font-size: 0.95rem;
    color: #7f1d1d;
}

.feedback-summary.is-redo {
    background: #fffbeb;
    border-color: #fde68a;
    border-left-color: #f59e0b;
    color: #7c4a08;
}

.feedback-summary a {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
}

.feedback-summary a:hover {
    text-decoration: none;
}

.feedback-summary-more {
    opacity: 0.75;
}

/* Instructor triage badges. Only drawn in "View as Student" mode, where they
   answer a different question from the review pin: what have I not looked at
   yet. Students never see these. */
.reviewed-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: #3b82f6;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    z-index: 5;
    cursor: help;
}

.reviewed-badge svg {
    width: 12px;
    height: 12px;
}

.needs-review-badge {
    position: absolute;
    top: 10px;
    left: 10px;
    background: #f59e0b;
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
    z-index: 5;
    cursor: help;
}

figure img {
    width: 140px;
    height: 140px;
    object-fit: contain;
    display: block;
}

figcaption {
    text-align: center;
    font-weight: 600;
    margin-top: 12px;
    color: #34495e;
    font-size: 0.95em;
}

/* ===================================
   Challenge Details (TurtleInstructions.html)
   =================================== */

.challenge {
    background: white;
    padding: 30px;
    margin-bottom: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 30px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.2s ease;
}

.challenge:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.challenge img {
    width: 200px;
    min-width: 200px;
    height: 200px;
    object-fit: contain;
    border-radius: 6px;
    padding: 10px;
    background: #fafafa;
}

.description {
    flex: 1;
    margin: 0;
}

.description p {
    margin-bottom: 10px;
}

.description p:last-child {
    margin-bottom: 0;
}

/* ===================================
   Hints Section
   =================================== */

.show {
    background-color: #f8f9ff;
    border-left: 3px solid #667eea;
    padding: 15px 20px;
    margin-top: 15px;
    border-radius: 4px;
    display: none;
}

.show li {
    margin-bottom: 8px;
    color: #555;
}

.arrow {
    border: solid #667eea;
    border-width: 0 2px 2px 0;
    display: inline-block;
    padding: 4px;
    transform: rotate(45deg);
    margin: 0 5px;
    cursor: pointer;
    transition: border-color 0.2s ease;
}

.arrow:hover {
    border-color: #764ba2;
}

/* ===================================
   Login System Styles
   =================================== */

.auth-buttons {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.login-btn, .logout-btn {
    background: white;
    color: #667eea;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.login-btn:hover, .logout-btn:hover {
    background: #f0f0f0;
    transform: translateY(-1px);
}

.logout-btn {
    background: #fff5f5;
    color: #dc3545;
}

.logout-btn:hover {
    background: #ffe0e3;
}

/* Modal styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

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

.modal-header h2 {
    margin: 0;
    color: #2c3e50;
    border: none;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
}

.tab-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid #ddd;
    background: white;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.tab-btn:hover:not(.active) {
    background: #f8f9fa;
}

.tab-content {
    padding: 10px 0;
}

.name-input, .key-input, .generated-key-input {
    width: 100%;
    padding: 10px;
    margin: 10px 0;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 16px;
}

.name-input:focus, .key-input:focus {
    border-color: #667eea;
    outline: none;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: #667eea;
    color: white;
    width: 100%;
    margin-top: 10px;
}

.btn-primary:hover {
    background: #5567d8;
}

.key-display-box {
    display: flex;
    gap: 10px;
    margin: 20px 0;
}

.generated-key-input {
    flex: 1;
    font-family: monospace;
    font-size: 18px;
    font-weight: bold;
    background: #f8f9fa;
}

.btn-copy {
    background: #28a745;
    color: white;
    padding: 10px 20px;
    white-space: nowrap;
}

.btn-copy:hover {
    background: #218838;
}

.success-message {
    color: #28a745;
    font-weight: 600;
    font-size: 1.1em;
    margin-bottom: 15px;
}

.key-warning {
    background: #fff3cd;
    border: 1px solid #ffc107;
    color: #856404;
    padding: 10px;
    border-radius: 6px;
    margin-top: 15px;
    font-size: 0.9em;
}

.modal-compact {
    max-width: 400px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
}

.btn-warning {
    background: #dc3545;
    color: white;
}

.btn-warning:hover {
    background: #c82333;
}

/* ===================================
   Responsive Design
   =================================== */

@media only screen and (max-width: 768px) {
    header h1 {
        font-size: 2em;
    }

    .subtitle {
        font-size: 1em;
    }

    .intro {
        padding: 20px 25px;
    }

    .challenge {
        flex-direction: column;
        padding: 20px;
    }

    .challenge img {
        width: 100%;
        max-width: 250px;
        min-width: auto;
    }

    .description {
        width: 100%;
    }

    figure {
        padding: 15px;
    }
}

@media only screen and (min-width: 880px) {
    .challenge img {
        width: 220px;
        min-width: 220px;
        height: 220px;
    }
}

@media only screen and (min-width: 1200px) {
    .challenge img {
        width: 240px;
        min-width: 240px;
        height: 240px;
    }
}

/* A challenge handed in and waiting for the teacher */
.review-pin.pin-turned-in {
    background: #2563eb;
    font-size: 11px;
}

.level-subtitle {
    margin-left: 0.5rem;
    font-size: 0.6em;
    font-weight: 400;
    opacity: 0.75;
}

/* Text set from the level files: `code` and links */
.challenge .description code {
    padding: 0.1em 0.35em;
    border-radius: 4px;
    background: #eef1f5;
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.92em;
}

/* ===================================
   The home page (js/gallery.js)
   =================================== */

.home-top {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.home-top:empty {
    display: none;
}

.home-card {
    display: flex;
    gap: 14px;
    padding: 16px;
    border: 1px solid #dfe4ec;
    border-radius: 12px;
    background: white;
}

.home-card.is-attention {
    border: 2px solid #c77700;
}

.home-card-picture {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 84px;
    height: 84px;
    border: 1px solid #dfe4ec;
    border-radius: 8px;
}

.home-card-picture img {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.home-card-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.home-card-kicker {
    font-size: 0.8rem;
    font-weight: 700;
    color: #3f4958;
}

.home-card.is-attention .home-card-kicker {
    color: #7a4300;
}

.home-card-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1b2330;
}

.home-card-text {
    font-size: 0.9rem;
    line-height: 1.4;
    color: #333c4a;
}

.home-card-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 6px;
}

.home-btn {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid #c9d1dd;
    border-radius: 8px;
    background: white;
    color: #1b2330;
    font-size: 0.9rem;
    font-weight: 600;
}

.home-btn:hover {
    border-color: #667eea;
}

.home-btn.is-primary {
    border-color: #1d5fd1;
    background: #1d5fd1;
    color: white;
}

.home-btn.is-primary:hover {
    background: #174ba6;
}

.home-link {
    padding: 0;
    border: none;
    background: none;
    color: #1d5fd1;
    font: inherit;
    font-size: 0.9rem;
    text-decoration: underline;
    cursor: pointer;
}

.home-standing-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.95rem;
    color: #1b2330;
}

.home-standing-number {
    font-weight: 700;
}

.home-standing-number.is-approved { color: #0b5d33; }
.home-standing-number.is-turned-in { color: #1a4699; }
.home-standing-number.is-redo { color: #7a4300; }

.home-bar,
.level-head-bar {
    display: block;
    height: 8px;
    overflow: hidden;
    border-radius: 4px;
    background: #dfe4ec;
}

.home-bar {
    margin-top: 8px;
}

.home-bar > div,
.level-head-bar > span {
    display: block;
    height: 100%;
    background: #1d5fd1;
}

/* The introduction, folded away once a student has work */
details.intro {
    margin-bottom: 24px;
    padding: 16px 24px;
}

details.intro > summary {
    font-size: 1rem;
    font-weight: 600;
    color: #2c3e50;
    cursor: pointer;
}

details.intro[open] > summary {
    margin-bottom: 16px;
}

.home-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 28px;
}

.home-filter {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid #c9d1dd;
    border-radius: 18px;
    background: white;
    color: #1b2330;
    font: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}

.home-filter.is-on {
    border-color: #1b2330;
    background: #1b2330;
    color: white;
    font-weight: 600;
}

.home-filter-count {
    font-size: 0.8rem;
    opacity: 0.75;
}

.home-empty {
    padding: 40px 0;
    text-align: center;
}

.level-block {
    margin-bottom: 44px;
}

.level-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    margin-bottom: 16px;
}

.level-head h2 {
    margin: 0;
    padding: 0;
    border: none;
    font-size: 1.4rem;
}

.level-head-title {
    flex: 1;
    color: #4b5565;
}

.level-head-bar {
    width: 180px;
}

.level-head-count {
    font-size: 0.85rem;
    font-weight: 600;
    color: #4b5565;
    white-space: nowrap;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    border: 1px solid #dfe4ec;
    border-radius: 12px;
    background: white;
    color: #1b2330;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.tile:hover {
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.25);
}

.tile-picture {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 130px;
}

.tile-picture img {
    max-width: 100%;
    width: 120px;
    height: 120px;
    object-fit: contain;
}

.tile-foot {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tile-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chip {
    flex: none;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.chip.is-approved { background: #dff3e6; color: #0b5d33; }
.chip.is-turned-in,
.chip.is-resent { background: #e1ebfb; color: #1a4699; }
.chip.is-redo { background: #fdecc8; color: #7a4300; }
.chip.is-working { background: #eceff4; color: #3f4958; }
.chip.is-new { background: #fde2e2; color: #9b1c1c; }

@media only screen and (max-width: 768px) {
    .tile-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .tile-picture {
        height: 100px;
    }

    .tile-picture img {
        width: 90px;
        height: 90px;
    }

    .level-head-bar {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tile {
        transition: none;
    }
}

/* ===================================
   The plain header. No color and no bar: a title, a line under it, and a
   dark rule. This replaces the gradient header above, which is left only
   because these rules are easier to read as one block.
   =================================== */

header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 24px;
    width: min(1160px, calc(100% - 40px));
    margin: 0 auto 32px;
    padding: 24px 0 16px;
    border-bottom: 2px solid #1b2330;
    background: none;
    box-shadow: none;
    color: #1b2330;
    text-align: left;
}

.header-title {
    flex: 1;
    min-width: 0;
}

header h1 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    text-align: left;
}

header .subtitle {
    margin: 4px 0 0;
    font-size: 0.95rem;
    color: #5a6474;
}

#headerProgress:not(:empty)::before {
    content: " - ";
}

.header-links {
    display: flex;
    align-items: baseline;
    gap: 20px;
}

.header-links a,
.header-links .login-btn,
.header-links .logout-btn {
    padding: 0;
    border: none;
    border-radius: 0;
    background: none;
    color: #1b2330;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 400;
    text-decoration: underline;
    cursor: pointer;
    transform: none;
}

.header-links a:hover,
.header-links .login-btn:hover,
.header-links .logout-btn:hover {
    background: none;
    color: #000;
    text-decoration: none;
    transform: none;
}

@media only screen and (max-width: 768px) {
    header h1 {
        font-size: 1.4rem;
    }
}
