/* --- Header & Navigation --- */
header h1 {
    color: var(--color-text-primary);
    font-weight: 900;
    font-size: 2.5rem;
    transition: color 0.3s ease;
    text-align: center;
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

#header-logo {
    /* Logo styling without button traits */
    width: 40px;
    height: 40px;
    transition: all 0.3s ease;
    display: block;
    margin: 0 auto;
    gap: 0.75rem;
}

/* Navigation: subtle bottom line with slight corner curvature and thinned edges.
   No hover animations — purely visual indicators using a subtle gradient line
   under the nav and a short active accent under the active button. */
header nav {
    background: transparent;
    box-shadow: none;
    padding: 0;
    border-bottom: 2px solid var(--color-border);
    position: relative;
    top: 2px;
    /* Allow buttons to wrap */
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
}

/* Decorative thin line that thins near the edges via a gradient */
header nav::before {
    content: "";
    position: absolute;
    left: 14px; /* inset so ends look thinner */
    right: 14px;
    bottom: 0;
    height: 2px;
    border-radius: 2px;
    background: linear-gradient(to right,
        rgba(0,0,0,0),
        var(--color-border),
        rgba(0,0,0,0));
    opacity: 0.95;
    pointer-events: none;
}

.nav-button {
    background: transparent;
    color: var(--color-text-secondary);
    font-weight: 700; /* Bolder font */
    font-size: 1.1rem;
    padding: 1rem 1.5rem;
    border-radius: 0;
    border-bottom: 4px solid transparent;
    transition: all 0.2s ease;
}

/* Keep hover non-animated and subtle (no transitions) */
.nav-button:hover {
    color: var(--color-text-secondary);
    background: transparent;
}

/* Active indicator: a short thicker segment under the active button */
.nav-button.active {
    color: var(--color-primary);
    position: relative;
}
.nav-button.active::after {
    content: "";
    position: absolute;
    left: 18%;
    right: 18%;
    bottom: -2px; /* sit on top of the decorative line */
    height: 3px;
    background: var(--color-primary);
    border-radius: 2px;
    pointer-events: none;
}

/* --- Utilities --- */
.hidden {
    display: none !important;
}

/* --- Theme & Settings Toggles --- */
.icon-button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#theme-toggle-button,
#settings-button {
    color: var(--color-text-primary);
}

#theme-toggle-button:hover,
#settings-button:hover {
    color: var(--color-secondary);
    background-color: var(--color-card-bg);
}


.quick-nav-cluster {
    position: absolute;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

@media (min-width: 768px) {
    .quick-nav-cluster {
        top: 2rem;
        left: 2.5rem;
    }
}

.home-link-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    text-align: center;
}

.home-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    padding: 0;
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    text-decoration: none;
    box-shadow: none;
    transition: color 0.2s ease, transform 0.1s ease;
}

.home-button:hover {
    color: var(--color-primary);
    transform: translateY(-1px);
}

.home-icon svg {
    width: 22px;
    height: 22px;
    display: block;
    fill: currentColor;
}

.home-tooltip {
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translate(-50%, -4px);
    padding: 0.2rem 0.55rem;
    border-radius: 8px;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    color: var(--color-text-primary);
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.home-link-wrapper:hover .home-tooltip,
.home-link-wrapper:focus-within .home-tooltip {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* Tag color dropdowns */
.tag-color-select {
    background-color: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-button);
    padding: 0.55rem 2.5rem 0.55rem 0.75rem;
    color: var(--color-text-primary);
    font-weight: 600;
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--color-text-secondary) 50%),
        linear-gradient(135deg, var(--color-text-secondary) 50%, transparent 50%),
        linear-gradient(to right, var(--color-border), var(--color-border));
    background-position: calc(100% - 16px) calc(50% - 2px), calc(100% - 10px) calc(50% - 2px),
        calc(100% - 2.5rem) 0;
    background-size: 6px 6px, 6px 6px, 1px 100%;
    background-repeat: no-repeat;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tag-color-select:focus-visible {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(91, 107, 255, 0.25);
}

