:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-2: #243044;
    --text: #e8edf4;
    --muted: #8b9cb3;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --border: #2d3a4f;
    --radius: 14px;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: linear-gradient(160deg, #0b1020 0%, #111827 45%, #0f172a 100%);
    color: var(--text);
    line-height: 1.6;
}

.container {
    width: min(1100px, 92vw);
    margin: 0 auto;
}

.site-header {
    border-bottom: 1px solid var(--border);
    background: rgba(15, 20, 25, 0.85);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 0;
}

.logo {
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
}

.nav a {
    color: var(--muted);
    text-decoration: none;
    margin-left: 1.25rem;
    font-weight: 500;
}

.nav a.active,
.nav a:hover {
    color: var(--text);
}

.main-content {
    padding: 1.25rem 0 2rem;
    min-height: calc(100vh - 70px);
    display: flex;
    flex-direction: column;
}

.anki-overview {
    flex: 1;
    display: flex;
    flex-direction: column;
    max-width: 640px;
    margin: 0 auto;
    width: 100%;
    padding: 0 0.25rem;
}

.deck-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.deck-list-item {
    margin: 0;
    padding: 0;
}

.deck-row-inner {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0;
}

.deck-link {
    color: var(--text);
    text-decoration: none;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
}

.deck-link:hover {
    color: #93c5fd;
    text-decoration: underline;
}

.deck-progress {
    margin-left: auto;
    font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
    font-size: 0.72rem;
    font-weight: 400;
    font-variant-numeric: tabular-nums;
    color: #5a6a7f;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

.btn-deck-edit {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.deck-list-item:hover .btn-deck-edit {
    opacity: 1;
}

.btn-deck-edit:hover {
    color: var(--text);
}

.btn-deck-delete {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 1rem;
    line-height: 1;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.deck-list-item:hover .btn-deck-delete {
    opacity: 1;
}

.btn-deck-delete:hover {
    color: #fca5a5;
}

.deck-rename-form {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.25rem 0 0.35rem;
}

.deck-rename-form[hidden] {
    display: none;
}

.deck-rename-input {
    flex: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    border-radius: 0;
    padding: 0.2rem 0;
    font: inherit;
}

.deck-rename-input:focus {
    outline: none;
    border-bottom-color: var(--primary);
}

.deck-list-empty {
    color: var(--muted);
    padding: 0.5rem 0;
}

.anki-bottom-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.65rem;
    margin-top: 1.25rem;
    padding-bottom: 0.5rem;
}

.anki-bar-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 999px;
    padding: 0.65rem 1.15rem;
    font-size: 0.92rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

.anki-bar-btn:hover:not(:disabled) {
    background: var(--surface-2);
    transform: translateY(-1px);
}

.anki-bar-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.settings-global {
    margin-top: 1.25rem;
    margin-bottom: 1.75rem;
}

.settings-global h2,
.settings-decks h2,
.settings-export h2 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    color: var(--muted);
    font-weight: 600;
}

.settings-export {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 3px double var(--border);
}

.deck-settings-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.deck-settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}

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

.deck-settings-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem 1rem;
    flex: 1;
    min-width: 0;
}

.deck-settings-name {
    font-size: 1rem;
    font-weight: 500;
}

.deck-settings-meta {
    font-size: 0.85rem;
    color: var(--muted);
}

.deck-settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex-shrink: 0;
}

.modal-sm {
    width: min(400px, 100%);
}

.deck-picker-select,
select {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    font: inherit;
}

.import-page {
    max-width: 520px;
}

.add-card-section {
    max-width: 640px;
    margin: 0 auto;
}

.add-card-form .field span {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.add-card-form textarea {
    min-height: 120px;
}

.add-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-top: 0.5rem;
}

.add-hint {
    margin: 1rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.add-hint kbd {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.1rem 0.35rem;
    font-size: 0.8rem;
}

.add-status {
    margin-top: 0.75rem;
    font-size: 0.9rem;
}

.add-status-ok {
    color: #86efac;
}

.add-status-error {
    color: #fca5a5;
}

.site-footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    padding: 1.25rem 0 2rem;
    font-size: 0.9rem;
}

.hero {
    text-align: center;
    padding: 2rem 0 2.5rem;
}

.hero h1 {
    font-size: clamp(1.8rem, 4vw, 2.6rem);
    margin: 0 0 0.75rem;
}

.hero p {
    color: var(--muted);
    max-width: 560px;
    margin: 0 auto 1.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    border: none;
    border-radius: 10px;
    padding: 0.7rem 1.1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s ease, background 0.15s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

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

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

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

.btn-ghost {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
}

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

.btn-danger-outline {
    background: transparent;
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.45);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #16a34a;
}

.alert {
    padding: 0.9rem 1rem;
    border-radius: 10px;
    margin-bottom: 1.25rem;
}

.alert-success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #86efac;
}

.alert-error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.alert-error a {
    color: #93c5fd;
}

.deck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

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

.deck-card h2 {
    margin: 0 0 0.5rem;
    font-size: 1.05rem;
    line-height: 1.4;
}

