/* Deck Lab app styles. Design tokens, base, the admin-panel shell and the deck-* rules are copied from
   TGG.Server/wwwroot/app.css (same look as the website); keep them in step when the site's tokens change. */

/* ── Design tokens ────────────────────────────────────────────────────── */

:root {
    color-scheme: light;

    --bg: #f6f6fb;
    --bg-soft: #eef0fb;
    --surface: #ffffff;
    --surface-border: #e6e6f2;
    --text: #17172a;
    --text-muted: #5b5b70;
    --text-faint: #8a8aa0;

    --accent: #6366f1;
    --accent-strong: #4f46e5;
    --accent-soft: rgba(99, 102, 241, 0.1);
    --accent-contrast: #ffffff;

    --blob-1: rgba(99, 102, 241, 0.35);
    --blob-2: rgba(236, 72, 153, 0.25);

    --shadow-sm: 0 1px 2px rgba(23, 23, 42, 0.06);
    --shadow-md: 0 12px 30px -12px rgba(23, 23, 42, 0.18);
    --shadow-lg: 0 30px 80px -30px rgba(23, 23, 42, 0.35);

    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 10px;

    --nav-bg: rgba(255, 255, 255, 0.72);
    /* logo.png is white line-art on a transparent background: invert it for light backgrounds */
    --logo-filter: invert(1);
}

/*
 * Three-state theming: no explicit choice → follow the OS (media query, guarded so an
 * explicit [data-theme="light"] can still win); an explicit choice (cookie set via
 * /prefs/theme/{value}) → the attribute block below wins outright, in either direction.
 */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;

        --bg: #0a0a12;
        --bg-soft: #10101c;
        --surface: #14141f;
        --surface-border: #262637;
        --text: #f2f2f8;
        --text-muted: #a6a6bd;
        --text-faint: #6f6f88;

        --accent: #818cf8;
        --accent-strong: #6366f1;
        --accent-soft: rgba(129, 140, 248, 0.16);
        --accent-contrast: #0a0a12;

        --blob-1: rgba(99, 102, 241, 0.35);
        --blob-2: rgba(236, 72, 153, 0.22);

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 12px 30px -12px rgba(0, 0, 0, 0.55);
        --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, 0.7);

        --nav-bg: rgba(10, 10, 18, 0.72);
        --logo-filter: none;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0a0a12;
    --bg-soft: #10101c;
    --surface: #14141f;
    --surface-border: #262637;
    --text: #f2f2f8;
    --text-muted: #a6a6bd;
    --text-faint: #6f6f88;

    --accent: #818cf8;
    --accent-strong: #6366f1;
    --accent-soft: rgba(129, 140, 248, 0.16);
    --accent-contrast: #0a0a12;

    --blob-1: rgba(99, 102, 241, 0.35);
    --blob-2: rgba(236, 72, 153, 0.22);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 12px 30px -12px rgba(0, 0, 0, 0.55);
    --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, 0.7);

    --nav-bg: rgba(10, 10, 18, 0.72);
    --logo-filter: none;
}

/* ── Reset & base ─────────────────────────────────────────────────────── */

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

html,
body {
    height: 100%;
}

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }

    * {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

#when-we-play,
#about {
    scroll-margin-top: 84px;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background-color 0.25s ease, color 0.25s ease;
}

h1, h2, h3, h4 {
    line-height: 1.15;
    margin: 0 0 0.5em;
}

p {
    margin: 0 0 1em;
    color: var(--text-muted);
}

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

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


/* ── Admin pages ──────────────────────────────────────────────────────── */

.admin-layout {
    width: 100%;
    min-height: 100vh;
    background: var(--bg);
}

.admin-appbar.mud-appbar {
    position: sticky;
    top: 0;
    z-index: 15;
    background: var(--surface) !important;
    color: var(--text) !important;
    border-bottom: 1px solid var(--surface-border);
}

.admin-drawer-toggle {
    color: var(--text-muted) !important;
}

.admin-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 0.25rem;
    font-size: 0.9rem;
}

.admin-breadcrumb-root {
    color: var(--text-faint);
    font-weight: 600;
}

.admin-breadcrumb-sep {
    color: var(--text-faint);
}

.admin-breadcrumb-current {
    color: var(--text);
    font-weight: 700;
}

.admin-appbar .mud-toolbar {
    gap: 0.5rem;
}

.admin-exit-link.mud-button-root {
    color: var(--text-muted) !important;
    text-transform: none;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    min-height: 2.5rem;
    margin-left: 0.5rem;
}