/* Dashboard-specific: remove the decorative arrow on the tag color picker */
#tag-color-select {
    /* Remove the composite background (arrows/ divider) used by .tag-color-select */
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: none !important;
    padding-right: 0.75rem !important;
}

#tag-color-select::-ms-expand {
    display: none;
}

.hide-quick-nav .quick-nav-cluster {
    display: none !important;
}

.dashboard-page .quick-nav-cluster {
    display: none !important;
}

#theme-toggle-button svg {
    width: 22px;
    height: 22px;
    color: inherit;
    stroke: currentColor;
    fill: currentColor;
    flex-shrink: 0;
}

/* Icon visibility logic */
body.light-mode #theme-icon-sun { display: none; }
body.light-mode #theme-icon-moon { display: block; }
body:not(.light-mode) #theme-icon-sun { display: block; }
body:not(.light-mode) #theme-icon-moon { display: none; }

/* --- Action Buttons --- */
.main-action-button {
    background-color: var(--color-primary);
    color: white;
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--border-radius-button);
    box-shadow: var(--shadow-sm);
    border: none;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
}
.main-action-button:hover {
    background-color: var(--color-primary-dark);
}
.main-action-button:active {
    transform: scale(0.98);
}

.secondary-action-button {
    background-color: var(--color-card-bg);
    color: var(--color-text-secondary);
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--border-radius-button);
    border: 2px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.secondary-action-button:hover {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    border-color: var(--color-text-secondary);
}
.secondary-action-button:active {
    transform: scale(0.98);
}

.danger-action-button {
    background-color: var(--color-incorrect-light);
    color: var(--color-incorrect);
    font-size: 1rem;
    font-weight: 700;
    border-radius: var(--border-radius-button);
    border: 1px solid var(--color-incorrect);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}
.danger-action-button:hover {
    background-color: var(--color-incorrect);
    color: white;
}
.danger-action-button:active {
    transform: scale(0.98);
}

#share-deck-button {
    background-color: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
    font-weight: 700;
    border-radius: var(--border-radius-button);
    padding: 0.75rem 1.25rem;
    margin-left: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    /* Reset defaults if needed */
    font-family: inherit;
    font-size: 1rem;
}
#share-deck-button:hover {
    background-color: var(--color-primary);
    color: white;
}
body.light-mode #share-deck-button:hover {
    color: white;
}

.continue-button {
    background-color: var(--color-primary);
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    border-radius: var(--border-radius-button);
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.continue-button:hover {
    background-color: var(--color-primary-dark);
}

/* --- Shared Panels/Containers --- */
.panel-container {
    background-color: var(--color-bg-secondary);
    box-shadow: var(--shadow-md);
    border-radius: var(--border-radius-card);
    border: 1px solid var(--color-border);
}

/* --- Toast Notification --- */
#toast-notification {
    background-color: var(--color-card-bg);
    color: var(--color-text-primary);
    font-weight: 600;
    border-radius: var(--border-radius-button);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    padding: 1rem 1.5rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    pointer-events: none;
}
#toast-notification.show {
    opacity: 1;
    transform: translateY(0);
}

/* --- Modals (Shared Structure) --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-overlay.visible {
    visibility: visible;
    opacity: 1;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal-content {
    position: relative;
    background-color: var(--color-bg-secondary);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    color: var(--color-text-primary);
    border-radius: var(--border-radius-card);
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.modal-close-button {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    color: var(--color-text-secondary);
    transition: color 0.2s ease;
    background: none;
    border: none;
    line-height: 1;
    font-size: 1.5rem;
    cursor: pointer;
}
.modal-close-button:hover {
    color: var(--color-text-primary);
}

/* Settings & Keybinds Specifics */
.settings-toggle-button {
    background-color: var(--color-card-bg);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    padding: 0.75rem 1.25rem;
    font-weight: 600;
    border-radius: var(--border-radius-button);
    transition: all 0.2s ease;
    text-align: center;
    cursor: pointer;
}
.settings-toggle-button:hover {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
}
.settings-toggle-button.active {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
    border-color: var(--color-primary);
    font-weight: 700;
}
body.light-mode .settings-toggle-button.active {
    color: var(--color-primary);
}

