/* ============================================
   SportTurnier – Styles
   ============================================ */

:root {
    --primary: #2563EB;
    --primary-dark: #1D4ED8;
    --primary-light: #DBEAFE;
    --success: #10B981;
    --success-light: #D1FAE5;
    --warning: #F59E0B;
    --warning-light: #FEF3C7;
    --danger: #EF4444;
    --danger-light: #FEE2E2;
    --bg: #F0F4F8;
    --card: #FFFFFF;
    --text: #1E293B;
    --text-secondary: #64748B;
    --border: #E2E8F0;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    padding: 0 16px 100px;
}

/* ---- Typography ---- */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.35rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    color: white;
    background: var(--primary);
    touch-action: manipulation;
    user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:hover { filter: brightness(1.1); }

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 2px solid var(--border);
}
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }

.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }
.btn-warning { background: var(--warning); color: #000; }

.btn-sm { padding: 8px 16px; font-size: 0.875rem; }
.btn-lg { padding: 16px 32px; font-size: 1.125rem; }
.btn-full { width: 100%; }

.btn-icon {
    width: 44px; height: 44px;
    padding: 0; border-radius: 50%;
    font-size: 1.25rem;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: none;
}
.btn-ghost:hover { color: var(--text); background: var(--bg); }

/* ---- Cards ---- */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 12px;
}
.card-clickable {
    cursor: pointer;
    transition: var(--transition);
}
.card-clickable:hover { box-shadow: var(--shadow-lg); }
.card-clickable:active { transform: scale(0.99); }

/* ---- Form Elements ---- */
.input-group { margin-bottom: 16px; }
.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
input[type="color"],
select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    color: var(--text);
    background: var(--card);
    transition: var(--transition);
    appearance: none;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

input[type="color"] {
    width: 50px;
    height: 50px;
    padding: 4px;
    cursor: pointer;
}

/* ---- Header ---- */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 0;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}
.page-header .back-btn {
    width: 40px; height: 40px;
    display: flex; align-items: center; justify-content: center;
    background: var(--card);
    border: none; border-radius: 50%;
    font-size: 1.25rem;
    cursor: pointer;
    box-shadow: var(--shadow);
}
.page-header h1, .page-header h2 {
    flex: 1;
}

/* ---- Type Cards ---- */
.type-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0;
}
.type-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
    border: 3px solid transparent;
}
.type-card:hover { border-color: var(--primary-light); }
.type-card.selected { border-color: var(--primary); background: var(--primary-light); }
.type-card .icon { font-size: 2rem; margin-bottom: 8px; }
.type-card .title { font-weight: 600; font-size: 0.95rem; }
.type-card .desc { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* ---- Team List ---- */
.team-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--card);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    box-shadow: var(--shadow);
}
.team-color {
    width: 36px; height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 3px solid rgba(0,0,0,0.1);
}
.team-name {
    flex: 1;
    font-weight: 600;
    font-size: 1rem;
}
.team-remove {
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    background: var(--danger-light);
    color: var(--danger);
    border: none; border-radius: 50%;
    font-size: 1.1rem; cursor: pointer;
}

/* ---- Match Card ---- */
.match-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
}
.match-card:hover { box-shadow: var(--shadow-lg); }
.match-card:active { transform: scale(0.99); }
.match-card.completed { opacity: 0.7; }
.match-card.live { border: 2px solid var(--success); }
.match-card .match-header {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.match-teams {
    display: flex;
    align-items: center;
    gap: 8px;
}
.match-team {
    flex: 1;
    text-align: center;
}
.match-team-name {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.match-team-score {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}
.match-vs {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 600;
    flex-shrink: 0;
}
.match-result-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 8px;
}
.match-result-badge.win { background: var(--success-light); color: var(--success); }
.match-result-badge.draw { background: var(--warning-light); color: var(--warning); }
.match-result-badge.loss { background: var(--danger-light); color: var(--danger); }
.match-result-badge.pending { background: var(--bg); color: var(--text-secondary); }

/* ---- Scoring Screen ---- */
.score-screen {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 60px);
    max-width: 600px;
    margin: 0 auto;
}
.score-header {
    text-align: center;
    padding: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}