/* Row action buttons (edit / delete): bigger hit area with room between them */
.admin-content td .mud-icon-button {
    padding: 0.55rem;
    margin: 0 0.35rem;
}

.admin-exit-link.mud-button-root:hover {
    color: var(--accent-strong) !important;
}

/* Admin reuses the public header's account menu. The public mobile rules turn it into an inline
   list inside the hamburger panel; the admin bar has no hamburger, so keep the dropdown form. */
.admin-account .account-trigger {
    display: inline-flex;
}

.admin-account .account-label,
.admin-account .account-divider + .account-label {
    display: none;
}

.admin-account .account-dropdown {
    display: none;
    position: absolute;
    min-width: 190px;
    padding: 0.35rem;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-md);
}

.admin-account .account-dropdown.account-dropdown--open {
    display: flex;
}

.admin-account .account-dropdown a {
    padding: 0.5rem 0.65rem;
    color: var(--text);
    font-weight: 400;
}

.admin-account .account-dropdown a:hover {
    background: var(--accent-soft);
}

.admin-account .account-divider {
    display: block;
}

.admin-account {
    width: auto;
    margin: 0;
    padding: 0;
    border: none;
}

/* Below the appbar (z 15) so the dropdown, which lives inside it, stays clickable. */
.admin-account-backdrop {
    position: fixed;
    inset: 0;
    z-index: 14;
}

.admin-user-name {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-right: 0.5rem;
}

.admin-logout-link.mud-button-root {
    color: var(--text-muted) !important;
}

.admin-logout-link.mud-button-root:hover {
    color: var(--accent-strong) !important;
}

.admin-drawer.mud-drawer {
    border-right: 1px solid var(--surface-border);
    background: var(--surface) !important;
}

.admin-drawer-header {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid var(--surface-border);
}

.admin-drawer-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #fff;
    font-weight: 800;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}

.admin-drawer-title {
    font-weight: 700;
    color: var(--text);
}

.admin-nav {
    padding: 0.75rem;
}

.admin-nav-heading.mud-typography {
    display: block;
    color: var(--text-faint);
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 0.9rem 0.75rem 0.35rem;
}

.admin-nav .mud-nav-link {
    border-radius: var(--radius-sm);
    margin: 0.1rem 0.4rem;
    color: var(--text-muted);
}

.admin-nav .mud-nav-link:hover {
    background: var(--accent-soft);
    color: var(--text);
}

.admin-nav .mud-nav-link.active,
.admin-nav .mud-nav-link.mud-nav-link-active {
    background: var(--accent-soft);
    color: var(--accent-strong);
    font-weight: 700;
}

.admin-main {
    padding: 0;
    margin-left: 0;
    width: 100%;
    transition: margin-left 0.2s ease, width 0.2s ease;
}

.admin-content {
    padding: 1.75rem clamp(1rem, 3vw, 2rem);
    max-width: 1400px;
    margin: 0 auto;
}

@media (min-width: 769px) {
    .admin-main--drawer-open {
        margin-left: 260px;
        width: calc(100% - 260px);
    }
}

/* MudDataGrid, restyled to match the site's surfaces/radius instead of MudBlazor's defaults */

.admin-content .mud-data-grid {
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.admin-content .mud-data-grid .mud-toolbar {
    background: var(--bg-soft);
    border-bottom: 1px solid var(--surface-border);
    padding: 0.85rem 1.25rem;
    gap: 0.75rem;
}

.admin-content .mud-table-head {
    background: var(--bg-soft);
}

.admin-content .mud-table-head th {
    color: var(--text-faint);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--surface-border);
}

.admin-content .mud-table-body tr.mud-table-row {
    border-bottom: 1px solid var(--surface-border);
    transition: background-color 0.12s ease;
}

.admin-content .mud-table-body tr.mud-table-row:nth-of-type(even) {
    background: color-mix(in srgb, var(--bg-soft) 45%, transparent);
}

.admin-content .mud-table-body tr.mud-table-row:hover {
    background: var(--accent-soft) !important;
}

.admin-content .mud-table-container {
    border-radius: 0;
}


/* ── Deck Lab (/decks) ─────────────────────────────────────────────────── */

.deck-muted { color: var(--text-faint); }
.deck-mono textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; }

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

.deck-notes { margin-bottom: 1rem; white-space: pre-line; color: var(--text-muted); }

