:root {
    color-scheme: light;
    --bg: #f5f7f9;
    --panel: #ffffff;
    --panel-soft: #eef3f7;
    --text: #17212b;
    --muted: #667382;
    --line: #d9e0e7;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --danger: #b42318;
    --warning: #9a5b13;
    --success: #167647;
    --accent: #c47f16;
    --info: #2f5f98;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a {
    color: var(--brand-dark);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    align-items: center;
    background: #101820;
    color: #fff;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    min-height: 64px;
    padding: 0 28px;
}

.brand {
    color: #fff;
    font-size: 18px;
    font-weight: 700;
}

.nav {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.nav a {
    color: #dce6ee;
    font-size: 14px;
}

.nav .user-chip {
    color: #ffffff;
    font-size: 13px;
}

.container {
    margin: 0 auto;
    max-width: 1180px;
    padding: 28px;
}

.page-header {
    align-items: flex-start;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 22px;
}

.page-header h1 {
    font-size: 30px;
    line-height: 1.2;
    margin: 0;
}

.page-header p {
    color: var(--muted);
    margin: 6px 0 0;
}

.grid {
    display: grid;
    gap: 16px;
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.card h2,
.card h3 {
    margin-top: 0;
}

.metric {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
}

.metric strong {
    color: var(--text);
    display: block;
    font-size: 28px;
    line-height: 1.1;
    margin-top: 4px;
    text-transform: none;
}

.dashboard-focus {
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(0, 1.5fr) minmax(280px, 0.9fr);
}

.focus-card,
.progress-panel,
.panel,
.topic-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.focus-card {
    align-items: flex-end;
    background: linear-gradient(135deg, #ffffff 0%, #eef7f4 100%);
    display: flex;
    gap: 18px;
    justify-content: space-between;
    padding: 24px;
}

.focus-card h2,
.progress-panel h2,
.panel h2,
.topic-card h2,
.topic-card h3 {
    margin: 0;
}

.focus-card p {
    color: var(--muted);
    margin: 8px 0 0;
}

.eyebrow {
    color: var(--brand-dark);
    display: inline-flex;
    font-size: 12px;
    font-weight: 750;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.focus-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
}

.progress-panel {
    align-items: center;
    display: grid;
    gap: 16px;
    grid-template-columns: 96px minmax(0, 1fr);
    padding: 20px;
}

.progress-ring {
    align-items: center;
    aspect-ratio: 1;
    background:
        radial-gradient(circle at center, #fff 58%, transparent 60%),
        conic-gradient(var(--brand) 0deg, var(--brand) var(--progress-deg), var(--panel-soft) var(--progress-deg), var(--panel-soft) 360deg);
    border: 1px solid var(--line);
    border-radius: 999px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.progress-ring strong {
    font-size: 24px;
    line-height: 1;
}

.progress-ring span {
    color: var(--muted);
    font-size: 11px;
}

.metric-strip {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-top: 16px;
}

.metric-tile {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    padding: 14px;
    text-transform: uppercase;
}

.metric-tile strong {
    color: var(--text);
    display: block;
    font-size: 24px;
    line-height: 1.1;
    margin-top: 4px;
    text-transform: none;
}

.section-gap {
    margin-top: 18px;
}

.section-title {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-title h2 {
    margin: 0;
}

.panel {
    padding: 18px;
}

.mini-badge-row {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mini-badge {
    align-items: center;
    display: grid;
    gap: 8px;
    justify-items: center;
    text-align: center;
}

.mini-badge img {
    aspect-ratio: 1;
    height: 72px;
    object-fit: contain;
    width: 72px;
}

.mini-badge span {
    font-size: 12px;
    font-weight: 700;
}

.event-list {
    display: grid;
    gap: 10px;
}

.event-row {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 10px;
    grid-template-columns: 58px minmax(0, 1fr);
    padding-bottom: 10px;
}

.event-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.event-row strong {
    color: var(--success);
}

.event-row span {
    color: var(--muted);
}

.topic-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.topic-card {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 240px;
    padding: 18px;
}

.topic-card-top,
.topic-card-footer,
.topic-card-meta {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: space-between;
}

.topic-card p {
    margin: 0;
}

.topic-card-footer,
.topic-card-meta {
    color: var(--muted);
    font-size: 13px;
    margin-top: auto;
}

.button,
button {
    align-items: center;
    background: var(--brand);
    border: 1px solid var(--brand);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 650;
    gap: 8px;
    justify-content: center;
    min-height: 40px;
    padding: 8px 14px;
    text-decoration: none;
}

.button:hover,
button:hover {
    background: var(--brand-dark);
    text-decoration: none;
}

.button.secondary {
    background: #fff;
    border-color: var(--line);
    color: var(--text);
}

.button.secondary:hover {
    background: var(--panel-soft);
}

.button.danger {
    background: var(--danger);
    border-color: var(--danger);
}

.form-stack {
    display: grid;
    gap: 14px;
}

.form-fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 12px;
    margin: 0;
    padding: 14px;
}

.form-fieldset legend {
    color: var(--text);
    font-size: 14px;
    font-weight: 750;
    padding: 0 6px;
}

.form-hint {
    color: var(--muted);
    font-size: 12px;
    margin: 0;
}

label {
    color: var(--muted);
    display: grid;
    font-size: 13px;
    font-weight: 650;
    gap: 6px;
}

input,
select,
textarea {
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    min-height: 40px;
    padding: 8px 10px;
    width: 100%;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

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

.checkbox-row input {
    min-height: auto;
    width: auto;
}

.table-wrap {
    overflow-x: auto;
}

.topic-media {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
    padding: 18px;
}

.topic-media-item {
    display: grid;
    gap: 14px;
}

.topic-media-item + .topic-media-item {
    border-top: 1px solid var(--line);
    padding-top: 16px;
}

.topic-media-header {
    align-items: flex-start;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.topic-media-header h2 {
    font-size: 20px;
    line-height: 1.2;
    margin: 0;
}

.topic-media-header p {
    color: var(--muted);
    margin: 6px 0 0;
}

.media-frame {
    aspect-ratio: 16 / 9;
    background: #101820;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.media-frame.document {
    aspect-ratio: 4 / 3;
    min-height: min(72vh, 680px);
}

.media-frame iframe,
.media-video {
    border: 0;
    display: block;
    height: 100%;
    width: 100%;
}

.media-video {
    aspect-ratio: 16 / 9;
    background: #101820;
    border-radius: 8px;
    height: auto;
}

.media-image {
    border: 1px solid var(--line);
    border-radius: 8px;
    display: block;
    height: auto;
    max-height: 680px;
    object-fit: contain;
    width: 100%;
}

.media-download {
    align-items: center;
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 14px;
}

.media-download strong,
.media-download span {
    display: block;
}

.media-download span {
    color: var(--muted);
    font-size: 13px;
    margin-top: 3px;
}

.media-actions {
    justify-content: flex-end;
}

.media-attribution {
    color: var(--muted);
    font-size: 12px;
    margin: 0;
}

.row-actions {
    align-items: center;
    gap: 10px;
}

.row-actions form {
    margin: 0;
}

.row-actions .button {
    min-height: 34px;
    padding: 6px 10px;
}

.topic-progress {
    margin-bottom: 18px;
}

.topic-progress h2 {
    margin: 0;
}

.topic-progress-header {
    align-items: baseline;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.topic-progress-header p {
    color: var(--muted);
    margin: 6px 0 0;
}

.topic-progress-header strong {
    color: var(--brand-dark);
    font-size: 26px;
    line-height: 1;
}

.topic-progress-track {
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    height: 16px;
    margin-top: 12px;
    overflow: hidden;
}

.topic-progress-track span {
    background: linear-gradient(90deg, #0f766e 0%, #2e9a90 100%);
    display: block;
    height: 100%;
}

.topic-progress-hint {
    color: var(--muted);
    margin: 10px 0 0;
}

table {
    border-collapse: collapse;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 10px 8px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.badge {
    background: var(--panel-soft);
    border-radius: 999px;
    color: var(--text);
    display: inline-flex;
    font-size: 12px;
    font-weight: 650;
    padding: 3px 9px;
}

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

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

.badge.danger {
    background: #fee4e2;
    color: var(--danger);
}

.flash,
.attempt-result {
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
}

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

.flash.error {
    background: #fee4e2;
    color: var(--danger);
}

.attempt-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.attempt-result {
    background: var(--panel);
    border: 1px solid var(--line);
    padding: 18px;
}

.attempt-result.success {
    border-color: #9bd7b3;
}

.attempt-result.error {
    border-color: #f1aaa4;
}

.attempt-result-header {
    align-items: flex-start;
    display: grid;
    gap: 12px;
    grid-template-columns: 96px minmax(0, 1fr);
}

.attempt-result-header p {
    color: var(--muted);
    margin: 6px 0 0;
}

.result-mark {
    align-items: center;
    background: var(--panel-soft);
    border-radius: 8px;
    display: inline-flex;
    font-size: 13px;
    font-weight: 750;
    justify-content: center;
    min-height: 42px;
    padding: 8px;
}

.attempt-result.success .result-mark {
    background: #dff7ea;
    color: var(--success);
}

.attempt-result.error .result-mark {
    background: #fee4e2;
    color: var(--danger);
}

.attempt-stats {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 14px;
}

.attempt-stat {
    background: var(--panel-soft);
    border-radius: 8px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    padding: 12px;
    text-transform: uppercase;
}

.attempt-stat strong {
    color: var(--text);
    display: block;
    font-size: 22px;
    margin-top: 4px;
    text-transform: none;
}

.reward-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.reward-list span {
    background: #fff7e8;
    border: 1px solid #f1d09c;
    border-radius: 999px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
}

.next-step {
    background: #eef3f7;
    border-radius: 8px;
    display: grid;
    gap: 2px;
    margin-top: 14px;
    padding: 12px;
}

.next-step span,
.next-step small {
    color: var(--muted);
}

.options {
    display: grid;
    gap: 10px;
    margin: 18px 0;
}

.scenario-box {
    background: #eef7f4;
    border-left: 4px solid var(--brand);
    border-radius: 6px;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.option {
    align-items: flex-start;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 10px;
    padding: 12px;
}

.option input {
    margin-top: 4px;
    min-height: auto;
    width: auto;
}

.progress-bar {
    background: var(--panel-soft);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.progress-bar.large {
    height: 12px;
    margin-top: 10px;
}

.progress-bar span {
    background: var(--brand);
    display: block;
    height: 100%;
}

.muted {
    color: var(--muted);
}

.actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.code-box {
    background: #101820;
    border-radius: 8px;
    color: #e6edf3;
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 13px;
    overflow-x: auto;
    padding: 12px;
    white-space: pre-wrap;
}

.filter-toolbar {
    display: grid;
    gap: 12px;
}

.filter-toolbar strong {
    font-size: 13px;
    text-transform: uppercase;
    color: var(--muted);
}

.filter-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.filter-chip {
    align-items: center;
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--text);
    display: inline-flex;
    font-size: 13px;
    font-weight: 700;
    min-height: 38px;
    padding: 8px 14px;
    text-decoration: none;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.filter-chip:hover {
    background: #e4ecef;
    text-decoration: none;
}

.filter-chip.active {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

.badge-list {
    display: grid;
    gap: 10px;
}

.badge-item {
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    gap: 12px;
    padding: 10px;
}

.badge-art {
    aspect-ratio: 1;
    border-radius: 8px;
    flex: 0 0 72px;
    height: 72px;
    object-fit: contain;
    width: 72px;
}

.badge-zoom-trigger {
    border-radius: 10px;
    display: inline-flex;
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.badge-zoom-trigger:hover {
    box-shadow: 0 10px 24px rgba(16, 24, 32, 0.14);
    text-decoration: none;
    transform: scale(1.04);
}

.badge-lightbox {
    inset: 0;
    opacity: 0;
    pointer-events: none;
    position: fixed;
    transition: opacity 0.18s ease;
    z-index: 40;
}

.badge-lightbox:target {
    opacity: 1;
    pointer-events: auto;
}

.badge-lightbox-backdrop {
    background: rgba(16, 24, 32, 0.72);
    inset: 0;
    position: absolute;
}

.badge-lightbox-dialog {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(16, 24, 32, 0.35);
    left: 50%;
    max-width: min(92vw, 560px);
    padding: 20px;
    position: absolute;
    text-align: center;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
}

.badge-lightbox-dialog strong {
    display: block;
    font-size: 20px;
    margin-top: 10px;
}

.badge-lightbox-art {
    aspect-ratio: 1;
    display: block;
    height: auto;
    margin: 8px auto 0;
    max-height: 58vh;
    max-width: 100%;
    object-fit: contain;
    width: min(100%, 360px);
}

.badge-lightbox-close {
    align-items: center;
    background: var(--panel-soft);
    border-radius: 999px;
    color: var(--text);
    display: inline-flex;
    font-size: 12px;
    font-weight: 700;
    justify-content: center;
    margin-left: auto;
    min-height: 34px;
    padding: 6px 12px;
}

.badge-lightbox-close:hover {
    background: #dde6ec;
    text-decoration: none;
}

@media (max-width: 760px) {
    .topbar,
    .page-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .container {
        padding: 20px;
    }

    .grid-2,
    .grid-3,
    .dashboard-focus,
    .metric-strip,
    .topic-grid,
    .attempt-stats {
        grid-template-columns: 1fr;
    }

    .focus-card,
    .section-title {
        align-items: flex-start;
        flex-direction: column;
    }

    .focus-actions,
    .attempt-actions,
    .media-download {
        width: 100%;
    }

    .focus-actions .button,
    .attempt-actions .button,
    .media-download .button,
    .media-actions .button {
        width: 100%;
    }

    .topic-media-header,
    .media-download {
        align-items: stretch;
        flex-direction: column;
    }

    .topic-progress-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .progress-panel,
    .attempt-result-header {
        grid-template-columns: 1fr;
    }

    .mini-badge-row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
