/* Spinner overlay for card loading */
#card-spinner {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    z-index: 20;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 5px solid #fff;
    border-top: 5px solid var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@font-face {
    font-family: "Beleren Bold";
    src:
        url("https://unpkg.com/@saeris/typeface-beleren-bold@1.0.1/Beleren2016-Bold.woff") format("woff"),
        url("https://unpkg.com/@saeris/typeface-beleren-bold@1.0.1/Beleren2016-Bold.ttf") format("truetype"),
        url("https://unpkg.com/@saeris/typeface-beleren-bold@1.0.1/Beleren2016-Bold.svg#Beleren2016-Bold") format("svg");
    font-style: normal;
    font-weight: bold;
    text-rendering: optimizeLegibility;
}

:root {
    --bg: #000000;
    --panel: #121214;
    --accent: #6a9fc6;
    --glass: rgba(0, 0, 0, 0.4);
    --border: rgba(255, 255, 255, 0.12);
    /* MTG P/T Box Gradients */
    --color-w: linear-gradient(135deg, #fbf8f1, #e5d9e3);
    --color-u: linear-gradient(135deg, #a5bed6, #a6c1dc);
    --color-b: linear-gradient(135deg, #aca6a6, #aba5a5);
    --color-r: linear-gradient(135deg, #e9bb8c, #e7bfa9);
    --color-g: linear-gradient(135deg, #bcc9b5, #bfcbbf);
    --color-m: linear-gradient(135deg, #e4d7c0, #ceb387);
    --color-c: linear-gradient(135deg, #b4bec6, #acbec0);
    /* Color Indicators */
    --color-indicator-w: linear-gradient(135deg, #fffec7, #fff);
    --color-indicator-u: linear-gradient(135deg, #acb8d2, #1b438e);
    --color-indicator-b: linear-gradient(135deg, #aca6a6, #1c1515);
    --color-indicator-r: linear-gradient(135deg, #d53939, #e7bfa9);
    --color-indicator-g: linear-gradient(135deg, #9fdd6d, #145c14);
    --color-indicator-m: linear-gradient(135deg, #f5ff35, #959941);
    --color-indicator-c: linear-gradient(135deg, #b4bec6, #bbb);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    outline: none;
}

.phone-view {
    position: relative;
    /* This makes it the 'zero point' (0,0) for all absolute children */
    width: min(400px, 100vw);
    min-height: 100vh;
    margin: 0 auto;
    /* Centers the 400px viewport on desktop */
    background: var(--bg);
    /* The 'phone screen' color */
    overflow-x: clip;
    /* Modern version of hidden; stops horizontal scrolling */
}

body {
    background: var(--bg);
    color: #fff;
    margin: 0;
    padding: 0;
    font-family: 'Beleren Bold';
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Remove number input arrows */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
}

header {
    background: var(--bg);
    padding: 10px 5px 2px 5px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2px 4px 2px;
}

.header-title {
    font-family: 'Beleren Bold';
    font-size: 1.3rem;
    font-weight: 900;
    color: #fff;
    letter-spacing: 0.04em;
}

.hamburger-btn {
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hamburger-btn svg {
    stroke: #fff;
}

button {
    cursor: pointer;
}

.search-wrapper {
    display: flex;
    align-items: center;
}

.mode-dropdown {
    padding: 9px 12px;
    border-radius: 8px 0px 0px 8px;
    border: 1px solid var(--border);
    background: #1a1a1e;
    color: #e5e5e5;
    font-family: 'Beleren Bold';
    font-weight: 700;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    height: 38px;
}

.mode-dropdown:focus {
    border-color: var(--accent);
}

#search-input {
    flex: 1;
    padding: 9px;
    border-radius: 0px 8px 8px 0px;
    background: #1a1a1e;
    border: 1px solid var(--border);
    color: white;
    font-family: 'Beleren Bold';
    font-size: 0.9rem;
    min-width: 0;
    height: 38px;
}

.dropdown {
    position: absolute;
    top: 96px;
    left: 12px;
    right: 12px;
    background: #1a1a1e;
    border-radius: 8px;
    border: 1px solid #333;
    max-height: 380px;
    overflow-y: auto;
    z-index: 500;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}

.result-item {
    padding: 14px;
    border-bottom: 1px solid #25252a;
    cursor: pointer;
}

.result-item:hover {
    background: #424249;
}

/* Stage & Card */
#stage {
    flex: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#card-anchor {
    position: relative;
    width: min(400px, 100vw);
    height: auto;
    aspect-ratio: 2.5/3.5;
    max-height: 75vh;
}

#main-art {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 11% / 4%;
    -webkit-touch-callout: none;
    /* iOS Safari */
    -webkit-user-select: none;
    /* Safari, Chrome */
    -khtml-user-select: none;
    /* Konqueror HTML */
    -moz-user-select: none;
    /* Old versions of Firefox */
    -ms-user-select: none;
    /* Internet Explorer/Edge */
    user-select: none;
    /* Non-prefixed version, currently in standardization */
    -webkit-user-drag: none;
    /* Safari, Chrome, Opera */
    user-drag: none;
    /* Non-prefixed version */
}

/* Overlays Control */
#ui-toggle {
    position: absolute;
    top: 0%;
    left: 0px;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 50%;
    padding: 7px 8px;
    color: #fff;
    z-index: 10;
    backdrop-filter: blur(2px);
}

body.minimal #ui-overlays,
body.minimal #bottom-controls {
    display: none;
}

body.minimal header {
    opacity: 0;
}

body.minimal #stage {
    justify-content: center;
}

/* Quantity */
.quantity-system {
    position: absolute;
    top: 13%;
    right: 5%;
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    backdrop-filter: blur(3px);
    padding: 2px 4px;
}

#qty-display {
    min-width: 30px;
    width: 24px;
    max-width: 80px;
    text-align: center;
    background: none;
    border: none;
    color: white;
    font-size: 2rem;
    font-family: 'Beleren Bold';
    font-weight: 900;
    /* iOS Safari input fixes */
    -webkit-appearance: none;
    -moz-appearance: textfield;
    appearance: none;
    /* Prevent iOS zoom and styling */
    font-size: 16px;
    transform: scale(1.25);
    transform-origin: center;
    /* Ensure clean input */
    outline: none;
    border-radius: 0;
    box-sizing: content-box;
    padding: 2px 4px;
}

.qty-btn {
    background: none;
    border: none;
    color: #fff;
    padding: 10px;
}

.qty-btn:hover {
    color: #aaa;
}

/* Dynamic P/T Box */
.pt-box {
    position: absolute;
    bottom: 5%;
    right: 4.5%;
    min-width: 22%;
    max-width: 40%;
    width: auto;
    transition: width 0.2s cubic-bezier(0.4,0,0.2,1);
    height: 8%;
    border: 3px solid #111;
    border-radius: 25% / 120%;
    /* box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.4), 0 3px 10px rgba(0, 0, 0, 0.5); */
}

#pt-input {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    transition: width 0.2s cubic-bezier(0.4,0,0.2,1);
    height: 100%;
    background: none;
    border: none;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 900;
    color: #000;
    font-family: 'Beleren Bold';
    padding-top: 5px;
}

/* Loyalty System for Planeswalkers */
.loyalty-box {
    position: absolute;
    bottom: -1.5%;
    right: 1.5%;
    width: 22%;
    height: 21%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
}

.loyalty-btn {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--border);
    color: #fff;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(2px);
    transition: all 0.2s;
}

.loyalty-btn:hover {
    background: rgba(114, 114, 114, 0.6);
}

#loyalty-input {
    width: 75%;
    height: 35%;
    background: url('./loyalty.webp') center/contain no-repeat;
    border: none;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 900;
    color: #fff;
    font-family: 'Beleren Bold';
    position: relative;
    z-index: 2;
    margin: -3px;
}


/* Counters */
#counters-overlay {
    position: absolute;
    top: 25%;
    left: 5%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.counter-pill {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    backdrop-filter: blur(8px);
}

.pill-name {
    width: 60px;
    background: none;
    border: none;
    color: #ffffff;
    font-family: 'Beleren Bold';
    font-size: 0.8rem;
    text-transform: uppercase;
    border-right: 1px solid #444;
    margin-right: 8px;
}

.pill-val {
    width: 35px;
    background: none;
    border: none;
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
    text-align: center;
    font-family: 'Beleren Bold';
}

/* Modals & Buttons */
.close-modal-btn {
    background: none;
    border: none;
    color: #888;
    padding: 5px;
}

.add-btn {
    background: #1a1a1e;
    border: 1px solid #333;
    color: #aaa;
    padding: 12px 24px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: 'Beleren Bold';
    font-weight: 600;
    transition-duration: 0.2s;
}

.add-btn:hover {
    background: rgb(60, 60, 66);
}

#bottom-controls {
    position: relative;
    display: flex;
    gap: 12px;
    align-items: center;
    margin-top: 2px;
    justify-content: center;
}

/* Recents Dropdown */
.recents-dropdown {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 320px;
    max-width: 90vw;
    background: #1a1a1e;
    border-radius: 8px;
    border: 1px solid #333;
    max-height: 300px;
    overflow-y: auto;
    z-index: 500;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.7);
    margin-bottom: 8px;
}

.recents-dropdown .result-item {
    padding: 12px 14px;
    border-bottom: 1px solid #25252a;
    cursor: pointer;
    font-size: 0.9rem;
}

.recents-dropdown .result-item:last-child {
    border-bottom: none;
}

.recents-dropdown .result-item:hover {
    background: #424249;
}

.recents-empty {
    padding: 20px;
    text-align: center;
    color: #888;
    font-size: 0.9rem;
}

#flip-btn {
    background: #1a1a1e;
    border: 1px solid #333;
    color: #aaa;
    transition-duration: 0.2s;
}

#flip-btn:hover {
    background: rgb(60, 60, 66);
}

#art-picker-btn {
    position: absolute;
    bottom: 12px;
    left: 12px;
    background: var(--glass);
    border: 1px solid var(--border);
    color: #fff;
    padding: 8px 14px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    backdrop-filter: blur(2px);
}