.score-body {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    position: relative;
}
.score-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px 8px;
    position: relative;
}
.score-side.team-a { background: color-mix(in srgb, var(--team-a-color, #2563EB) 8%, transparent); }
.score-side.team-b { background: color-mix(in srgb, var(--team-b-color, #10B981) 8%, transparent); }

.score-team-name {
    font-size: 1rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 8px;
    padding: 4px 16px;
    border-radius: 20px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-display {
    font-size: 5rem;
    font-weight: 800;
    line-height: 1;
    margin: 8px 0;
    color: var(--text);
    min-width: 100px;
    text-align: center;
}

.score-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.score-btn {
    width: 72px;
    height: 56px;
    border: 2px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    font-size: 1.75rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    touch-action: manipulation;
    user-select: none;
}
.score-btn:active { transform: scale(0.93); }
.score-btn.plus { border-color: var(--success); color: var(--success); }
.score-btn.plus:hover { background: var(--success-light); }
.score-btn.minus { border-color: var(--text-secondary); }
.score-btn.minus:hover { background: var(--danger-light); }
.score-btn.plus5 { font-size: 1.1rem; }

.score-divider {
    position: absolute;
    left: 50%;
    top: 10%;
    bottom: 10%;
    width: 2px;
    background: var(--border);
    transform: translateX(-50%);
}
.score-vs {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg);
    padding: 8px;
    border-radius: 50%;
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.875rem;
    z-index: 1;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.score-footer {
    padding: 12px 16px;
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---- Standings Table ---- */
.standings-table {
    width: 100%;
    border-collapse: collapse;
}
.standings-table th {
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    padding: 8px 4px;
    text-align: center;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.standings-table th.left { text-align: left; }
.standings-table td {
    padding: 10px 4px;
    text-align: center;
    font-size: 0.9rem;
    border-bottom: 1px solid var(--border);
}
.standings-table td.left { text-align: left; font-weight: 600; }
.standings-table tr:first-child td { background: var(--primary-light); }
.standings-table .rank {
    font-weight: 700;
    color: var(--primary);
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 0;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin: 12px 0;
    overflow: hidden;
}
.tab {
    flex: 1;
    padding: 12px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    background: transparent;
    color: var(--text-secondary);
}
.tab.active {
    background: var(--primary);
    color: white;
}
.tab:hover:not(.active) {
    background: var(--primary-light);
}

/* ---- Home Screen ---- */
.home-hero {
    text-align: center;
    padding: 32px 16px 24px;
}
.home-hero h1 {
    font-size: 2rem;
    margin-bottom: 4px;
}
.home-hero .subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}
.hero-icon {
    font-size: 3.5rem;
    margin-bottom: 8px;
}

.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 16px 0;
}
.quick-action {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
    border: none;
    color: var(--text);
}
.quick-action:hover { box-shadow: var(--shadow-lg); }
.quick-action:active { transform: scale(0.97); }
.quick-action .qa-icon { font-size: 2rem; margin-bottom: 8px; }
.quick-action .qa-title { font-weight: 600; }
.quick-action .qa-desc { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }

/* ---- Tournament List ---- */
.section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin: 20px 0 8px;
    padding-left: 4px;
}

.tournament-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--card);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: var(--transition);
}
.tournament-item:hover { box-shadow: var(--shadow-lg); }
.tournament-item:active { transform: scale(0.99); }
.tournament-item .ti-icon {
    font-size: 1.5rem;
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-light);
    border-radius: 10px;
}
.tournament-item .ti-info { flex: 1; }
.tournament-item .ti-name { font-weight: 600; font-size: 0.95rem; }
.tournament-item .ti-meta { font-size: 0.8rem; color: var(--text-secondary); margin-top: 2px; }
.tournament-item .ti-arrow { color: var(--text-secondary); font-size: 1.25rem; }

/* ---- Bracket ---- */
.bracket-round {
    margin-bottom: 24px;
}
.bracket-round-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 8px;
    padding-left: 4px;
}

.bracket-match {
    display: flex;
    flex-direction: column;
    background: var(--card);
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    cursor: pointer;
}
.bracket-team {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 8px;
    font-size: 0.9rem;
}
.bracket-team + .bracket-team {
    border-top: 1px solid var(--border);
}
.bracket-team.winner { background: var(--success-light); font-weight: 600; }
.bracket-team.loser { opacity: 0.5; }
.bracket-team .bt-color {
    width: 12px; height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}
.bracket-team .bt-name { flex: 1; }
.bracket-team .bt-score { font-weight: 700; }

/* ---- Station Mode ---- */
.station-grid {
    display: grid;
    gap: 12px;
    margin: 12px 0;
}
.station-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
}
.station-card h3 {
    font-size: 0.95rem;
    margin-bottom: 8px;
}
.station-teams {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.station-team {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg);
    border-radius: 20px;
    font-size: 0.85rem;
}
.station-team input {
    width: 40px;
    text-align: center;
    padding: 4px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
}

/* ---- Direct Score Input ---- */
.direct-score {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: center;
    margin: 8px 0;
}
.direct-score input {
    width: 80px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    padding: 8px;
}
.direct-score span {
    font-size: 1.2rem;
    color: var(--text-secondary);
    font-weight: 600;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state .title { font-weight: 600; font-size: 1.1rem; color: var(--text); margin-bottom: 4px; }
.empty-state .desc { font-size: 0.9rem; }

/* ---- Settings ---- */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-label {
    font-weight: 500;
    font-size: 0.95rem;
}
.setting-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.toggle {
    width: 50px; height: 28px;
    background: var(--border);
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
}
.toggle.active { background: var(--success); }
.toggle::after {
    content: '';
    position: absolute;
    width: 22px; height: 22px;
    background: white;
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle.active::after { left: 25px; }

/* ---- Timer ---- */
.timer-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
}
.timer-display {
    font-size: 2rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--primary);
}
.timer-btn {
    width: 40px; height: 40px;
    border-radius: 50%;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-content {
    background: var(--card);
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 24px;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal-content h2 { margin-bottom: 16px; }

/* ---- Toast ---- */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-weight: 500;
    z-index: 200;
    animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(-50%) translateY(20px); } }

/* ---- Confirm Dialog ---- */
.confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 150;
    padding: 24px;
}
.confirm-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 340px;
    width: 100%;
    text-align: center;
}
.confirm-box h3 { margin-bottom: 8px; }
.confirm-box p { color: var(--text-secondary); margin-bottom: 20px; font-size: 0.95rem; }
.confirm-actions { display: flex; gap: 12px; justify-content: center; }

/* ---- Animations ---- */
.fade-in { animation: fadeIn 0.2s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---- Responsive ---- */
@media (max-width: 400px) {
    .score-display { font-size: 4rem; }
    .score-btn { width: 64px; height: 48px; font-size: 1.5rem; }
    .type-grid { grid-template-columns: 1fr; }
}

@media (min-width: 601px) {
    .score-display { font-size: 6rem; }
    .score-btn { width: 80px; height: 64px; }
}

/* ---- Color Dot ---- */
.color-dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

/* ---- Progress ---- */
.progress-bar {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}
.progress-bar-fill {
    height: 100%;
    background: var(--success);
    border-radius: 3px;
    transition: width 0.3s ease;
}