.deck-meta {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 0 0 1rem;
}

.deck-actions {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.deck-actions form {
    margin: 0;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 3rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px dashed var(--border);
}

.upload-section,
.install-page {
    max-width: 640px;
}

.upload-form,
.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.field span {
    font-size: 0.9rem;
    color: var(--muted);
}

input[type="text"],
input[type="file"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
}

.hint,
.info-box {
    color: var(--muted);
}

.info-box {
    margin-top: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.info-box pre {
    background: #0b1220;
    padding: 0.75rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 0.85rem;
}

.study-panel {
    position: relative;
    width: min(720px, 100%);
    margin: 0 auto 1.5rem;
    padding-right: 5.5rem;
}

.study-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
    margin-bottom: 1rem;
}

.study-progress {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.btn-jump-trigger {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
    cursor: pointer;
    letter-spacing: 0.05em;
}

.btn-jump-trigger:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.06);
}

.jump-form {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.35rem 0.45rem;
    box-shadow: var(--shadow);
}

.jump-form[hidden] {
    display: none;
}

.jump-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.jump-form input[type="number"] {
    width: 5.5rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.4rem 0.55rem;
    font: inherit;
    font-variant-numeric: tabular-nums;
}

.jump-form input[type="number"]::-webkit-outer-spin-button,
.jump-form input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.jump-form input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.flashcard-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    margin: 0;
}

.flashcard-single {
    width: 100%;
    min-height: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
}

.card-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.card-main {
    flex: 1.2;
}

.card-secondary {
    flex: 1;
}

.card-reveal-zone {
    cursor: pointer;
    border-radius: 10px;
    margin: 0 -0.35rem -0.35rem;
    padding: 0 0.35rem 0.35rem;
    outline: none;
    transition: background 0.2s ease;
}

.card-reveal-zone:hover {
    background: rgba(59, 130, 246, 0.06);
}

.card-reveal-zone:focus-visible {
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.45);
}

.card-reveal-zone.is-revealed {
    cursor: default;
}

.card-reveal-zone.is-revealed:hover {
    background: transparent;
}

.study-edge-next {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 5.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: var(--radius);
    z-index: 3;
    padding: 0;
    transition: background 0.2s ease;
}

.study-edge-next:hover:not(:disabled) {
    background: rgba(59, 130, 246, 0.06);
}

.study-edge-next:disabled {
    cursor: default;
    pointer-events: none;
    opacity: 0;
}

.reveal-hint {
    margin: 0;
    padding: 0.85rem 0.5rem 0.25rem;
    text-align: center;
    color: var(--muted);
    font-size: 0.95rem;
    font-style: italic;
}

.card-divider {
    display: flex;
    align-items: center;
    margin: 1.1rem 0 0.5rem;
    gap: 0.75rem;
    pointer-events: none;
}

.card-divider::before,
.card-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
}

.card-divider span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
    flex-shrink: 0;
}

.face-content-secondary {
    color: #c8d6ea;
    font-size: 0.98rem;
}

.face-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 0.75rem;
}

.face-content {
    flex: 1;
    font-size: 1.08rem;
    white-space: pre-wrap;
    overflow-y: auto;
    line-height: 1.55;
}

.study-controls {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.study-controls-tools {
    margin-top: 0.85rem;
    align-items: center;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
    font-size: 0.9rem;
    cursor: pointer;
}

.btn-sm {
    padding: 0.45rem 0.75rem;
    font-size: 0.85rem;
}

.deck-title-row {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.deck-title-row h2 {
    flex: 1;
}

.btn-rename {
    padding: 0.35rem 0.55rem;
    min-width: auto;
}

.rename-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.rename-form .rename-input {
    flex: 1 1 180px;
}

textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    font: inherit;
    line-height: 1.5;
    resize: vertical;
    width: 100%;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 20, 0.72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    width: min(560px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem 1.35rem 1.35rem;
}

.modal h2 {
    margin: 0 0 1rem;
    font-size: 1.15rem;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.settings-section {
    max-width: 900px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

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

.settings-card h2 {
    margin: 0 0 0.75rem;
    font-size: 1.1rem;
}

.settings-form {
    margin-top: 1rem;
}

input[type="password"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    width: 100%;
}

.deck-resume {
    color: #93c5fd;
}

code {
    background: rgba(255, 255, 255, 0.06);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.88em;
}

@media (max-width: 600px) {
    .flashcard-single {
        min-height: 280px;
        padding: 1.1rem;
    }

    .study-top {
        flex-direction: column;
        align-items: flex-start;
    }

    .study-controls-tools {
        flex-direction: column;
        align-items: stretch;
    }

    .study-controls-tools .btn,
    .study-controls-tools .toggle {
        width: 100%;
        justify-content: center;
    }

    .anki-bottom-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .anki-bar-btn {
        width: 100%;
    }

    .btn-deck-edit {
        opacity: 1;
    }

    .btn-deck-delete {
        opacity: 1;
    }
}
