/* ===== فونت فارسی ===== */
@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css');

/* ===== ریست و پایه ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg: #f2f2f7;
    --bg-card: #ffffff;
    --bg-grouped: #f2f2f7;
    --text: #000000;
    --text-secondary: #8e8e93;
    --text-tertiary: #c7c7cc;
    --accent: #007aff;
    --accent-green: #34c759;
    --accent-red: #ff3b30;
    --accent-orange: #ff9500;
    --separator: rgba(60, 60, 67, 0.12);
    --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
    --radius: 14px;
    --radius-sm: 10px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 56px;
    --header-height: 56px;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Vazirmatn', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
    overflow-x: hidden;
    direction: rtl;
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 12px);
    -webkit-font-smoothing: antialiased;
}

/* ===== تایپوگرافی ===== */
h1, h2, h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* ===== هدر ===== */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(242, 242, 247, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 0.5px solid var(--separator);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.app-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.header-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1rem;
    font-weight: 500;
    font-family: inherit;
    padding: 8px 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-btn:active {
    opacity: 0.6;
}

/* ===== ناوبری پایین (iOS style) ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--nav-height) + var(--safe-bottom));
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 0.5px solid var(--separator);
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 8px;
    padding-bottom: var(--safe-bottom);
    z-index: 100;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.65rem;
    font-weight: 500;
    cursor: pointer;
    padding: 4px 16px;
    min-width: 64px;
    transition: color 0.15s;
}

.nav-item.active {
    color: var(--accent);
}

.nav-item svg {
    width: 26px;
    height: 26px;
}

/* ===== صفحات ===== */
.page {
    display: none;
    padding: 12px 16px 24px;
    animation: fadeIn 0.25s ease;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== کارت‌ها ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 12px;
}

.card-section {
    padding: 14px 16px;
    border-bottom: 0.5px solid var(--separator);
}

.card-section:last-child {
    border-bottom: none;
}

.section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
    padding: 0 4px;
}

/* ===== دکمه‌ها ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    padding: 14px 20px;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    width: 100%;
}

.btn:active {
    opacity: 0.7;
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-success {
    background: var(--accent-green);
    color: #fff;
}

.btn-danger {
    background: var(--accent-red);
    color: #fff;
}

.btn-secondary {
    background: var(--bg);
    color: var(--accent);
}

.btn-sm {
    padding: 8px 14px;
    font-size: 0.875rem;
    width: auto;
}

/* ===== فرم‌ها ===== */
.form-group {
    margin-bottom: 16px;
}

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

.form-input, .form-select {
    width: 100%;
    font-family: inherit;
    font-size: 1.05rem;
    padding: 12px 14px;
    border: 1px solid var(--separator);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
    appearance: none;
    -webkit-appearance: none;
}

.form-input:focus, .form-select:focus {
    border-color: var(--accent);
    background: #fff;
}

.form-input::placeholder {
    color: var(--text-tertiary);
}

/* ===== لیست بازیکنان / مسابقات ===== */
.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 0.5px solid var(--separator);
    cursor: pointer;
    transition: background 0.15s;
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:active {
    background: rgba(0,0,0,0.04);
}

.list-item-title {
    font-weight: 600;
    font-size: 1rem;
}

.list-item-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-active {
    background: rgba(52, 199, 89, 0.15);
    color: var(--accent-green);
}

.badge-finished {
    background: rgba(142, 142, 147, 0.15);
    color: var(--text-secondary);
}

/* ===== صفحه بازی (Match View) ===== */
.score-board {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 8px;
    align-items: center;
    text-align: center;
    padding: 20px 12px;
}

.player-score-box {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 16px 8px;
}

.player-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-score {
    font-size: 2.6rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.player-score.winning {
    color: var(--accent-green);
}

.vs-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-tertiary);
}

.hand-info {
    text-align: center;
    padding: 8px 16px 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.wins-bar {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}

.win-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-tertiary);
}

.win-dot.filled {
    background: var(--accent);
}

/* ===== ورودی امتیاز سریع ===== */
.score-input-area {
    padding: 16px;
}

.score-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.score-input-box {
    text-align: center;
}

.score-input-box label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.score-input-box input {
    width: 100%;
    font-size: 1.8rem;
    font-weight: 700;
    text-align: center;
    padding: 14px 8px;
    border: 2px solid var(--separator);
    border-radius: var(--radius);
    background: var(--bg);
    font-family: inherit;
    font-variant-numeric: tabular-nums;
    outline: none;
    -moz-appearance: textfield;
}

.score-input-box input::-webkit-outer-spin-button,
.score-input-box input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.score-input-box input:focus {
    border-color: var(--accent);
    background: #fff;
}

/* ===== پیام برنده ===== */
.winner-banner {
    display: none;
    text-align: center;
    padding: 20px 16px;
    background: linear-gradient(135deg, #34c759, #30d158);
    color: #fff;
    border-radius: var(--radius);
    margin: 12px 0;
    animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.winner-banner.show {
    display: block;
}

.winner-banner h2 {
    font-size: 1.4rem;
    margin-bottom: 4px;
}

.winner-banner p {
    opacity: 0.9;
    font-size: 0.95rem;
}

@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ===== تاریخچه جدول ===== */
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.history-table th {
    text-align: center;
    padding: 14px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg);
    border-bottom: 0.5px solid var(--separator);
}

.history-table td {
    text-align: center;
    padding: 16px 12px;
    border-bottom: 0.5px solid var(--separator);
    vertical-align: middle;
}

.history-table tr:last-child td {
    border-bottom: none;
}

.history-table tr:active {
    background: rgba(0,0,0,0.03);
}

/* ===== مودال ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: none;
    align-items: flex-end;
    justify-content: center;
    animation: fadeOverlay 0.2s ease;
}

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

@keyframes fadeOverlay {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    background: #fff;
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 20px 16px calc(20px + var(--safe-bottom));
    animation: slideUp 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-handle {
    width: 36px;
    height: 5px;
    background: var(--text-tertiary);
    border-radius: 3px;
    margin: 0 auto 16px;
}

.modal h2 {
    font-size: 1.2rem;
    margin-bottom: 16px;
    text-align: center;
}

/* ===== خالی ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 12px;
    opacity: 0.4;
}

.empty-state p {
    font-size: 0.95rem;
}

/* ===== لودینگ ===== */
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--separator);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    margin: 24px auto;
}

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

/* ===== toast ===== */
.toast {
    position: fixed;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 20px);
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 300;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    pointer-events: none;
    white-space: nowrap;
    max-width: 90vw;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ===== جزئیات دست‌ها ===== */
.hand-list {
    margin-top: 8px;
}

.hand-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 0.5px solid var(--separator);
    font-size: 0.9rem;
}

.hand-item:last-child {
    border-bottom: none;
}

.hand-score {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* ===== ریسپانسیو ===== */
@media (min-width: 500px) {
    body {
        max-width: 480px;
        margin: 0 auto;
        box-shadow: 0 0 40px rgba(0,0,0,0.08);
    }
    .bottom-nav, .app-header {
        max-width: 480px;
        left: 50%;
        transform: translateX(-50%);
        width: 100%;
    }
}
