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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: #1a1a1a;
    background: #f5f5f5;
}

header {
    background: #2d2d2d;
    padding: 0.75rem 1rem;
}

header a {
    color: #e74c3c;
    text-decoration: none;
    font-weight: bold;
    font-size: 1.1rem;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-link {
    color: #aaa !important;
    font-weight: normal !important;
    font-size: 0.9rem !important;
}

.error {
    color: #c0392b;
    background: #fdecea;
    padding: 0.5rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 0.5rem;
}

.auth-link {
    margin-top: 1rem;
    font-size: 0.9rem;
}

.auth-link a {
    color: #e74c3c;
}

main {
    padding: 1rem;
    max-width: 100%;
}

h1 {
    margin-bottom: 0.25rem;
    font-size: 1.4rem;
}

/* Deck list */
.deck-list {
    list-style: none;
    margin-top: 1rem;
}

.deck-list li {
    margin-bottom: 0.5rem;
}

.deck-list a {
    display: block;
    padding: 0.75rem 1rem;
    background: #fff;
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.format-badge {
    display: inline-block;
    background: #e0e0e0;
    color: #555;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    margin-bottom: 1rem;
}

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: #e74c3c;
    color: #fff;
    border: none;
    border-radius: 6px;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.9rem;
    margin: 0.5rem 0;
}

/* Forms */
form {
    max-width: 400px;
}

form label {
    display: block;
    margin: 0.75rem 0 0.25rem;
    font-weight: 600;
}

form input[type="text"],
form input[type="password"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

/* Sideboard Grid */
.grid-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 1rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    background: #fff;
}

.sb-grid {
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.sb-grid th,
.sb-grid td {
    border: 1px solid #ddd;
    padding: 0;
    text-align: center;
    height: 36px;
}

.sb-grid thead th {
    background: #f8f8f8;
    position: sticky;
    top: 0;
    z-index: 20;
    font-weight: 600;
}

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 10;
    background: #fff;
}

.sb-grid thead th.sticky-col {
    z-index: 30;
}

.card-name-col,
.card-name {
    min-width: 160px;
    max-width: 200px;
    text-align: left;
    padding: 0 0.5rem;
    font-weight: 500;
}

.qty-col,
.qty-cell {
    width: 32px;
    min-width: 32px;
    font-weight: 600;
    position: sticky;
    left: 160px;
    z-index: 10;
    background: #fff;
}

.sb-grid thead th.qty-col {
    z-index: 30;
    background: #f8f8f8;
}

.matchup-col {
    min-width: 52px;
    width: 52px;
}

.matchup-col span {
    display: block;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    padding: 0.4rem 0;
    font-size: 12px;
}

/* Category rows */
.category-row {
    background: #f0f0f0;
}

.category-row {
    cursor: pointer;
    user-select: none;
}

.category-label {
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #555;
    padding: 0.25rem 0.5rem !important;
    text-align: left !important;
}

.collapse-icon {
    display: inline-block;
    font-size: 10px;
    width: 1em;
}

.cat-total {
    font-size: 12px;
    font-weight: 600;
    color: transparent;
}

.category-row.collapsed .cat-total {
    color: #555;
}

.category-row.collapsed .cat-total.has-value {
    background: #ffcdd2;
}

/* Summary rows */
.summary-row {
    background: #e8f5e9;
    font-weight: 600;
}

.summary-row .sticky-col,
.summary-row .qty-cell {
    background: #e8f5e9;
}

.category-row .sticky-col,
.category-row .qty-cell {
    background: #f0f0f0;
}

.summary-cell {
    font-weight: 600;
}

/* Cell with +/- buttons */
.cell {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 34px;
    gap: 0;
}

.cell-out {
    background: #ffcdd2;
}

.cell-in {
    background: #c8e6c9;
}

.cell-btn {
    width: 20px;
    height: 34px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 14px;
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    touch-action: manipulation;
}

.cell-btn:hover:not(:disabled) {
    color: #333;
    background: rgba(0, 0, 0, 0.05);
}

.cell-btn:disabled {
    opacity: 0.2;
    cursor: default;
}

.cell-count {
    min-width: 12px;
    text-align: center;
    font-weight: 600;
    font-size: 13px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 0;
    margin-top: 1rem;
    border-bottom: 2px solid #ddd;
}

.tab {
    padding: 0.5rem 1.25rem;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    color: #888;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab.active {
    color: #e74c3c;
    border-bottom-color: #e74c3c;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Matchup tab */
#matchup-select {
    width: 100%;
    max-width: 400px;
    padding: 0.6rem;
    font-size: 1rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    margin-top: 1rem;
    background: #fff;
}

.matchup-hint {
    color: #888;
    margin-top: 1rem;
}

.matchup-summary {
    margin-top: 1rem;
}

.matchup-summary h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}

.swap-section {
    margin-bottom: 1rem;
    padding: 0.75rem;
    border-radius: 6px;
}

.swap-section h4 {
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
}

.swap-out {
    background: #ffcdd2;
}

.swap-in {
    background: #c8e6c9;
}

.swap-section ul {
    list-style: none;
    padding: 0;
}

.swap-section li {
    padding: 0.25rem 0;
    font-size: 0.95rem;
}

.swap-count {
    display: inline-block;
    width: 2rem;
    font-weight: 700;
}