.deck-header {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.deck-header-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.deck-back { color: var(--text-faint); text-decoration: none; font-size: 0.85rem; }
.deck-back:hover { color: var(--accent); }
.deck-title { margin: 0.15rem 0; font-size: clamp(1.4rem, 3vw, 2rem); }
.deck-subtitle { display: flex; flex-wrap: wrap; gap: 0.35rem; color: var(--text-muted); font-size: 0.9rem; }

.deck-toolbar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; margin-bottom: 1rem; }

.deck-section-title { font-size: 1rem; font-weight: 700; margin: 1.5rem 0 0.6rem; }
.deck-section-title.mt-0 { margin-top: 0; }

.deck-facts {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem 2rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

.deck-facts > div:not(.deck-curve) { display: flex; flex-direction: column; }
.deck-fact-value { font-size: 1.4rem; font-weight: 700; }
.deck-fact-label { font-size: 0.78rem; color: var(--text-faint); }

.deck-curve { display: flex; gap: 0.3rem; align-items: flex-end; height: 4.2rem; }
.deck-curve-bar { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; width: 1.4rem; height: 100%; }
.deck-curve-fill { width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.deck-curve-count, .deck-curve-label { font-size: 0.7rem; color: var(--text-faint); }

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

.deck-card-grid--small { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 0.4rem; }

.deck-card {
    position: relative;
    display: block;
    aspect-ratio: 488 / 680;
    border-radius: 4.5% / 3.5%;
    overflow: hidden;
    background: var(--bg-soft);
    border: 1px solid var(--surface-border);
    padding: 0;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.deck-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.deck-card img { width: 100%; height: 100%; object-fit: cover; display: block; }
.deck-card--pickable { outline: 2px dashed var(--accent); outline-offset: 2px; }

.deck-card-missing {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.deck-card-qty {
    position: absolute;
    top: 6%;
    right: 6%;
    min-width: 1.6rem;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: rgba(10, 10, 18, 0.85);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    text-align: center;
}

.deck-warning-list { margin: 0.25rem 0 0; padding-left: 1.1rem; }

.deck-line-list { list-style: none; margin: 0; padding: 0; }
.deck-qty { display: inline-block; min-width: 1.4rem; font-weight: 700; }
.deck-chip-row { display: flex; flex-wrap: wrap; gap: 0.2rem; }

.deck-link-button {
    background: none;
    border: none;
    padding: 0;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
}

.deck-version-list { list-style: none; margin: 0; padding: 0; }
.deck-version-list li { padding: 0.5rem 0.6rem; border-radius: var(--radius-sm); border-left: 3px solid transparent; }
.deck-version-list li + li { margin-top: 0.15rem; }
.deck-version--selected { background: var(--accent-soft); border-left-color: var(--accent) !important; }
.deck-version-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.deck-version-note { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.15rem; }

.deck-diff-zone { margin: 1rem 0 0.3rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-faint); }
.deck-diff { list-style: none; margin: 0; padding: 0; }
.deck-diff li { padding: 0.15rem 0; }
.deck-diff-sign { display: inline-block; min-width: 2.2rem; font-weight: 700; font-family: ui-monospace, monospace; }
.deck-diff--add .deck-diff-sign { color: #16a34a; }
.deck-diff--remove .deck-diff-sign { color: #dc2626; }

.deck-plan-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 1rem; }
.deck-plan-head { display: flex; align-items: flex-start; gap: 0.25rem; margin-bottom: 0.75rem; }
.deck-plan-title { margin: 0; font-size: 1.1rem; }
.deck-plan-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.deck-plan-label { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.4rem; }
.deck-plan-label--in { color: #16a34a; }
.deck-plan-label--out { color: #dc2626; }
.deck-plan-notes { margin: 0.75rem 0 0; color: var(--text-muted); white-space: pre-line; }

.deck-match-rows { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.deck-match-rows li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; font-size: 0.88rem; }
.deck-match-games { display: inline-flex; flex-wrap: wrap; gap: 0.5rem; color: var(--text-muted); font-size: 0.8rem; }

.deck-result {
    display: inline-block;
    padding: 0.1rem 0.55rem;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.85rem;
    background: var(--bg-soft);
}

.deck-result--small { font-size: 0.75rem; }
.deck-result--win { background: rgba(22, 163, 74, 0.15); color: #16a34a; }
.deck-result--loss { background: rgba(220, 38, 38, 0.13); color: #dc2626; }
.deck-result--draw { background: var(--accent-soft); color: var(--accent); }


.deck-game-form {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-sm);
}

.deck-game-form__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.4rem; }

.deck-table { background: var(--surface) !important; border: 1px solid var(--surface-border); border-radius: var(--radius-md); overflow-x: auto; }
.deck-row--good td { background: rgba(22, 163, 74, 0.08); }
.deck-row--bad td { background: rgba(220, 38, 38, 0.07); }

.deck-goldfish-status { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.75rem; min-height: 2.25rem; }
.deck-hand { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

/* Deck tab: name, version and the key cards, then the list in columns. */
.deck-hero { margin-bottom: 1.25rem; }
.deck-hero-head { display: flex; align-items: flex-start; gap: 0.5rem; margin-bottom: 0.75rem; }
.deck-hero-title { margin: 0; font-size: 1.35rem; }
.deck-hero-meta { color: var(--text-muted); font-size: 0.9rem; }
.deck-card-grid--hero { grid-template-columns: repeat(auto-fill, minmax(min(46%, 170px), 1fr)); max-width: 1100px; }
.deck-list-columns { columns: 3 15rem; column-gap: 2rem; }
.deck-list-group { break-inside: avoid; margin-bottom: 0.75rem; }
.deck-list-group .deck-section-title { margin-top: 0; }
.deck-card--highlight { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sideboard guide: jump to an opponent, play/draw, condition switches. Sticky so it stays reachable at the table. */
.deck-jump {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
    background: var(--bg);
    border-bottom: 1px solid var(--surface-border);
}
.deck-jump-chips { display: flex; flex-wrap: wrap; gap: 0.15rem; flex: 1 1 20rem; }
.deck-opponent { margin-bottom: 2rem; }
.deck-opponent-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; }
.deck-conditions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem 0.35rem; margin-bottom: 0.6rem; }
.deck-conditional-list { list-style: none; margin: 0.75rem 0 0; padding: 0.5rem 0 0; border-top: 1px dashed var(--surface-border); font-size: 0.88rem; }
.deck-conditional--off { opacity: 0.5; }
.deck-conditional--on { font-weight: 600; }

/* Room between the tab bar and the panel, so a MudGrid's negative margin can't cover the tabs. */
.deck-tabs .mud-tabs-panels { padding-top: 1.5rem; }

/* Phones: a dropdown instead of the tab bar (DeckDetail), one column for In/Out. */
.deck-tab-select { display: none !important; }

@media (max-width: 600px) {
    .deck-plan-columns { grid-template-columns: 1fr; }
    .deck-card-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
    .deck-tab-select { display: flex !important; margin-bottom: 0.5rem; }
    .deck-tabs .mud-tabs-tabbar { display: none; }
    .deck-tabs .mud-tabs-panels { padding-top: 0.5rem; }
    .deck-header { flex-direction: column; align-items: stretch; }
}

.deck-busy { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; color: #fff; font-weight: 600; }
.deck-toolbar.mb-0 { margin-bottom: 0; }
.deck-plan-warnings {
    margin: 0 0 0.75rem;
    padding: 0.4rem 0.75rem 0.4rem 1.6rem;
    border-radius: var(--radius-sm);
    background: rgba(245, 158, 11, 0.12);
    color: #b45309;
    font-size: 0.85rem;
}

/* ── App shell (offline app only) ─────────────────────────────────────── */

.deck-boot {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    color: var(--text-faint);
    font-size: 1rem;
}

.deck-gate {
    max-width: 30rem;
    margin: 12vh auto;
    padding: 2rem;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.deck-gate h1 { margin: 0 0 0.5rem; font-size: 1.6rem; }
.deck-gate p { color: var(--text-muted); }

.deck-sync {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
    background: var(--bg-soft);
    color: var(--text-muted);
    border: 1px solid var(--surface-border);
    cursor: pointer;
}

.deck-sync-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: #22c55e; }
.deck-sync--syncing .deck-sync-dot { background: var(--accent); animation: deck-pulse 1s infinite alternate; }
.deck-sync--offline .deck-sync-dot { background: #f59e0b; }
.deck-sync--problem .deck-sync-dot { background: #ef4444; }

@keyframes deck-pulse { from { opacity: 1; } to { opacity: 0.3; } }

.deck-card-tip img { width: 220px; border-radius: 10px; display: block; }

#blazor-error-ui {
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 3000;
    color: #17172a;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.scryfall-ref { color: var(--accent); text-decoration: underline dotted; text-underline-offset: 2px; }
.scryfall-ref:hover { color: var(--accent-strong); }
