:root {
    --bg: #111827;
    --surface: #1f2937;
    --surface2: #374151;
    --border: #374151;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --accent: #6366f1;
    --danger: #ef4444;
    --success: #10b981;
}

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

html, body {
    height: 100%;
    background-color: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

a {
    color: var(--accent);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

.header {
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.header-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1rem;
    letter-spacing: 0.01em;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}

.table th[data-col] {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.table th[data-col]:hover {
    color: var(--text);
}

.table th.sort-active {
    color: var(--text);
}

.sort-icon {
    display: inline-block;
    width: 1em;
    color: var(--accent);
    font-size: 0.85em;
    opacity: 0.3;
    margin-left: 0.1em;
}

.table th.sort-active .sort-icon {
    opacity: 1;
}

.table td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

.table tbody tr:not(.final-sep):hover {
    background-color: var(--surface2);
}

.form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.input {
    background-color: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 0.95rem;
    padding: 0.55rem 0.85rem;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

.input:focus {
    border-color: var(--accent);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background-color 0.15s, opacity 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    opacity: 0.88;
    text-decoration: none;
}

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

.btn-ghost {
    background-color: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.btn-icon {
    background-color: transparent;
    color: var(--danger);
    border: 1px solid transparent;
    padding: 0.3rem 0.55rem;
    font-size: 0.8rem;
}

.btn-icon:hover {
    border-color: var(--danger);
    opacity: 1;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    background-color: var(--surface2);
    color: var(--text-muted);
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.badge-accent {
    background-color: color-mix(in srgb, var(--accent) 18%, transparent);
    color: var(--accent);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
}

@media (max-width: 680px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

.dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.user-name {
    display: flex;
    align-items: center;
}

.weight-list {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 420px;
    overflow-y: auto;
}

.weight-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.5rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

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

.weight-item:hover {
    background-color: var(--surface2);
    border-radius: 0.35rem;
}

.weight-item-date {
    color: var(--text-muted);
    font-size: 0.8rem;
    min-width: 6rem;
    flex-shrink: 0;
}

.weight-item-note {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
}

.weight-item-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    margin-left: auto;
    flex-shrink: 0;
}

.weight-item-action {
    margin-left: 0.75rem;
    flex-shrink: 0;
}

.chart-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.chart-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.7rem;
    border-radius: 9999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.chart-filter-btn.active {
    border-color: var(--surface2);
    background: var(--surface2);
    color: var(--text);
}

.chart-filter-btn:hover {
    color: var(--text);
}

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.text-muted {
    color: var(--text-muted);
}

.progress-bar-wrap {
    background-color: var(--surface2);
    border-radius: 9999px;
    height: 8px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-bar {
    height: 100%;
    border-radius: 9999px;
    background-color: var(--accent);
    transition: width 0.4s ease;
}

.progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.alert-error {
    background-color: color-mix(in srgb, var(--danger) 15%, transparent);
    border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
    color: #fca5a5;
    border-radius: 0.5rem;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.alert-warning {
    background-color: color-mix(in srgb, var(--warning) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
    color: #fcd34d;
    border-radius: 0.5rem;
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.alert-warning a {
    color: #fcd34d;
    font-weight: 600;
    margin-left: auto;
    white-space: nowrap;
}

.progress-sep {
    opacity: 0.4;
    margin: 0 0.2rem;
}

.badge-inactive {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 9999px;
    background-color: color-mix(in srgb, var(--warning) 20%, transparent);
    color: #fcd34d;
    margin-left: 0.4rem;
    vertical-align: middle;
}

.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 2rem;
}

.auth-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 1.5rem;
}

.auth-footer {
    margin-top: 1.25rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.chart-wrap {
    position: relative;
    height: 320px;
    cursor: pointer;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem 0;
    font-size: 0.9rem;
}

.rank-num {
    color: var(--text-muted);
    font-size: 0.85rem;
    min-width: 1.5rem;
}

.goal-target {
    display: block;
    font-weight: 500;
    white-space: nowrap;
}

.goal-remaining {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.goal-achieved {
    display: block;
    font-size: 0.78rem;
    color: var(--success);
    white-space: nowrap;
}

.settings-card {
    max-width: 480px;
}

.form-inline {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
}

.form-inline .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 160px;
}

.color-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.35rem;
}

.input-color {
    width: 3rem;
    height: 2.4rem;
    padding: 0.15rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface2);
    cursor: pointer;
    flex-shrink: 0;
}

.input-color::-webkit-color-swatch-wrapper { padding: 0; }
.input-color::-webkit-color-swatch { border: none; border-radius: 4px; }

.badge-streak {
    display: inline-block;
    font-size: 0.72rem;
    padding: 0.1rem 0.45rem;
    border-radius: 9999px;
    background-color: color-mix(in srgb, #f97316 18%, transparent);
    color: #fb923c;
    margin-left: 0.4rem;
    vertical-align: middle;
    white-space: nowrap;
}

.alert-newlow {
    background-color: color-mix(in srgb, var(--success) 15%, transparent);
    border: 1px solid color-mix(in srgb, var(--success) 40%, transparent);
    color: #6ee7b7;
    border-radius: 0.5rem;
    padding: 0.65rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 1rem;
    text-align: center;
}

.chart-toggle {
    display: flex;
    gap: 0.25rem;
    margin-bottom: 0.75rem;
}

.chart-toggle-btn {
    padding: 0.3rem 0.9rem;
    border-radius: 0.4rem;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.15s;
}

.chart-toggle-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.challenge-finished {
    font-weight: 400;
    color: var(--success);
    font-size: 0.9rem;
}

.readonly-section {
    opacity: 0.4;
    pointer-events: none;
}

button[disabled].btn-icon {
    opacity: 0.3;
    cursor: not-allowed;
}

.final-icon {
    font-size: 1.1rem;
    width: 1.8rem;
}

.final-sep td {
    padding: 0;
    border: none;
    border-top: 3px dashed var(--surface2);
}

.final-sep:hover td {
    background-color: transparent;
}

.final-others td {
    color: var(--text-muted);
}

.final-others .user-name {
    color: var(--text-muted);
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.summary-stat {
    background: var(--surface2);
    border-radius: 0.6rem;
    padding: 1rem 0.75rem 0.75rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
}

.summary-stat-value {
    font-size: 1.45rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    line-height: 1.2;
}

.summary-stat-winner {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 0.15rem;
}

.summary-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
    .mob-hide { display: none; }

    .card {
        padding: 1rem 0.85rem;
    }

    .container {
        padding: 1rem 0.75rem;
    }

    .header {
        padding: 0.65rem 0.85rem;
    }
}
