/* ==========================================================================
   Matek Érettségi Navigátor
   Same design language as rapcsak.com: light-first, one accent, no noise.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f1f3f6;
    --border: #e3e6eb;
    --text: #15181e;
    --text-2: #4b5563;
    --text-3: #7b8494;
    --accent: #2457c5;
    --accent-hover: #1c47a3;
    --accent-soft: #e8eefb;
    --on-accent: #ffffff;
    --danger: #b42318;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04);

    --radius: 12px;
    --radius-sm: 8px;
    --header-h: 64px;
    --toolbar-h: 56px;
    --gutter: 16px;
    --max-w: 1120px;

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f1115;
        --surface: #161a21;
        --surface-2: #1d222b;
        --border: #272d38;
        --text: #e8eaee;
        --text-2: #aab2bf;
        --text-3: #7f8896;
        --accent: #8ab0ff;
        --accent-hover: #a5c2ff;
        --accent-soft: rgba(138, 176, 255, 0.12);
        --on-accent: #0f1115;
        --danger: #f08a80;
        --shadow: none;
    }
}

:root[data-theme="dark"] {
    --bg: #0f1115;
    --surface: #161a21;
    --surface-2: #1d222b;
    --border: #272d38;
    --text: #e8eaee;
    --text-2: #aab2bf;
    --text-3: #7f8896;
    --accent: #8ab0ff;
    --accent-hover: #a5c2ff;
    --accent-soft: rgba(138, 176, 255, 0.12);
    --on-accent: #0f1115;
    --danger: #f08a80;
    --shadow: none;
}

/* ---------- Base ---------- */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-h) + var(--toolbar-h) + 16px);
    -webkit-text-size-adjust: 100%;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

main {
    flex: 1;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.25;
    letter-spacing: -0.01em;
    font-weight: 600;
}

p {
    margin: 0;
}

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

a:hover {
    color: var(--accent-hover);
}

ul, ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

img {
    display: block;
    max-width: 100%;
    height: auto;
}

figure {
    margin: 0;
}

button {
    font: inherit;
    color: inherit;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

.icon {
    width: 1.1em;
    height: 1.1em;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.container {
    width: 100%;
    max-width: var(--max-w);
    margin: 0 auto;
    padding-left: var(--gutter);
    padding-right: var(--gutter);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.2;
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    color: var(--on-accent);
}

.btn-secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

.btn-secondary:hover {
    border-color: var(--text-3);
    color: var(--text);
}

.btn-secondary[aria-pressed="true"] {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}

.icon-btn:hover {
    color: var(--text);
    border-color: var(--text-3);
}

.icon-btn .icon {
    width: 18px;
    height: 18px;
}

/* ---------- Header ---------- */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
    background: var(--bg);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.nav {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    min-width: 0;
}

.brand:hover {
    color: var(--text);
}

.brand .icon {
    color: var(--accent);
    width: 20px;
    height: 20px;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 0.925rem;
    font-weight: 500;
}

.nav-link:hover {
    color: var(--text);
    background: var(--surface-2);
}

.lang-switch {
    display: inline-flex;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
}

.lang-btn {
    padding: 4px 10px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--text-3);
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
}

.lang-btn[aria-pressed="true"] {
    background: var(--text);
    color: var(--bg);
}

/* Theme toggle: show the icon of the theme you would switch TO */
.icon-moon { display: none; }
.icon-sun  { display: block; }

:root[data-theme="dark"] .icon-moon { display: block; }
:root[data-theme="dark"] .icon-sun  { display: none; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-moon { display: block; }
    :root:not([data-theme="light"]) .icon-sun  { display: none; }
}

/* ---------- Footer ---------- */
.site-footer {
    border-top: 1px solid var(--border);
    padding: 24px 0;
    font-size: 0.875rem;
    color: var(--text-3);
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px 24px;
}

/* ==========================================================================
   Index: year grid
   ========================================================================== */
.intro {
    padding: 40px 0 28px;
}

.intro h1 {
    font-size: clamp(1.5rem, 3.5vw, 2rem);
    letter-spacing: -0.02em;
    margin-bottom: 10px;
}

.intro .lead {
    color: var(--text-2);
    max-width: 62ch;
}

.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 20px;
    margin-top: 16px;
    font-size: 0.875rem;
    color: var(--text-3);
}

.stats strong {
    color: var(--text);
    font-weight: 600;
}

.year-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding-bottom: 48px;
}

.year {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.15s;
}

.year:hover {
    border-color: var(--text-3);
}

.year h2 {
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
}

.set-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.set-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background-color 0.15s, color 0.15s;
}

.set-link .icon {
    color: var(--text-3);
}

.set-link:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.set-link:hover .icon {
    color: var(--accent);
}

/* ==========================================================================
   Exam viewer
   ========================================================================== */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 6px 6px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 0.925rem;
    font-weight: 500;
    white-space: nowrap;
}

.back-link:hover {
    color: var(--text);
    background: var(--surface-2);
}

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

/* Toolbar sticks under the header */
.toolbar {
    position: sticky;
    top: var(--header-h);
    z-index: 90;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.toolbar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 10px;
    padding-bottom: 10px;
}