.keybind-list {
    list-style: none;
    padding-left: 0;
}
.keybind-list li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}
.keybind-list kbd {
    background-color: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    padding: 0.25rem 0.6rem;
    font-family: monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--color-text-primary);
    box-shadow: var(--shadow-sm);
}
.keybind-list span {
    color: var(--color-text-secondary);
}

/* Hide the visible scrollbar in the Keybinds modal while preserving scrollability.
   This keeps the modal aesthetic but allows scrolling with wheel/keyboard/touch. */
#keybinds-modal-content {
    /* Firefox */
    scrollbar-width: none;
    /* IE 10+ */
    -ms-overflow-style: none;
}
#keybinds-modal-content::-webkit-scrollbar {
    width: 0;
    height: 0;
}

/* --- Shared Inputs --- */
.transparent-input {
    background-color: transparent;
    border: none;
    border-bottom: 2px solid var(--color-border);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text-primary);
    padding: 0.5rem 0.25rem;
    transition: border-color 0.2s ease;
    width: 100%;
}
.transparent-input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Range Slider */
input[type=range] {
    appearance: none;
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
}
input[type=range]:focus {
    outline: none;
}
input[type=range]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    margin-top: -8px;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s ease;
}
input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}
input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: var(--color-card-bg);
    border-radius: 4px;
    border: 1px solid var(--color-border);
}
input[type=range]::-moz-range-thumb {
    height: 20px;
    width: 20px;
    border: none;
    border-radius: 50%;
    background: var(--color-primary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform 0.1s ease;
}
input[type=range]::-moz-range-thumb:hover {
    transform: scale(1.1);
}
input[type=range]::-moz-range-track {
    width: 100%;
    height: 6px;
    cursor: pointer;
    background: var(--color-card-bg);
    border-radius: 4px;
    border: 1px solid var(--color-border);
}

/* --- Progress Bar --- */
.progress-bar-container {
    width: 100%;
    height: 12px;
    background-color: var(--color-card-bg);
    border-radius: 6px;
    border: 1px solid var(--color-border);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}
.progress-bar {
    width: 0%;
    height: 100%;
    background-color: var(--color-primary);
    border-radius: 6px;
    transition: width 0.3s ease;
}

/* --- Footer --- */
footer {
    border-top: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    font-size: 0.9rem;
    padding: 2rem 0;
    margin-top: 4rem;
    text-align: center;
}
footer .flex {
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
}
footer .space-x-4 {
    column-gap: 0.75rem;
}
footer .space-x-4 > :not([hidden]) ~ :not([hidden]) {
    margin-left: 0 !important;
}
/* Ensure flex children can shrink/wrap on small screens */
footer .flex > * {
    flex: 0 1 auto;
    min-width: 0;
}

/* Footer links: allow normal wrapping between words and prevent mid-word breaks */
.footer-link {
    display: inline-block;
    white-space: normal;
    word-break: normal;
    overflow-wrap: normal;
    padding: 0 0.25rem;
}
#about-button,
#keybinds-button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-text-secondary);
    font-weight: 600;
    transition: color 0.2s ease;
    padding: 0 0.5rem;
}
#about-button:hover,
#keybinds-button:hover {
    color: var(--color-primary);
}

/* --- Animation Utilities --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in {
    animation: fadeIn 0.3s ease;
}

/* === Term action icons: learned / require-2-correct === */
.term-badge-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    z-index: 60;
}
.term-action-btn {
    position: relative;
    background: none;
    border: none;
    color: var(--color-text-secondary);
    width: 76px;
    height: 76px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    cursor: pointer;
    transition: color 0.15s ease, transform 0.08s ease;
    z-index: 0;
    --term-highlight-color: rgba(255, 255, 255, 0.12);
    --term-highlight-color-active: rgba(255, 255, 255, 0.2);
}

body.light-mode .term-action-btn {
    --term-highlight-color: rgba(66, 87, 178, 0.12);
    --term-highlight-color-active: rgba(66, 87, 178, 0.22);
}

.term-action-btn::after {
    content: "";
    position: absolute;
    inset: 12px;
    border-radius: 10px;
    background-color: var(--term-highlight-color);
    opacity: 0;
    transition: opacity 0.15s ease, transform 0.08s ease, background-color 0.15s ease;
    pointer-events: none;
    z-index: -1;
}