#art-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px;
    overflow-y: auto;
    max-height: 60vh;
}

#art-grid img {
    width: 100%;
    border-radius: 10px;
    border: 3px solid transparent;
    -webkit-touch-callout: none;
    /* iOS Safari */
    -webkit-user-select: none;
    /* Safari, Chrome */
    -khtml-user-select: none;
    /* Konqueror HTML */
    -moz-user-select: none;
    /* Old versions of Firefox */
    -ms-user-select: none;
    /* Internet Explorer/Edge */
    user-select: none;
    /* Non-prefixed version, currently in standardization */
    -webkit-user-drag: none;
    /* Safari, Chrome, Opera */
    user-drag: none;
    /* Non-prefixed version */
}

#art-grid img.active {
    border-color: var(--accent);
}

/* Add this at the VERY BOTTOM of your style.css to ensure top priority */
.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

/* Ensure Modal is strictly isolated */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    width: min(400px, 100vw);
}

.printImg {
    cursor: pointer;
    transition-duration: 0.2s;
}

.printImg:hover {
    filter: brightness(1.2) contrast(0.8);
}

/* Fix dropdown positioning to ensure it doesn't push content */
.dropdown {
    position: absolute;
    left: 0;
    right: 0;
    background: #1a1a1e;
    border-radius: 8px;
    border: 1px solid #333;
    max-height: 380px;
    overflow-y: auto;
    z-index: 500;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.7);
}

