:root {
    --bg-color: #f5f5f5;
    --text-primary: #111111;
    --text-secondary: #777777;
    --border-color: #e5e5e5;
    --border-strong: #1a1a1a;
    --accent: #111111;
    --surface: #ffffff;
    --font-heading: 'Inter', 'Noto Sans JP', sans-serif;
    --font-body: 'Inter', 'Noto Sans JP', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--surface);
    min-height: 100vh;
    box-shadow: 0 0 40px rgba(0,0,0,0.05);
    padding-bottom: 3rem;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 2.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo-area h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.logo-area p {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 0.15rem;
}

/* Right side wrapper */
.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Login/Logout text button — small & clean */
.btn-text {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.04em;
    padding: 0.4rem 0.9rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-text:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: #f5f5f5;
}

/* + Add button — circle icon */
.btn-icon {
    background: var(--text-primary);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.btn-icon:hover {
    opacity: 0.75;
}

/* Stats */
.dashboard {
    padding: 0;
}

.stats-overview {
    display: flex;
    justify-content: center;
    gap: 4rem;
    padding: 2rem;
    border-bottom: 1px solid var(--border-color);
    background: #fdfdfd;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* Folder Bar */
.folder-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.85rem 2.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
    overflow: hidden;
}

.folder-bar-inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.folder-bar-inner::-webkit-scrollbar { display: none; }

.folder-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.35rem 0.9rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.folder-chip:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

.folder-chip.active {
    background: var(--text-primary);
    color: #fff;
    border-color: var(--text-primary);
}

.folder-chip .chip-count {
    font-size: 0.72rem;
    font-weight: 400;
    opacity: 0.6;
}

.folder-chip.active .chip-count {
    opacity: 0.8;
}

.folder-chip .chip-edit {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-left: 0.1rem;
    transition: opacity 0.2s;
}

.folder-chip:hover .chip-edit {
    opacity: 1;
}

.folder-add-btn {
    flex-shrink: 0;
    background: none;
    border: 1px dashed #ccc;
    color: #aaa;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.folder-add-btn:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* Folder card search */
.folder-search-wrap {
    position: relative;
    display: flex;
    align-items: center;
    margin-bottom: 0.65rem;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: #fafafa;
    padding: 0 0.75rem;
    transition: border-color 0.2s;
}

.folder-search-wrap:focus-within {
    border-color: #aaa;
    background: #fff;
}

.folder-search-icon {
    flex-shrink: 0;
    color: #aaa;
    margin-right: 0.5rem;
}

#folder-card-search {
    flex: 1;
    border: none;
    background: transparent;
    padding: 0.55rem 0;
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text-primary);
    outline: none;
}

#folder-card-search::placeholder {
    color: #bbb;
}

.folder-search-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: #bbb;
    font-size: 0.8rem;
    padding: 0 0 0 0.3rem;
    line-height: 1;
    transition: color 0.15s;
    flex-shrink: 0;
}

.folder-search-clear:hover { color: #555; }

/* Folder Modal card list */
.folder-card-list {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    max-height: 340px;
    overflow-y: auto;
    padding: 0.5rem 0.25rem;
}

.folder-card-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.35rem 0.4rem;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    font-size: 0.72rem;
    position: relative;
    text-align: center;
    user-select: none;
    max-width: 150px;
    min-width: 0;        /* grid cell 寬度限制必須 */
    overflow: hidden;    /* 確保任何溢出都被截斷 */
}

.folder-card-item:has(input:checked) {
    border-color: #111;
    background: #f8f8f8;
}

.folder-card-item:hover { border-color: #bbb; }

.folder-card-item input[type="checkbox"] {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: #111;
}

.folder-card-item .card-thumb-wrap {
    width: 100%;
    aspect-ratio: 3/4;
    overflow: hidden;
    border-radius: 4px;
    background: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-card-item .card-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1.5);
    transform-origin: center center;
}

.folder-card-item .card-label {
    display: block;
    width: 100%;
    min-width: 0;        /* 讓 grid cell 限制子元素寬度 */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 0.7rem;
    margin-top: 0.25rem;
    padding: 0 2px;
}

/* Collection List */
.collection-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 2rem;
    padding: 3rem;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.tcg-item {
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--surface);
    transition: box-shadow 0.3s;
    /* 確保即使在非常大的螢幕上，卡片也不會過度拉伸變形 */
    max-width: 320px; 
    margin: 0 auto; /* 置中排列 */
    width: 100%;
}

.tcg-item:hover {
    box-shadow: 0 10px 30px rgba(0,0,0,0.06);
}