/* no transform here; check buttons handle their own lift behavior */
.term-action-btn:hover {
    color: var(--color-primary);
}
.term-action-btn:hover::after {
    opacity: 1;
}

.term-action-btn svg {
    width: 18px;
    height: 18px;
}

.term-action-btn svg.term-star {
    width: 12px;
    height: 12px;
}

/* active states (JS will toggle .active) */
.term-action-btn.active {
    color: var(--color-primary);
}
.term-action-btn.active::after {
    opacity: 1;
    background-color: var(--term-highlight-color-active);
}

#flashcards-view .term-action-btn {
    --term-highlight-color: var(--color-card-bg);
    --term-highlight-color-active: var(--color-card-bg);
}

    /* Check buttons should appear slightly raised by default and raise further on hover.
       Also nudge the check slightly right (closer to the star) so both icons look balanced. */
    .term-action-btn.term-check {
        transform: translate(34px, -1.1px);
    }
    .term-action-btn.term-check:hover {
        transform: translate(34px, -1.1px);
    }

/* Tooltip */
.term-action-btn .tooltip-text {
    position: absolute;
    top: 50%;
    right: 100%;
    transform: translateY(-50%);
    margin-right: 10px;
    white-space: nowrap;
    background: var(--color-card-bg);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
.term-action-btn:hover .tooltip-text {
    opacity: 1;
    transform: translateY(-50%) translateX(-4px);
}

/* Tooltip caret (small triangle) */
.term-action-btn .tooltip-text::after {
    content: "";
    position: absolute;
    right: -6px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 6px solid var(--color-card-bg);
    filter: drop-shadow(-1px 0 0 rgba(0,0,0,0.03));
}

/* --- Progress Overview (completion screen) --- */
.tnq-progress-overview {
    margin-top: 2rem;
    padding: 1.5rem;
    border-radius: var(--border-radius-card);
    border: 1px solid var(--color-border);
    background: var(--color-bg-secondary);
    box-shadow: var(--shadow-md);
}

.tnq-progress-overview h3 {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--color-text-primary);
    text-align: left;
}

.tnq-progress-content {
    display: grid;
    grid-template-columns: minmax(220px, 320px) 1fr;
    gap: 1.5rem;
    align-items: stretch;
}

.tnq-progress-chart {
    position: relative;
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-card);
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 260px;
}

.tnq-progress-chart canvas {
    width: 100% !important;
    height: 100% !important;
    max-width: 240px;
    max-height: 240px;
}

.tnq-progress-chart-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.tnq-progress-details {
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.tnq-progress-highlight {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-card);
    padding: 1rem 1.25rem;
}

.tnq-progress-highlight .tnq-progress-score {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--color-text-primary);
}

.tnq-progress-highlight .tnq-progress-label {
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.08em;
    color: var(--color-text-secondary);
}

.tnq-progress-improvement {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-top: 0.35rem;
}

.tnq-progress-improvement.positive {
    color: var(--color-correct, #2ecc71);
}

.tnq-progress-improvement.negative {
    color: var(--color-incorrect, #ff5c5c);
}

.tnq-progress-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

.tnq-stat-card {
    background: var(--color-card-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-card);
    padding: 0.85rem 1rem;
}

.tnq-stat-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-secondary);
    margin-bottom: 0.35rem;
}

.tnq-stat-dot {
    width: 11px;
    height: 11px;
    border-radius: 999px;
    border: 1px solid var(--color-border);
    box-shadow: 0 0 0 2px var(--color-card-bg);
}

.tnq-stat-card strong {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--color-text-primary);
}

.tnq-stat-card-total {
    width: 100%;
    grid-column: 1 / -1;
}

.tnq-progress-history {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
}

.tnq-progress-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.tnq-progress-actions:empty,
.tnq-progress-actions.hidden {
    display: none;
}

@media (max-width: 768px) {
    .tnq-progress-content {
        grid-template-columns: 1fr;
    }

    .tnq-progress-chart {
        min-height: 220px;
    }
}