/* Placeholder styling for counter names */
.pill-name::placeholder {
    color: rgba(255, 255, 255, 0.2);
    font-size: 0.6rem;
}

/* Custom button styling for the pills to avoid default HTML look */
.pill-btn {
    color: #888;
    border: none;
    background: none;
    font-size: 1.2rem;
    padding: 0 5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.pill-btn:active {
    color: var(--accent);
}

/* Ensure the pill-val doesn't look like a standard input */
.pill-val {
    width: 35px;
    background: none;
    border: none;
    color: white;
    font-weight: bold;
    font-size: 1.1rem;
    text-align: center;
    -webkit-appearance: none;
}

/* --- DUNGEON SYSTEM --- */
#dungeon-highlight {
    position: absolute;
    pointer-events: none;
    border: 3px solid #fff;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.5), inset 0 0 10px rgba(0, 0, 0, 0.5);
    background: rgba(255, 255, 255, 0);
    border-radius: 4px;
    z-index: 5;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    backdrop-filter: brightness(3.5) saturate(1.2) contrast(1.3);
}

.dungeon-active #main-art {
    filter: brightness(0.3) saturate(0.8) contrast(0.9);
    transition: filter 0.3s ease;
}

.dungeon-active #card-anchor {
    cursor: pointer;
    /* Indicates it's tappable */
}