/* Layout for Image and Details Side-by-Side internally */
.item-layout {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
}

@media (min-width: 600px) {
    /* For PC, within the 2-column grid, make inside layout side-by-side if you want, or keep it stacked. Stacking is best for 2 columns. */
}

.item-img-box {
    width: 100%;
    /* 使用比例控制高度會比寫死 300px 來得更舒服自然 */
    aspect-ratio: 4 / 5; 
    background: #fbfbfb;
    border: 1px solid #f0f0f0;
    border-radius: 12px;
    overflow: hidden; 
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.item-img-box img {
    max-width: 120%;
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1.5); 
    transform-origin: center center;
    transition: transform 0.4s ease;
}

.item-img-box:hover img {
    transform: scale(2.1);
}

.item-details {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    flex: 1;
}

.item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-title {
    font-size: 1.15rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s;
    /* Limit lines to standardize card heights */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: calc(1.15rem * 1.4 * 2); /* Reserve space for exactly 2 lines */
}

.item-title:hover {
    color: #444;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.grades-container {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 0.5rem;
    min-height: 80px; /* Ensure grade space doesn't pop heavily */
    max-height: 280px; /* Keep it contained so it doesn't break card layout */
    overflow-y: auto;
    padding-right: 4px; /* Space for the scrollbar */
}

/* Custom scrollbar for a cleaner App look */
.grades-container::-webkit-scrollbar {
    width: 4px;
}
.grades-container::-webkit-scrollbar-track {
    background: transparent;
}
.grades-container::-webkit-scrollbar-thumb {
    background: #e0e0e0;
    border-radius: 4px;
}

.grade-tag {
    display: inline-flex;
    justify-content: space-between;
    align-items: center;
    background: #fcfcfc;
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.8rem;
    border-radius: 8px;
    font-size: 0.85rem;
    gap: 0.3rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}

.grade-tag.hidden-tag {
    display: none;
}

.grade-tag.expand-tag {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    justify-content: center;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.grade-tag.expand-tag:hover {
    background: transparent;
    border-color: transparent;
    color: var(--text-primary);
}

.grade-tag:hover:not(.expand-tag):not(.hidden-tag) {
    border-color: #bbbbbb;
    background: #f5f5f5;
}

/* User selected grade styling */
.grade-tag.selected {
    background: var(--text-primary);
    color: var(--surface);
    border-color: var(--text-primary);
}

.grade-price {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.item-actions {
    margin-top: 0.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.8rem;
    border-top: 1px solid #f0f0f0;
}

.btn-update {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.2s;
    line-height: 1;
}

.btn-update:hover:not(:disabled) {
    border-color: var(--text-primary);
    color: var(--text-primary);
    background: #f5f5f5;
}

.btn-update:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.update-icon {
    display: inline-block;
}


.btn-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 4px;
}

.btn-remove:hover {
    color: #e11d48;
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    width: 100%;
    max-width: 600px;
    background: var(--surface);
    border-radius: 16px;
    padding: 2.5rem 3rem;
    transform: scale(0.95);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.1);
}

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

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.modal-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 2.5rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 1rem 0;
    background: transparent;
    border: none;
    border-bottom: 2px solid var(--border-color);
    font-size: 1.75rem;
    font-weight: 500;
    transition: border-color 0.2s;
    font-family: var(--font-body);
}

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

.form-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.btn-primary {
    background: var(--accent);
    color: var(--surface);
    border: none;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: opacity 0.2s;
}

.btn-primary:hover {
    opacity: 0.9;
}

.loader-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.error-msg {
    margin-top: 1rem;
    color: #e11d48;
    font-size: 0.85rem;
    text-align: center;
}

/* Responsive constraints */
@media (max-width: 900px) {
    .collection-list {
        grid-template-columns: 1fr;
        padding: 2rem 1.5rem;
    }
    .app-header {
        padding: 1rem 1.25rem;
    }
    .stats-overview {
        gap: 2rem;
    }
    .modal-content {
        padding: 2rem 1.5rem;
    }
}

/* ── Floating Save Bar ─────────────────────────────────────────────────────── */
#save-bar {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    background: #111;
    color: #fff;
    padding: 0.85rem 1.5rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    z-index: 500;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
}

#save-bar.visible {
    transform: translateX(-50%) translateY(0);
}

#save-bar-btn {
    background: #fff;
    color: #111;
    border: none;
    padding: 0.45rem 1.1rem;
    border-radius: 50px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

#save-bar-btn:hover {
    opacity: 0.8;
}

