:root {
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text: #1f2937;
    --border: #d1d5db;
    --red-suit: #ef4444;
    --black-suit: #111827;
    --success: #10b981;
    --gold: #f59e0b;
    --danger: #ef4444;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; }

body.app-body {
    background: var(--bg);
    color: var(--text);
    margin: 0;
    padding: calc(8px + var(--safe-top)) 8px calc(20px + var(--safe-bottom));
    max-width: 900px;
    margin-inline: auto;
    min-height: 100dvh;
    overflow-x: hidden;
}

h1, h2 { text-align: center; color: var(--primary); margin: 0 0 6px; }
h1 { font-size: 1.5rem; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; }
p.subtitle { text-align: center; color: #6b7280; font-size: 0.875rem; margin: 0 0 16px; line-height: 1.4; }

.section {
    background: var(--card-bg);
    padding: 12px;
    border-radius: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.04);
    margin-bottom: 12px;
    border: 1px solid var(--border);
}

.top-nav {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.top-nav a {
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
    text-decoration: none;
    color: #6b7280;
    background: white;
    border: 1px solid var(--border);
    -webkit-tap-highlight-color: transparent;
}
.top-nav a.active { background: var(--primary); color: white; border-color: var(--primary); }

.variant-segment {
    display: flex;
    background: #e5e7eb;
    border-radius: 10px;
    padding: 3px;
    margin-bottom: 12px;
}
.variant-segment label { flex: 1; position: relative; cursor: pointer; }
.variant-segment input { position: absolute; opacity: 0; width: 0; height: 0; }
.variant-segment span {
    display: block;
    text-align: center;
    padding: 10px 6px;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #6b7280;
    border-radius: 8px;
}
.variant-segment input:checked + span { background: white; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }

.btn {
    padding: 12px 16px;
    border: none;
    border-radius: 12px;
    font-size: 0.9375rem;
    font-weight: 700;
    cursor: pointer;
    color: white;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); }
.btn-secondary { background: #6b7280; }
.btn-block { width: 100%; }

.mini-card {
    flex: 0 0 44px;
    width: 44px;
    height: 58px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 700;
    background: white;
    cursor: grab;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.1s, box-shadow 0.1s;
}
.mini-card.card-red { color: var(--red-suit); }
.mini-card.card-black { color: var(--black-suit); }
.mini-card .suit-sm { font-size: 0.625rem; line-height: 1; }
.mini-card.is-selected { outline: 2px solid var(--primary); outline-offset: 2px; transform: scale(1.05); }
.mini-card.is-dragging { opacity: 0.5; }
.mini-card:active { cursor: grabbing; }

/* Manual row editor */
.row-editor { display: flex; flex-direction: column; gap: 10px; }

.editor-status {
    padding: 10px 12px;
    border-radius: 10px;
    background: #f9fafb;
    border: 1px solid var(--border);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.45;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.editor-status.is-valid { background: #ecfdf5; border-color: #6ee7b7; color: #047857; }
.editor-status.is-foul { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.editor-hands, .editor-royalty { font-size: 0.75rem; opacity: 0.9; }

.editor-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.editor-row-label {
    font-size: 0.6875rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6b7280;
}
.editor-row-count { font-size: 0.75rem; font-weight: 700; color: #9ca3af; }
.editor-row-hint { font-size: 0.6875rem; color: #9ca3af; }

.editor-dropzone {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 66px;
    padding: 8px;
    border-radius: 12px;
    border: 2px dashed #e5e7eb;
    background: #fafafa;
    align-items: center;
}
.editor-dropzone.drop-target { border-color: var(--primary); background: #eff6ff; }
.editor-row.row-back .editor-dropzone { border-color: #c7d2fe; background: #f8fafc; }

.editor-slot {
    width: 44px;
    height: 58px;
    border-radius: 8px;
    border: 1.5px dashed #d1d5db;
    background: rgba(255,255,255,0.6);
}

.editor-pool-wrap { margin-top: 4px; }
.editor-pool { min-height: 72px; }

/* Compare page */
.player-count-segment { display: flex; gap: 6px; margin-bottom: 12px; }
.player-count-segment button {
    flex: 1;
    padding: 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: white;
    font-weight: 700;
    font-size: 0.875rem;
    color: #6b7280;
    cursor: pointer;
}
.player-count-segment button.active { background: var(--primary); color: white; border-color: var(--primary); }

.player-panel {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fafafa;
}
.player-panel h3 { margin: 0 0 8px; font-size: 0.9375rem; color: var(--text); text-align: left; }
.card-input.input-error { border-color: var(--danger); background: #fef2f2; }
    width: 100%;
    min-height: 52px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.75rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    resize: vertical;
}
.player-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.player-actions .btn { flex: 1; min-width: 100px; font-size: 0.8125rem; padding: 10px 12px; }

.score-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.score-table th, .score-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: center; }
.score-table th { font-size: 0.6875rem; text-transform: uppercase; color: #6b7280; }
.score-total { font-weight: 800; font-size: 1rem; color: var(--success); }
.match-detail { font-size: 0.75rem; color: #6b7280; margin-top: 8px; line-height: 1.4; }
.foul-tag { color: var(--danger); font-weight: 800; font-size: 0.75rem; }

/* OFC */
.ofc-board { display: flex; flex-direction: column; gap: 10px; }
.ofc-row-label { font-size: 0.6875rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: #6b7280; margin-bottom: 6px; }
.ofc-slots { display: flex; flex-wrap: wrap; gap: 6px; }
.ofc-slot {
    width: 44px;
    height: 58px;
    border-radius: 8px;
    border: 2px dashed #d1d5db;
    background: #f9fafb;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.625rem;
    color: #9ca3af;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.ofc-slot.can-place { border-color: var(--primary); background: #eff6ff; animation: pulse-slot 1.2s ease infinite; }
.ofc-slot.filled { border-style: solid; border-color: var(--border); background: white; cursor: default; animation: none; }
.ofc-slot.foul-risk { border-color: #fca5a5; }

@keyframes pulse-slot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.25); }
    50% { box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15); }
}

.ofc-deal {
    text-align: center;
    padding: 16px;
    border-radius: 14px;
    background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
    border: 2px solid #93c5fd;
    margin-bottom: 12px;
}
.ofc-deal-label { font-size: 0.75rem; font-weight: 700; color: #1d4ed8; text-transform: uppercase; letter-spacing: 0.05em; }
.ofc-deal-card { display: flex; justify-content: center; margin-top: 10px; }
.ofc-deal-card .mini-card { width: 56px; height: 74px; font-size: 1rem; cursor: default; }
.ofc-progress { text-align: center; font-size: 0.8125rem; color: #6b7280; margin-bottom: 10px; }

.status-banner {
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-bottom: 12px;
}
.status-banner.ok { background: #ecfdf5; border: 1px solid #6ee7b7; color: #047857; }
.status-banner.warn { background: #fffbeb; border: 1px solid #fcd34d; color: #b45309; }
.status-banner.bad { background: #fef2f2; border: 1px solid #fca5a5; color: #b91c1c; }

.action-bar { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.action-bar .btn { flex: 1; }

@media (min-width: 600px) {
    body.app-body { padding: 20px 20px 32px; }
    .section { padding: 16px; }
    .mini-card { flex: 0 0 40px; width: 40px; height: 52px; font-size: 0.75rem; }
    .editor-slot, .ofc-slot { width: 40px; height: 52px; }
}
