/* Card Reader - Complete Styles */
/* Base styles extracted from inline styles in card_reader.html */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #1a1d2e 0%, #2d1b3d 100%);
    color: #fff;
    min-height: 100vh;
    padding-top: 70px;
    overflow-x: hidden;
    overflow-y: auto;
}

.main-container {
    display: grid;
    grid-template-columns: 100px 1fr; /* 稍窄的sidebar */
    grid-template-rows: auto 1fr; /* Let toolbar height be determined by content */
    height: calc(100vh - 70px);
    gap: 0;
    transition: grid-template-columns 0.3s ease;
}

/* Collapsed state - sidebar collapses completely */
.main-container.sidebar-collapsed {
    grid-template-columns: 0 1fr;
}

/* Desktop 默认样式 - 在 grid 里显示 */
/* Toolbar spans full width across all columns */
.spreads-toolbar {
    grid-column: 1 / -1; /* Span all columns for full width */
    grid-row: 1;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 1px 12px; /* Reduced vertical padding */
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(217, 27, 122, 0.3);
    border-right: none;
    overflow-x: auto; /* Single scrollbar on toolbar */
    overflow-y: hidden;
    min-width: 0;
    position: relative;
}

/* Toolbar scrollbar styling */
.spreads-toolbar::-webkit-scrollbar {
    height: 6px;
}

.spreads-toolbar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

.spreads-toolbar::-webkit-scrollbar-thumb {
    background: rgba(217, 27, 122, 0.5);
    border-radius: 3px;
}

.spreads-toolbar::-webkit-scrollbar-thumb:hover {
    background: rgba(217, 27, 122, 0.7);
}

/* 顶部一行：Spreads */
.spreads-row {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: visible; /* Let parent toolbar handle scrolling */
    flex: 1 0 auto; /* Don't shrink */
    min-width: 0;
}

.spread-cache-tray {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: auto; /* Remove fixed min-width to eliminate gap */
    flex-shrink: 0;
}

.spread-cache-pill {
    padding: 4px 12px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.spread-cache-pill:hover {
    border-color: #d91b7a;
    color: #d91b7a;
}

.spread-cache-empty {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
}

.reset-spreads-btn {
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.reset-spreads-btn:hover {
    border-color: #d91b7a;
    color: #d91b7a;
    box-shadow: 0 0 10px rgba(217, 27, 122, 0.3);
}

.spread-item.dragging {
    opacity: 0.6;
}

.spread-label {
    white-space: nowrap;
    color: #fff;
}

.spreads-empty-state {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
}

.spread-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 14px;
    background: rgba(217, 27, 122, 0.2);
    border: 1px solid rgba(217, 27, 122, 0.4);
    border-radius: 16px;
    cursor: move;
    transition: all 0.3s ease;
    white-space: nowrap;
    scroll-snap-align: start;
    font-size: 13px;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.spread-item.dragging {
    cursor: move;
    opacity: 0.5;
}

/* Drop position indicators - show line at insertion point */
.spread-item.drag-over {
    position: relative;
}

.spread-item.drag-over::before {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: #d91b7a;
    border-radius: 2px;
    pointer-events: none;
    z-index: 100;
    box-shadow: 0 0 6px rgba(217, 27, 122, 0.8);
    animation: indicator-pulse 0.8s infinite;
}

.spread-item.drop-before::before {
    left: -6px;
}

.spread-item.drop-after::before {
    right: -6px;
    left: auto;
}

@keyframes indicator-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 6px rgba(217, 27, 122, 0.8); }
    50% { opacity: 0.7; box-shadow: 0 0 10px rgba(217, 27, 122, 1); }
}

.spread-item:hover {
    background: rgba(217, 27, 122, 0.4);
    transform: translateY(-2px);
}

.spread-item.active {
    background: rgba(217, 27, 122, 0.6);
    border-color: #d91b7a;
    box-shadow: 0 0 15px rgba(217, 27, 122, 0.5);
}

/* Fully filled spread - light blue color */
.spread-item.fully-filled {
    background: rgba(100, 180, 230, 0.3);
    border-color: rgba(100, 180, 230, 0.7);
}

.spread-item.fully-filled.active {
    background: rgba(100, 180, 230, 0.5);
    border-color: #64b4e6;
    box-shadow: 0 0 15px rgba(100, 180, 230, 0.5);
}

/* 左侧列：卡片类型选择 */
/* Sidebar only in content row (row 2), not spanning toolbar */
.deck-selector-column {
    grid-column: 1;
    grid-row: 2; /* Only row 2, below the toolbar */
    display: flex;
    flex-direction: column;
    gap: 10px; /* 减小间距 */
    padding: 20px 8px; /* 减小左右padding */
    background: rgba(0, 0, 0, 0.3);
    border-right: 1px solid rgba(217, 27, 122, 0.3);
    overflow-y: auto; /* 允许滚动 */
    overflow-x: hidden;
    transition: transform 0.3s ease, opacity 0.3s ease;
    position: relative;
}

/* Desktop only: collapsed sidebar slides out and fades */
@media (min-width: 769px) {
    .deck-selector-column.collapsed {
        transform: translateX(-100px);
        opacity: 0;
        pointer-events: none;
    }
}

.column-collapse-handle {
    position: fixed;
    left: 100px; /* Start at edge of sidebar */
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 60px;
    background: rgba(217, 27, 122, 0.3);
    border: 1px solid rgba(217, 27, 122, 0.5);
    border-left: none;
    border-radius: 0 8px 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: left 0.3s ease, background 0.3s ease, width 0.3s ease;
    z-index: 100;
}

/* Handle is now outside column - use sibling selector */
.deck-selector-column.collapsed + .column-collapse-handle {
    left: 0; /* Move to left edge when collapsed */
}

.column-collapse-handle:hover {
    background: rgba(217, 27, 122, 0.5);
    width: 24px;
}

.collapse-icon {
    font-size: 14px;
    color: #fff;
    transition: transform 0.3s ease;
    user-select: none;
}

/* Use sibling selector for icon rotation */
.deck-selector-column.collapsed + .column-collapse-handle .collapse-icon {
    transform: rotate(180deg);
}

.deck-type-btn {
    padding: 10px 12px; /* 更紧凑 */
    background: rgba(74, 85, 104, 0.3);
    border: 1px solid rgba(217, 27, 122, 0.3);
    border-radius: 6px; /* 略小的圆角 */
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px; /* 略小字体 */
    font-weight: 500;
    letter-spacing: 0.5px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    white-space: nowrap;
}