.q-index {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1 1 auto;
    min-width: 0;
}

.q-index::-webkit-scrollbar {
    display: none;
}

.q-index a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 0.875rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    transition: background-color 0.15s, color 0.15s;
}

.q-index a:hover {
    background: var(--surface-2);
    color: var(--text);
}

.q-index a.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.q-index a.is-timing::after {
    content: "";
    width: 6px;
    height: 6px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--accent);
}

.q-index a.unavailable {
    color: var(--text-3);
    text-decoration: line-through;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-left: auto;
}

.total-time {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 0.875rem;
    white-space: nowrap;
}

.total-time .icon {
    color: var(--text-3);
}

.total-time output {
    font-family: var(--mono);
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.toolbar .btn {
    height: 36px;
}

.btn-label {
    display: none;
}

/* Question list */
.questions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 20px 0 48px;
}

.question {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 16px;
    min-width: 0;
}

.q-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.q-head h2 {
    font-size: 1.05rem;
}

.timer {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 4px 4px 12px;
    border-radius: 999px;
    background: var(--surface-2);
}

.timer output {
    font-family: var(--mono);
    font-size: 0.925rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-2);
    margin-right: 6px;
}

.timer.is-running output {
    color: var(--accent);
}

.timer .icon-btn {
    width: 30px;
    height: 30px;
    border: 0;
    background: transparent;
}

.timer .icon-btn:hover {
    background: var(--surface);
    color: var(--text);
}

.timer .icon-btn .icon {
    width: 16px;
    height: 16px;
}

.timer.is-running .play-btn {
    background: var(--accent);
    color: var(--on-accent);
}

.timer .icon-pause { display: none; }
.timer.is-running .icon-play  { display: none; }
.timer.is-running .icon-pause { display: block; }

.q-image,
.q-solution {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #fff;
}

.q-image img,
.q-solution img {
    width: 100%;
}

.q-solution {
    border-color: var(--accent);
}

.solution-toggle {
    align-self: flex-start;
}

.solution-toggle .icon-eye-off { display: none; }
.solution-toggle[aria-expanded="true"] .icon-eye     { display: none; }
.solution-toggle[aria-expanded="true"] .icon-eye-off { display: block; }

.q-unavailable {
    padding: 24px 16px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-3);
    font-size: 0.925rem;
    text-align: center;
}

/* Time breakdown dialog */
.dialog {
    width: min(520px, calc(100vw - 32px));
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.dialog::backdrop {
    background: rgba(15, 17, 21, 0.5);
    backdrop-filter: blur(2px);
}

.dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px 12px 20px;
    border-bottom: 1px solid var(--border);
}

.dialog-head h2 {
    font-size: 1.05rem;
}

.dialog-body {
    padding: 16px 20px 20px;
}

.breakdown {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px 12px;
    font-size: 0.875rem;
}

.breakdown .label {
    color: var(--text-2);
    white-space: nowrap;
}

.breakdown .bar {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.breakdown .bar::after {
    content: "";
    display: block;
    height: 100%;
    width: var(--w, 0%);
    background: var(--accent);
    border-radius: inherit;
}

.breakdown .value {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    color: var(--text);
    white-space: nowrap;
}

.breakdown .value small {
    color: var(--text-3);
    font-family: var(--font);
    margin-left: 6px;
}

.breakdown-total {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
    color: var(--text-2);
}

.breakdown-total output {
    font-family: var(--mono);
    font-weight: 600;
    color: var(--text);
}

.empty {
    color: var(--text-3);
    font-size: 0.925rem;
    text-align: center;
    padding: 12px 0;
}

/* ==========================================================================
   Breakpoints
   ========================================================================== */
@media (min-width: 640px) {
    :root {
        --gutter: 24px;
    }

    .intro {
        padding-top: 48px;
    }

    .year-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 16px;
    }

    .btn-label {
        display: inline;
    }

    .question {
        padding: 20px;
    }
}

@media (min-width: 900px) {
    :root {
        --gutter: 32px;
    }

    .intro {
        padding-top: 64px;
    }

    .year-grid {
        gap: 20px;
    }

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

    .questions.two-col .question {
        padding: 16px;
    }
}

@media (max-width: 899px) {
    /* the two-column toggle only makes sense on wide screens */
    #layout-toggle {
        display: none;
    }
}

@media (max-width: 639px) {
    .exam-title {
        font-size: 0.925rem;
    }

    .back-link .back-label {
        display: none;
    }

    .nav-link-label {
        display: none;
    }
}

@media (max-width: 380px) {
    .lang-switch {
        display: none;
    }
}

/* ---------- Print: exam paper + solutions if revealed ---------- */
@media print {
    .site-header,
    .toolbar,
    .site-footer,
    .timer,
    .solution-toggle {
        display: none !important;
    }

    body {
        background: #fff;
        color: #000;
    }

    .questions {
        display: block;
        padding: 0;
    }

    .question {
        border: 0;
        padding: 0 0 16px;
        break-inside: avoid;
    }

    .q-image,
    .q-solution {
        border: 0;
    }
}