/* --- FLIP CARD ANIMATION --- */
.flip-card {
    background-color: transparent;
    width: 100%;
    height: 100%;
    perspective: 1000px;
    overflow: hidden;
}

.flip-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.6s ease-in-out;
    transform-style: preserve-3d;
}

.flip-card.flipped .flip-card-inner {
    transform: rotateY(-180deg);
}

.flip-card-front,
.flip-card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.flip-card-front img,
.flip-card-back img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 11% / 4%;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    user-drag: none;
}

.flip-card-back {
    transform: rotateY(-180deg);
}

/* --- SIDE PANEL --- */
/* Side panel container */
.side-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 3000;
    pointer-events: none;
}

.side-panel.sidepanel-open {
    pointer-events: auto;
}

/* Side panel overlay */
.side-panel-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    opacity: 0;
    transition: opacity 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    pointer-events: auto;
}

.side-panel.sidepanel-open .side-panel-overlay {
    opacity: 1;
}

/* Side panel sliding content */
.side-panel-content {
    position: absolute;
    top: 0;
    right: 0;
    width: min(320px, 80vw);
    height: 100%;
    background: var(--panel);
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.25);
    pointer-events: auto;
}

.side-panel.sidepanel-open .side-panel-content {
    transform: translateX(0);
}

.side-panel .side-panel-content {
    transform: translateX(100%);
}

.side-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

.side-panel-title {
    font-size: 1.1rem;
    font-weight: 900;
    color: #fff;
    font-family: 'Beleren Bold';
}

.side-panel-body {
    flex: 1;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 12px 0;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.toggle-slider {
    position: relative;
    width: 50px;
    height: 24px;
    background: #333;
    border-radius: 12px;
    transition: background 0.3s ease;
    border: 1px solid var(--border);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s ease;
}

.toggle-label input[type="checkbox"]:checked+.toggle-slider {
    background: var(--accent);
}

.toggle-label input[type="checkbox"]:checked+.toggle-slider::before {
    transform: translateX(26px);
}

.toggle-text {
    font-family: 'Beleren Bold';
    font-size: 0.9rem;
    color: #fff;
    flex: 1;
}

.side-panel-btn {
    width: 100%;
    background: #1a1a1e;
    border: 1px solid #333;
    color: #aaa;
    padding: 16px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-family: 'Beleren Bold';
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.side-panel-btn:hover {
    background: rgb(60, 60, 66);
    color: #fff;
}

.toggle-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.feature-explanation {
    font-family: 'Beleren Bold';
    font-size: 0.75rem;
    color: #aaa;
    line-height: 1.3;
    margin-top: -6px;
}

/* --- MODAL ENHANCEMENTS --- */
.modal-body {
    padding: 20px;
}

.input-label {
    display: block;
    font-family: 'Beleren Bold';
    font-size: 0.9rem;
    color: #fff;
    margin-bottom: 8px;
}

.deck-url-input {
    width: 100%;
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #1a1a1e;
    color: #fff;
    font-family: 'Beleren Bold';
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

.deck-url-input:focus {
    border-color: var(--accent);
    outline: none;
}

.disclaimer-text {
    font-family: 'Beleren Bold';
    font-size: 0.85rem;
    color: #ccc;
    line-height: 1.6;
    margin: 0;
}

/* Modal fade animations */
.modal {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal:not(.hidden) {
    opacity: 1;
}

.modal-content {
    transform: scale(0.9);
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.modal:not(.hidden) .modal-content {
    transform: scale(1);
}