.deck-type-btn:hover {
    background: rgba(217, 27, 122, 0.3);
    transform: translateY(-2px);
}

.deck-type-btn.active {
    background: rgba(217, 27, 122, 0.6);
    border-color: #d91b7a;
    box-shadow: 0 0 15px rgba(217, 27, 122, 0.5);
}

/* 主要操作区域 */
.main-area {
    grid-column: 2;
    grid-row: 2;
    position: relative;
    background: rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.deck-pile {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: var(--card-width);
    height: var(--card-height); /* 匹配card尺寸 */
    cursor: pointer;
    transition: transform 0.2s ease-out;
    z-index: 10;
    user-select: none;
}

.deck-pile:hover {
    transform: translate(-50%, -50%) scale(1.05);
}

.deck-pile.shuffling .deck-card {
    animation: shuffleCardAnimation 0.8s ease-in-out;
}

.deck-pile.shuffling .deck-card:nth-child(1) {
    animation: shuffleCard1 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(2) {
    animation: shuffleCard2 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(3) {
    animation: shuffleCard3 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(4) {
    animation: shuffleCard4 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(5) {
    animation: shuffleCard5 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(6) {
    animation: shuffleCard6 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(7) {
    animation: shuffleCard7 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(8) {
    animation: shuffleCard8 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(9) {
    animation: shuffleCard9 0.8s ease-in-out;
}
.deck-pile.shuffling .deck-card:nth-child(10) {
    animation: shuffleCard10 0.8s ease-in-out;
}

@keyframes shuffleCard1 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-65px, 0) rotate(-10deg); }
    50% { transform: translate(-25px, 0) rotate(-3deg); }
    75% { transform: translate(-50px, 0) rotate(-7deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard2 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(55px, 0) rotate(9deg); }
    50% { transform: translate(20px, 0) rotate(2deg); }
    75% { transform: translate(45px, 0) rotate(6deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard3 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-70px, 0) rotate(-11deg); }
    50% { transform: translate(-30px, 0) rotate(-4deg); }
    75% { transform: translate(-55px, 0) rotate(-8deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard4 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(60px, 0) rotate(10deg); }
    50% { transform: translate(25px, 0) rotate(3deg); }
    75% { transform: translate(50px, 0) rotate(7deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard5 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-58px, 0) rotate(-9deg); }
    50% { transform: translate(-22px, 0) rotate(-2deg); }
    75% { transform: translate(-48px, 0) rotate(-6deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard6 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(52px, 0) rotate(8deg); }
    50% { transform: translate(18px, 0) rotate(2deg); }
    75% { transform: translate(42px, 0) rotate(5deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard7 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-62px, 0) rotate(-10deg); }
    50% { transform: translate(-28px, 0) rotate(-3deg); }
    75% { transform: translate(-52px, 0) rotate(-7deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard8 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(57px, 0) rotate(9deg); }
    50% { transform: translate(23px, 0) rotate(3deg); }
    75% { transform: translate(47px, 0) rotate(6deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard9 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(-68px, 0) rotate(-11deg); }
    50% { transform: translate(-32px, 0) rotate(-4deg); }
    75% { transform: translate(-58px, 0) rotate(-8deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}
@keyframes shuffleCard10 {
    0% { transform: translate(0, 0) rotate(0deg); }
    25% { transform: translate(63px, 0) rotate(10deg); }
    50% { transform: translate(27px, 0) rotate(3deg); }
    75% { transform: translate(53px, 0) rotate(7deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes shuffleCardAnimation {
    0% { transform: translate(0, 0) rotate(0deg); }
    20% { transform: translate(-50px, 0) rotate(-5deg); }
    40% { transform: translate(60px, 0) rotate(5deg); }
    60% { transform: translate(-45px, 0) rotate(-3deg); }
    80% { transform: translate(40px, 0) rotate(3deg); }
    100% { transform: translate(0, 0) rotate(0deg); }
}

.deck-card.entering {
    animation: cardEnterAnimation 0.5s ease-out forwards;
}

@keyframes cardEnterAnimation {
    0% {
        transform: translate(0, -300px) rotate(0deg) scale(0.8);
        opacity: 0;
    }
    50% {
        transform: translate(0, -50px) rotate(0deg) scale(1.02);
        opacity: 0.8;
    }
    80% {
        transform: translate(0, 5px) rotate(0deg) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(0, 0) rotate(0deg) scale(1);
        opacity: 1;
    }
}

.deck-card {
    position: absolute;
    width: var(--card-width);
    height: var(--card-height); /* 使用与card相同的CSS变量 */
    border-radius: 6px;
    background: #2a2d3a;
    background-image: url("data:image/svg+xml,%3Csvg width='18' height='31' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='tinydots' width='0.8' height='0.8' patternUnits='userSpaceOnUse'%3E%3Ccircle cx='0.4' cy='0.4' r='0.15' fill='%23ffffff' opacity='0.3'/%3E%3C/pattern%3E%3Cpattern id='crosshatch' width='1' height='1' patternUnits='userSpaceOnUse'%3E%3Cpath d='M0 0 L1 1 M1 0 L0 1' stroke='%23ffffff' stroke-width='0.08' opacity='0.15'/%3E%3C/pattern%3E%3C/defs%3E%3Cg%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='url(%23crosshatch)'/%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='url(%23tinydots)'/%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='none' stroke='%23ffffff' stroke-width='0.3' opacity='0.4'/%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='none' stroke='%23d91b7a' stroke-width='0.6'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 15px 26px;
    border: 2px solid #d91b7a;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.deck-card:nth-child(1) { transform: translate(0, 0); z-index: 10; }
.deck-card:nth-child(2) { transform: translate(1px, 1px); z-index: 9; }
.deck-card:nth-child(3) { transform: translate(2px, 2px); z-index: 8; }
.deck-card:nth-child(4) { transform: translate(3px, 3px); z-index: 7; }
.deck-card:nth-child(5) { transform: translate(4px, 4px); z-index: 6; }
.deck-card:nth-child(6) { transform: translate(5px, 5px); z-index: 5; }
.deck-card:nth-child(7) { transform: translate(6px, 6px); z-index: 4; }
.deck-card:nth-child(8) { transform: translate(7px, 7px); z-index: 3; }
.deck-card:nth-child(9) { transform: translate(8px, 8px); z-index: 2; }
.deck-card:nth-child(10) { transform: translate(9px, 9px); z-index: 1; }

.deck-base-hit {
    position: absolute;
    bottom: -15px;
    left: -5px;
    width: calc(100% + 10px);
    height: 30px;
    cursor: grab;
    pointer-events: auto;
}

.deck-right-hit {
    position: absolute;
    top: 0;
    right: -10px;
    width: 15px;
    height: 100%;
    cursor: grab;
    pointer-events: auto;
    z-index: 11;
}

.deck-pile-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.9);
    font-size: 16px;
    font-weight: bold;
    text-align: center;
    z-index: 10;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.card {
    width: var(--card-width);
    height: var(--card-height);
    border-radius: 6px;
    position: absolute;
    cursor: grab;
    transition: box-shadow 0.3s ease;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
    transform-style: preserve-3d;
    will-change: transform, left, top;
    user-select: none;
}

.card,
.deck-pile,
.slot-drag-handle {
    touch-action: none;
}

.card:active {
    cursor: grabbing;
}

.card:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 40px rgba(217, 27, 122, 0.4);
    z-index: 1000 !important;
}

.card.revealed .card-front {
    transform: rotateY(0deg);
}

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

.card:not(.revealed) .card-front {
    transform: rotateY(180deg);
}

.card:not(.revealed) .card-back {
    transform: rotateY(0deg);
}

.card-front,
.card-back {
    width: 100%;
    height: 100%;
    position: absolute;
    backface-visibility: hidden;
    border-radius: 8px;
    transition: transform 0.6s;
}

.card-front {
    background: white;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #d91b7a;
    overflow: hidden;
    transform: rotateY(180deg);
}

.card-front img {
    width: 104%; /* 放大一点避免白边 */
    height: 104%;
    object-fit: cover;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.card-back {
    transform: rotateY(0deg);
    background: #2a2d3a;
    background-image: url("data:image/svg+xml,%3Csvg width='18' height='31' xmlns='http://www.w3.org/2000/svg'%3E%3Cdefs%3E%3Cpattern id='tinydots' width='0.8' height='0.8' patternUnits='userSpaceOnUse'%3E%3Ccircle cx='0.4' cy='0.4' r='0.15' fill='%23ffffff' opacity='0.3'/%3E%3C/pattern%3E%3Cpattern id='crosshatch' width='1' height='1' patternUnits='userSpaceOnUse'%3E%3Cpath d='M0 0 L1 1 M1 0 L0 1' stroke='%23ffffff' stroke-width='0.08' opacity='0.15'/%3E%3C/pattern%3E%3C/defs%3E%3Cg%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='url(%23crosshatch)'/%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='url(%23tinydots)'/%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='none' stroke='%23ffffff' stroke-width='0.3' opacity='0.4'/%3E%3Cpath d='M9 0 L18 15.5 L9 31 L0 15.5 Z' fill='none' stroke='%23d91b7a' stroke-width='0.6'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 18px 31px;
    border: 2px solid #d91b7a;
}

.spread-slots {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.spread-slots.active {
    display: block;
}

/* Optimized layout system for all spreads */
.spread-slots.optimized-layout {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Ensure optimized layouts are properly centered vertically - account for spread row and controls */
.spread-slots.optimized-layout,
.spread-slots.celtic-layout {
    /* Account for: spread row height (~60px) + controls area (~100px including buttons and margin) */
    padding-top: var(--spread-top-offset);
    padding-bottom: calc(var(--spread-top-offset) + 20px);
    box-sizing: border-box;
}

/* Unified center line calculation - all spreads align to this baseline */
/* The center line is at: container center (50%) adjusted for padding */
/* Horizontal spreads naturally center at this line via align-items: center */
/* Grid layouts need their grid-row: 2 center to align to this same line */

/* Unified vertical center alignment - all spreads align to horizontal spread center line */
/* Horizontal spreads (single, three, five, seven) use align-items: center, creating a baseline */
/* All grid layouts align their grid-row: 2 to this horizontal spread center line */
/* This ensures consistent vertical positioning across all spreads */

/* SYSTEMATIC ISSUE ANALYSIS:
 * Problem: Grid layouts are offset by half card height compared to horizontal spreads
 * Root Cause: 
 *   - Horizontal spreads: Cards are direct flex children, align-items: center aligns card CENTER to flex center
 *   - Grid layouts: Grid is flex child, align-items: center aligns GRID CENTER to flex center
 *   - Grid-row: 2 center = Grid center = flex center (correct)
 *   - BUT: Grid's align-items: center aligns SLOT CENTER within row, not CARD CENTER
 *   - Slot height = card height (140px), so slot center = card center (correct)
 *   - However, the visual alignment issue suggests grid-row positioning vs card positioning mismatch
 *   
 * The real issue: When grid uses align-items: center, grid-row: 2's CENTER LINE aligns with flex center.
 * But we want grid-row: 2's CARD CENTER (which is at row center + card center offset) to align.
 * Since card center = row center (both 70px from row top), they should match...
 * 
 * ACTUAL ISSUE: The padding-top/bottom on .spread-slots.optimized-layout creates an offset!
 * Horizontal spreads center within the padded area, but grids center within the full container.
 * This creates a systematic offset that needs correction.
 */

/* Visual feedback for card over deck */
.card.over-deck {
    opacity: 0.7;
    transform: scale(1.1) !important;
}

/* Single card - perfectly centered */
.spread-slots.single-layout {
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Horizontal line layouts (3, 5, 7 cards) */
.spread-slots.horizontal-layout {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: var(--card-gap);
}

/* Pyramid layout (4 cards) */
/* Uses CSS Grid with proper centering */
.spread-slots.pyramid-layout {
    display: grid;
    grid-template-columns: repeat(3, calc(var(--card-width) + 8px));
    grid-template-rows: repeat(2, calc(var(--card-height) + 8px));
    gap: var(--card-gap);
    justify-content: center;
    align-content: center; /* Vertically center the entire grid */
}

/* Cross layout (5 cards) - Love Cross */
/* Uses CSS Grid for proper 3x3 centering */
.spread-slots.cross-layout {
    display: grid;
    grid-template-columns: repeat(3, calc(var(--card-width) + 8px));
    grid-template-rows: repeat(3, calc(var(--card-height) + 8px));
    gap: var(--card-gap);
    justify-content: center;
    align-content: center; /* Vertically center the entire grid */
    /* No margin-top hack - use proper centering */
}

/* Spirit layout (6 cards - 2x3 grid) */
/* Uses CSS Grid with proper centering */
.spread-slots.spirit-layout {
    display: grid;
    grid-template-columns: repeat(3, calc(var(--card-width) + 8px));
    grid-template-rows: repeat(2, calc(var(--card-height) + 8px));
    gap: var(--card-gap);
    justify-content: center;
    align-content: center; /* Vertically center the entire grid */
}

/* Tree layout (7 cards) */
/* Uses CSS Grid with proper centering */
.spread-slots.tree-layout {
    display: grid;
    grid-template-columns: repeat(3, calc(var(--card-width) + 8px));
    grid-template-rows: repeat(3, calc(var(--card-height) + 8px));
    gap: var(--card-gap);
    justify-content: center;
    align-content: center; /* Vertically center the entire grid */
}

/* Nine grid layout (3x3) - Lenormand */
/* Uses CSS Grid with proper centering */
.spread-slots.nine-grid-layout {
    display: grid;
    grid-template-columns: repeat(3, calc(var(--card-width) + 8px));
    grid-template-rows: repeat(3, calc(var(--card-height) + 8px));
    gap: var(--card-gap);
    justify-content: center;
    align-content: center; /* Vertically center the entire grid */
}

/* Celtic Cross optimized layout */
.spread-slots.celtic-layout {
    display: flex;
    justify-content: center;
    align-items: center;
    --cross-to-staff-gap: 48px;
    --rotated-card-width: 140px;
    --rotated-card-height: 100px;
}

.celtic-cross-section {
    display: grid;
    grid-template-columns: var(--card-width) var(--card-width) var(--card-width);
    grid-template-rows: var(--card-height) var(--card-height) var(--card-height);
    gap: var(--card-gap);
    position: relative;
    align-items: center;
    justify-items: center;
}

.celtic-staff-section {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: var(--card-gap);
    margin-left: var(--cross-to-staff-gap);
}

.celtic-slot {
    position: relative;
    width: var(--card-width);
    height: var(--card-height);
}

.celtic-slot.rotated {
    width: var(--rotated-card-width);
    height: var(--rotated-card-height);
}

.celtic-slot[data-position="1"] {
    grid-column: 2;
    grid-row: 2;
    z-index: 2;
}

.celtic-slot[data-position="2"] {
    grid-column: 2;
    grid-row: 2;
    width: var(--rotated-card-width);
    height: var(--rotated-card-height);
    z-index: 1;
}

.celtic-slot[data-position="3"] {
    grid-column: 2;
    grid-row: 1;
}

.celtic-slot[data-position="4"] {
    grid-column: 2;
    grid-row: 3;
}

.celtic-slot[data-position="5"] {
    grid-column: 3;
    grid-row: 2;
}

.celtic-slot[data-position="6"] {
    grid-column: 1;
    grid-row: 2;
}

/* Ensure slots maintain their styling in optimized layouts */
.optimized-layout .slot,
.single-layout .slot,
.horizontal-layout .slot,
.pyramid-layout .slot,
.cross-layout .slot,
.spirit-layout .slot,
.tree-layout .slot,
.nine-grid-layout .slot,
.celtic-layout .slot {
    position: relative;
    left: auto !important;
    top: auto !important;
}

/* Grid position helpers */
.pyramid-slot[data-position="1"] { grid-column: 1; grid-row: 2; }
.pyramid-slot[data-position="2"] { grid-column: 2; grid-row: 2; }
.pyramid-slot[data-position="3"] { grid-column: 3; grid-row: 2; }
.pyramid-slot[data-position="4"] { grid-column: 2; grid-row: 1; }

.cross-slot[data-position="1"] { grid-column: 2; grid-row: 2; }
.cross-slot[data-position="2"] { grid-column: 1; grid-row: 2; }
.cross-slot[data-position="3"] { grid-column: 3; grid-row: 2; }
.cross-slot[data-position="4"] { grid-column: 2; grid-row: 1; }
.cross-slot[data-position="5"] { grid-column: 2; grid-row: 3; }

.spirit-slot[data-position="1"] { grid-column: 1; grid-row: 1; }
.spirit-slot[data-position="2"] { grid-column: 3; grid-row: 1; }
.spirit-slot[data-position="3"] { grid-column: 1; grid-row: 2; }
.spirit-slot[data-position="4"] { grid-column: 3; grid-row: 2; }
.spirit-slot[data-position="5"] { grid-column: 2; grid-row: 1; }
.spirit-slot[data-position="6"] { grid-column: 2; grid-row: 2; }

.tree-slot[data-position="1"] { grid-column: 1; grid-row: 1; }
.tree-slot[data-position="2"] { grid-column: 1; grid-row: 2; }
.tree-slot[data-position="3"] { grid-column: 3; grid-row: 1; }
.tree-slot[data-position="4"] { grid-column: 3; grid-row: 2; }
.tree-slot[data-position="5"] { grid-column: 2; grid-row: 2; }
.tree-slot[data-position="6"] { grid-column: 2; grid-row: 1; }
.tree-slot[data-position="7"] { grid-column: 2; grid-row: 3; }

@media (max-width: 1200px) {
    .spread-slots.optimized-layout,
    .spread-slots.celtic-layout {
        --card-gap: 20px;
    }
    .spread-slots.celtic-layout {
        --cross-to-staff-gap: 36px;
    }
}

@media (max-width: 900px) {
    .spread-slots.optimized-layout,
    .spread-slots.celtic-layout {
        --card-gap: 16px;
        --card-width: 85px;
        --card-height: 145px; /* 85px * 1.71 = 145px (correct tarot ratio) */
    }
    .spread-slots.celtic-layout {
        --cross-to-staff-gap: 28px;
        --rotated-card-width: 126px;
        --rotated-card-height: 90px;
    }
}

.slot {
    position: absolute;
    width: calc(var(--card-width) + 8px);
    height: calc(var(--card-height) + 8px);
    border: 2px dashed rgba(217, 27, 122, 0.4);
    border-radius: 8px;
    background: rgba(217, 27, 122, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    transition: all 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.slot[data-angle="90"] {
    width: calc(var(--card-height) + 8px);
    height: calc(var(--card-width) + 8px);
}

.slot.filled {
    border-color: rgba(217, 27, 122, 0.8);
    background: rgba(217, 27, 122, 0.2);
}

.slot.highlight {
    border-color: rgba(255, 215, 0, 0.9);
    background: rgba(255, 215, 0, 0.15);
    box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
}

.slot-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    padding: 5px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
}

/* In creation mode, position label below slot */
.slot.creating .slot-label {
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    background: rgba(217, 27, 122, 0.6);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
}

.card-counter {
    position: absolute;
    bottom: 45px; /* Above copyright notice */
    right: max(8px, 2vw); /* Responsive right padding */
    background: rgba(217, 27, 122, 0.9);
    color: white;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 12px; /* Smaller, like spread buttons */
    font-weight: 500;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.controls {
    /* 桌面端：在左侧列底部显示 */
    position: fixed;
    bottom: 40px;
    left: 6px;
    width: 88px; /* 匹配左侧列宽度 */
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 1000;
    padding: 0;
    pointer-events: auto;
}

.controls > * {
    pointer-events: auto; /* Re-enable clicks on buttons */
}

.control-btn,
.create-spread-btn,
.save-spread-btn,
.finish-create-btn,
.customize-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 6px 8px;
    min-width: 48px;
    height: 48px;
    background: rgba(217, 27, 122, 0.5);
    border: 1px solid rgba(217, 27, 122, 0.4);
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    font-size: 10px;
    transition: all 0.3s ease;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-icon {
    font-size: 14px;
    line-height: 1;
}

.btn-text {
    font-size: 9px;
    font-weight: 500;
    line-height: 1;
    white-space: nowrap;
}

.control-btn:hover,
.create-spread-btn:hover,
.save-spread-btn:hover,
.finish-create-btn:hover,
.customize-btn:hover {
    background: rgba(217, 27, 122, 0.7);
    border-color: #d91b7a;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(217, 27, 122, 0.4);
}

.control-btn:active,
.create-spread-btn:active,
.save-spread-btn:active,
.finish-create-btn:active,
.customize-btn:active {
    transform: translateY(0);
}

.control-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Reversals toggle button - 确保优先级高于.control-btn */
.control-btn.reversals-toggle {
    background: rgba(100, 100, 100, 0.4) !important;
    border-color: rgba(150, 150, 150, 0.4) !important;
}
.control-btn.reversals-toggle.active {
    background: rgba(147, 51, 234, 0.6) !important;
    border-color: rgba(147, 51, 234, 0.8) !important;
}
.control-btn.reversals-toggle.active:hover {
    background: rgba(147, 51, 234, 0.8) !important;
    box-shadow: 0 0 15px rgba(147, 51, 234, 0.4);
}
.control-btn.reversals-toggle:hover:not(.active) {
    background: rgba(100, 100, 100, 0.6) !important;
    border-color: rgba(150, 150, 150, 0.6) !important;
}

/* Reversed card - combine with flip animation (no visible indicator) */
.card.reversed.revealed .card-front {
    transform: rotateY(0deg) rotateZ(180deg);
}
.card.reversed:not(.revealed) .card-front {
    transform: rotateY(180deg) rotateZ(180deg);
}

/* Responsive spread container */
.spread-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spread-info-box {
    display: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(217, 27, 122, 0.15);
    border: 2px solid rgba(217, 27, 122, 0.6);
    border-radius: 16px;
    padding: 30px 40px;
    color: rgba(217, 27, 122, 0.9);
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    z-index: 500;
    max-width: 90%;
    box-shadow: 0 8px 32px rgba(217, 27, 122, 0.3);
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.spread-info-box.show {
    display: block;
}

@media (max-width: 1200px) {
    .spread-info-box {
        font-size: 14px;
        padding: 25px 35px;
    }
}

/* Customization box for three-card spread */
.customization-box {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(26, 26, 46, 0.95);
    backdrop-filter: blur(15px);
    border: 2px solid rgba(217, 27, 122, 0.6);
    border-radius: 12px;
    padding: 20px 30px;
    display: none;
    flex-direction: column;
    gap: 15px;
    z-index: 2000;
    min-width: 400px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    box-shadow: 0 8px 32px rgba(217, 27, 122, 0.3);
}

.customization-box.show {
    display: flex;
}

.customization-title {
    color: rgba(217, 27, 122, 0.9);
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 5px;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

@media (max-width: 768px) {
    .customization-box {
        position: fixed;
        top: 50%;
        bottom: auto;
        transform: translate(-50%, -50%);
        width: calc(100% - 32px);
        min-width: unset;
        padding: 18px 20px;
    }
}

.customization-input-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.customization-label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 13px;
    margin-bottom: 4px;
}

.customization-input {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(217, 27, 122, 0.4);
    border-radius: 8px;
    padding: 10px 15px;
    color: #fff;
    font-size: 14px;
    transition: all 0.3s ease;
}

.customization-input:focus {
    outline: none;
    border-color: rgba(217, 27, 122, 0.8);
    background: rgba(255, 255, 255, 0.15);
}

.customization-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 5px;
}

.customization-btn {
    padding: 8px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.customization-btn.apply {
    background: rgba(217, 27, 122, 0.8);
    color: #fff;
}

.customization-btn.apply:hover {
    background: rgba(217, 27, 122, 1);
}

.customization-btn.cancel {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

.customization-btn.cancel:hover {
    background: rgba(255, 255, 255, 0.2);
}

.customize-btn {
    padding: 8px 16px;
    background: rgba(217, 27, 122, 0.6);
    border: 1px solid rgba(217, 27, 122, 0.4);
    color: #fff;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.customize-btn:hover {
    background: rgba(217, 27, 122, 0.8);
    border-color: #d91b7a;
    transform: translateY(-2px);
    box-shadow: 0 0 15px rgba(217, 27, 122, 0.4);
}

.loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #d91b7a;
    font-size: 20px;
    z-index: 2000;
    display: none;
}

.loading::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(217, 27, 122, 0.3);
    border-top-color: #d91b7a;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 10px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Card Reader Specific Styles - Saved Spreads, Hints, etc. */
/* Card Reader Specific Styles - Saved Spreads, Hints, etc. */

:root {
    /* 标准塔罗牌比例 1:1.71 (70mm x 120mm) */
    --card-width: clamp(70px, 18vw, 100px);
    --card-height: clamp(120px, 30vw, 171px); /* 171px = 100px * 1.71 */
    --card-gap: clamp(12px, 3vw, 24px);
    --spread-top-offset: clamp(40px, 7vh, 100px);
    --spread-creation-padding: clamp(12px, 2vw, 24px);
    --controls-stack-gap: 12px;
}

/* Desktop: Horizontal toolbar layout (reverted from column layout) */
@media (min-width: 769px) {
    .spreads-toolbar {
        /* Desktop 默认在 grid 里显示，不需要 !important */
        position: relative;
        grid-column: 2;
        grid-row: 1;
        left: auto;
        top: auto;
        width: auto;
        height: auto;
        display: flex;
        flex-direction: row;
    }

    /* Desktop button styles - ensure full buttons with text */
    .control-btn,
    .create-spread-btn,
    .save-spread-btn,
    .finish-create-btn,
    .customize-btn {
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 6px 8px;
        min-width: 48px;
        height: 48px;
        background: rgba(217, 27, 122, 0.5);
        border: 1px solid rgba(217, 27, 122, 0.4);
        color: #fff;
        border-radius: 10px;
        cursor: pointer;
        font-size: 10px;
        transition: all 0.3s ease;
        white-space: nowrap;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    }

    .btn-icon {
        font-size: 16px;
        line-height: 1;
        display: block;
    }

    .btn-text {
        font-size: 9px;
        font-weight: 500;
        line-height: 1;
        display: block;
    }
}

/* Mobile toggle button - hidden by default (desktop) */
.spreads-toolbar-toggle {
    display: none;
}

.spreads-toolbar-backdrop {
    display: none;
}

.spreads-toolbar {
    scroll-padding-left: 16px;
}

.spread-cache-tray {
    min-height: 32px;
}

.spread-cache-pill {
    font-size: 12px;
}

.ping-layer {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 1100;
}

.ping-marker {
    position: absolute;
    width: 64px;
    height: 64px;
    border-radius: 999px;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    opacity: 0;
    animation: pingPulse 2.5s ease-out forwards;
}

.ping-marker__label {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 12px;
    font-weight: 600;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
}

.ping-marker--default {
    background: rgba(59, 130, 246, 0.35);
    border: 2px solid rgba(59, 130, 246, 0.9);
}

.ping-marker--info {
    background: rgba(14, 165, 233, 0.35);
    border: 2px solid rgba(14, 165, 233, 0.9);
}

.ping-marker--warning {
    background: rgba(251, 191, 36, 0.35);
    border: 2px solid rgba(251, 191, 36, 0.9);
}

.ping-marker--success {
    background: rgba(16, 185, 129, 0.35);
    border: 2px solid rgba(16, 185, 129, 0.9);
}

.ping-marker--fade {
    opacity: 0;
}

@keyframes pingPulse {
    0% {
        opacity: 0.9;
        transform: translate(-50%, -50%) scale(0.6);
    }
    60% {
        opacity: 0.8;
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(1.3);
    }
}

.spread-slots.optimized-layout,
.spread-slots.celtic-layout {
    padding-top: var(--spread-top-offset);
    padding-bottom: calc(var(--spread-top-offset) + 20px);
}

@media (max-width: 768px) {
    .spread-slots.optimized-layout,
    .spread-slots.celtic-layout {
        padding-top: calc(var(--spread-top-offset) * 0.5);
        padding-bottom: calc(var(--spread-top-offset) * 0.7);
    }
}

@media (max-width: 768px) {
    :root {
        /* 保持塔罗牌比例 1:1.71 */
        --card-width: clamp(50px, 22vw, 75px);
        --card-height: clamp(86px, 37vw, 128px); /* 128px = 75px * 1.71 */
        --card-gap: clamp(8px, 2vw, 16px);
    }

    /* Mobile: reduce slot border gap from 8px to 4px for better visual fit */
    .slot {
        width: calc(var(--card-width) + 4px);
        height: calc(var(--card-height) + 4px);
    }

    body {
        padding-top: 70px;
    }

    /* Mobile: 无sidebar的垂直堆叠布局 */
    .main-container {
        display: flex;
        flex-direction: column;
        height: calc(100vh - 70px);
        gap: 0;
    }

    /* Mobile: deck-selector as collapsible floating box */
    .deck-selector-column {
        position: fixed;
        bottom: 100px;
        right: 10px;
        z-index: 25;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        width: auto;
        min-width: 80px;
        height: auto;
        overflow: hidden;
        background: rgba(0, 0, 0, 0.85);
        border: 1px solid rgba(217, 27, 122, 0.5);
        border-radius: 8px;
        padding: 0;
        gap: 0;
        transform: none !important;
        transition: all 0.2s ease;
    }

    /* Collapsed state: only show active button */
    .deck-selector-column.collapsed .deck-type-btn:not(.active) {
        display: none;
    }

    .deck-selector-column.collapsed {
        border-radius: 20px;
        min-width: 70px;
    }

    /* Mobile: 隐藏toggle handle */
    .column-collapse-handle {
        display: none !important;
    }

    .deck-type-btn {
        width: 100%;
        padding: 8px 14px;
        font-size: 11px;
        text-align: center;
        border-radius: 0;
        border: none;
        border-bottom: 1px solid rgba(217, 27, 122, 0.2);
    }

    .deck-type-btn:last-child {
        border-bottom: none;
    }

    .deck-type-btn.active {
        background: rgba(217, 27, 122, 0.3);
    }

    /* Collapsed: rounded active button */
    .deck-selector-column.collapsed .deck-type-btn.active {
        border-radius: 20px;
        border-bottom: none;
    }

    /* Mobile: deck尺寸使用CSS变量与card保持一致 */
    .deck-pile-label {
        font-size: 12px;
        line-height: 1.2;
    }

    .deck-hint {
        font-size: 6px;
        margin-top: 3px;
        line-height: 1.1;
        opacity: 0.8;
    }

    /* Mobile: spreads toolbar 全宽显示 */
    .spreads-toolbar {
        position: fixed;
        top: 70px;
        left: 0;
        right: 0;
        display: flex;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 6px 10px;
        gap: 8px;
        background: rgba(0, 0, 0, 0.6);
        border-bottom: 1px solid rgba(217, 27, 122, 0.3);
        min-height: 42px;
        -webkit-overflow-scrolling: touch;
        z-index: 30;
        touch-action: pan-x; /* Allow horizontal scrolling on touch devices */
    }

    /* Allow touch scrolling on spread items - don't block pan gestures */
    .spreads-toolbar .spread-item,
    .spreads-toolbar .spread-item-wrapper {
        touch-action: pan-x;
    }

    .spreads-toolbar .spreads-row {
        display: flex;
        flex-direction: row;
        gap: 8px;
        flex-wrap: nowrap;
        align-items: center;
    }

    .spreads-toolbar .reset-spreads-btn {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 4px 10px;
        font-size: 11px;
    }

    /* Mobile: 隐藏hint和hide按钮 */
    .spread-hint-btn,
    .spread-hide-btn {
        display: none !important;
    }

    /* Mobile 时隐藏 toggle button */
    .spreads-toolbar-toggle {
        display: none !important;
    }

    /* Backdrop overlay for side panel */
    .spreads-toolbar-backdrop {
        display: none;
    }

    .spreads-row {
        flex: 1 0 auto;
        min-width: 50px;
    }

    .spread-cache-tray {
        flex-shrink: 0;
        justify-content: flex-start;
    }

    .main-area {
        flex: 1;
        min-height: 60vh;
        margin-top: 42px; /* spread toolbar(42px) only - deck selector is now floating */
    }

    .controls {
        position: fixed;
        bottom: 55px; /* Above copyright */
        left: 6px;
        transform: none;
        width: auto;
        padding: 0;
        gap: 4px;
        flex-direction: column; /* 垂直排列 */
        flex-wrap: nowrap;
        justify-content: flex-start;
        align-items: flex-start;
        background: transparent; /* 无背景 */
        backdrop-filter: none;
        border-radius: 0;
        z-index: 25;
    }

    .control-btn,
    .save-spread-btn,
    .finish-create-btn,
    .customize-btn,
    .create-spread-btn {
        width: 36px; /* 更方正 */
        min-width: 36px;
        height: 36px;
        padding: 2px;
        flex-direction: column;
        gap: 1px;
        border-radius: 6px;
    }

    .btn-icon {
        font-size: 14px;
    }

    .btn-text {
        font-size: 6px;
    }

    /* Spread items更紧凑 */
    .spread-item {
        padding: 5px 12px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    :root {
        /* 保持塔罗牌比例 1:1.71 */
        --card-width: clamp(45px, 20vw, 65px);
        --card-height: clamp(77px, 34vw, 111px); /* 111px = 65px * 1.71 */
        --spread-top-offset: clamp(32px, 6vh, 80px);
    }

    .deck-selector-column {
        bottom: 90px;
        right: 8px;
        min-width: 70px;
    }

    .deck-type-btn {
        font-size: 10px;
        padding: 6px 10px;
    }

    .spread-cache-pill {
        font-size: 10px;
        padding: 3px 8px;
    }

    .spreads-toolbar {
        min-height: 38px;
        padding: 5px 8px;
        gap: 6px;
    }

    .main-area {
        margin-top: 38px; /* spread toolbar(38px) only */
    }

    .controls {
        bottom: 50px;
        left: 4px;
    }

    .control-btn,
    .save-spread-btn,
    .finish-create-btn,
    .customize-btn,
    .create-spread-btn {
        width: 32px;
        min-width: 32px;
        height: 32px;
        padding: 2px;
    }

    .btn-icon {
        font-size: 12px;
    }

    .btn-text {
        font-size: 5px;
    }

    .spread-item {
        padding: 4px 10px;
        font-size: 11px;
    }

    .deck-pile-label {
        font-size: 10px;
    }
}

@media (max-width: 360px) {
    :root {
        /* 保持塔罗牌比例 1:1.71 */
        --card-width: clamp(40px, 18vw, 55px);
        --card-height: clamp(68px, 31vw, 94px); /* 94px = 55px * 1.71 */
        --card-gap: clamp(6px, 2vw, 12px);
    }

    .deck-selector-column {
        bottom: 80px;
        right: 6px;
        min-width: 60px;
    }

    .deck-type-btn {
        font-size: 9px;
        padding: 5px 8px;
    }

    .spreads-toolbar {
        min-height: 34px;
        padding: 4px 6px;
        gap: 5px;
    }

    .main-area {
        margin-top: 34px; /* spread toolbar(34px) only */
    }

    .controls {
        bottom: 45px;
        left: 3px;
        gap: 3px;
    }

    .control-btn,
    .save-spread-btn,
    .finish-create-btn,
    .customize-btn,
    .create-spread-btn {
        width: 28px;
        min-width: 28px;
        height: 28px;
        padding: 2px;
    }

    .btn-icon {
        font-size: 10px;
    }

    .btn-text {
        font-size: 4px;
    }

    .spread-item {
        padding: 3px 8px;
        font-size: 10px;
    }

    .spread-cache-pill {
        font-size: 9px;
        padding: 2px 6px;
    }

    .reset-spreads-btn {
        font-size: 9px;
        padding: 3px 8px;
    }

    .deck-pile-label {
        font-size: 9px;
    }
}

/* Saved Spreads Styles */
.spread-item.saved {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.4);
}

.spread-item.saved:hover {
    background: rgba(76, 175, 80, 0.4);
}

.spread-item-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    flex-shrink: 0; /* 防止在flex容器中被压缩 */
}

.spread-hint-btn {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.spread-hint-btn:hover {
    background: rgba(217, 27, 122, 0.5);
    border-color: #d91b7a;
}

.spread-delete-btn {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(244, 67, 54, 0.3);
    border: 1px solid rgba(244, 67, 54, 0.5);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    padding: 0;
}

.spread-delete-btn:hover {
    background: rgba(244, 67, 54, 0.5);
}

.spread-favorite-btn {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(255, 193, 7, 0.3);
    border: 1px solid rgba(255, 193, 7, 0.5);
    color: #ffc107;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

.spread-favorite-btn:hover {
    background: rgba(255, 193, 7, 0.5);
    transform: scale(1.1);
}

.spread-item.saved.pinned {
    border-color: rgba(255, 193, 7, 0.6);
    box-shadow: 0 0 8px rgba(255, 193, 7, 0.3);
}

.spread-item.saved.recent::after {
    content: '🔥';
    margin-left: 4px;
    font-size: 12px;
}

.spread-hide-btn {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(158, 158, 158, 0.3);
    border: 1px solid rgba(158, 158, 158, 0.5);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
}

.spread-hide-btn:hover {
    background: rgba(158, 158, 158, 0.5);
    transform: scale(1.1);
}

/* All control buttons use shared styles - only define state variations */
.save-spread-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.create-spread-btn.active {
    background: rgba(217, 27, 122, 0.9);
    box-shadow: 0 0 10px rgba(217, 27, 122, 0.5);
}

/* Custom spread creation mode */
.main-area.creating-spread {
    cursor: crosshair;
}

.main-area.creating-spread .deck-pile {
    pointer-events: none;
    opacity: 0.5;
}

.slot.creating {
    border-color: rgba(255, 152, 0, 0.8);
    box-shadow: 0 0 10px rgba(255, 152, 0, 0.5);
    position: relative;
}

.slot.creating:hover {
    border-color: rgba(255, 152, 0, 1);
    box-shadow: 0 0 15px rgba(255, 152, 0, 0.7);
}

/* Slot controls in creation mode */
.slot-delete-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(244, 67, 54, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #fff;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    padding: 0;
    line-height: 1;
}

.slot-delete-btn:hover {
    background: rgba(244, 67, 54, 1);
    transform: scale(1.1);
}

/* Drag handle - simplified, positioned at bottom center */
.slot-drag-handle {
    position: absolute;
    bottom: -10px;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 16px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: rgba(255, 255, 255, 0.8);
    font-size: 10px;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    z-index: 10;
    user-select: none;
    line-height: 1;
}

.slot-drag-handle:active {
    cursor: grabbing;
    background: rgba(217, 27, 122, 0.6);
}

.slot-drag-handle:hover {
    background: rgba(217, 27, 122, 0.4);
}

/* Hint Modal Styles */
.hint-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.hint-modal.show {
    display: flex;
}

.hint-modal-content {
    background: rgba(26, 26, 46, 0.95);
    border: 1px solid rgba(217, 27, 122, 0.3);
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.hint-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.hint-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #fff;
}

.hint-modal-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.hint-modal-close:hover {
    color: var(--primary-color);
}

.hint-modal-body {
    padding: 20px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.hint-modal-body h4 {
    color: #fff;
    margin-top: 16px;
    margin-bottom: 8px;
}

.hint-modal-body ul {
    margin: 8px 0;
    padding-left: 20px;
}

.hint-modal-body li {
    margin: 4px 0;
}

/* Manage Spreads Modal */
.manage-spreads-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.manage-spreads-modal.show {
    display: flex;
}

.manage-spreads-content {
    background: rgba(26, 26, 46, 0.95);
    border: 1px solid rgba(217, 27, 122, 0.3);
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.manage-spreads-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.manage-spreads-header h3 {
    margin: 0;
    font-size: 18px;
    color: #fff;
}

.manage-spreads-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.manage-spreads-close:hover {
    color: var(--primary-color);
}

.manage-spreads-tabs {
    display: flex;
    gap: 10px;
    padding: 15px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.manage-tab {
    padding: 8px 16px;
    background: rgba(74, 85, 104, 0.3);
    border: 1px solid rgba(217, 27, 122, 0.3);
    border-radius: 8px;
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
}

.manage-tab:hover {
    background: rgba(74, 85, 104, 0.5);
}

.manage-tab.active {
    background: rgba(217, 27, 122, 0.4);
    border-color: rgba(217, 27, 122, 0.6);
}

.manage-spreads-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.manage-spread-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    margin-bottom: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.manage-spread-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(217, 27, 122, 0.3);
}

.manage-spread-name {
    flex: 1;
    color: #fff;
    font-size: 14px;
}

.manage-spread-actions {
    display: flex;
    gap: 8px;
}

.manage-spread-action-btn {
    padding: 6px 12px;
    background: rgba(74, 85, 104, 0.3);
    border: 1px solid rgba(217, 27, 122, 0.3);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.3s ease;
}

.manage-spread-action-btn:hover {
    background: rgba(74, 85, 104, 0.5);
}

.manage-spread-action-btn.rename {
    background: rgba(33, 150, 243, 0.2);
    border-color: rgba(33, 150, 243, 0.4);
}

.manage-spread-action-btn.rename:hover {
    background: rgba(33, 150, 243, 0.4);
}

.manage-spread-action-btn.hide {
    background: rgba(158, 158, 158, 0.2);
    border-color: rgba(158, 158, 158, 0.4);
}

.manage-spread-action-btn.hide:hover {
    background: rgba(158, 158, 158, 0.4);
}

.manage-spread-action-btn.delete {
    background: rgba(244, 67, 54, 0.2);
    border-color: rgba(244, 67, 54, 0.4);
}

.manage-spread-action-btn.delete:hover {
    background: rgba(244, 67, 54, 0.4);
}

/* ===== Mobile Spread Edit Mode ===== */
.mobile-edit-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9998;
    pointer-events: auto;
}

.mobile-edit-overlay.active {
    display: block;
}

/* Keep spreads-toolbar above overlay when in edit mode */
body.spread-edit-mode .spreads-toolbar {
    z-index: 10000;
    position: relative;
}

/* Trash zone at bottom */
.mobile-trash-zone {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 300px;
    height: 80px;
    border: 3px dashed rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    background: rgba(244, 67, 54, 0.15);
    z-index: 10001;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.mobile-trash-zone.active {
    display: flex;
}

.mobile-trash-zone.drag-over {
    background: rgba(244, 67, 54, 0.4);
    border-color: #f44336;
    transform: translateX(-50%) scale(1.05);
}

.mobile-trash-icon {
    font-size: 36px;
    opacity: 0.8;
    transition: transform 0.2s ease;
}

.mobile-trash-zone.drag-over .mobile-trash-icon {
    transform: scale(1.2);
}

/* Spread item in edit mode */
body.spread-edit-mode .spread-item {
    cursor: grab;
    animation: wiggle 0.3s ease-in-out infinite;
}

body.spread-edit-mode .spread-item.dragging {
    cursor: grabbing;
    animation: none;
    opacity: 0.8;
    transform: scale(1.05);
    z-index: 10002;
}

@keyframes wiggle {
    0%, 100% { transform: rotate(-1deg); }
    50% { transform: rotate(1deg); }
}

/* Mobile drop indicators */
body.spread-edit-mode .spread-item.drop-before::before,
body.spread-edit-mode .spread-item.drop-after::before {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 28px;
    background: #d91b7a;
    border-radius: 2px;
    z-index: 100;
    box-shadow: 0 0 8px rgba(217, 27, 122, 0.9);
}

body.spread-edit-mode .spread-item.drop-before::before {
    left: -8px;
}

body.spread-edit-mode .spread-item.drop-after::before {
    right: -8px;
    left: auto;
}

