:root {
    --primary: #0f766e;          /* teal-700, 5.7:1 on white */
    --primary-strong: #0e6963;
    --primary-on-text: #ffffff;   /* text color when sitting on --primary background */
    --primary-bg-tint: rgba(15, 118, 110, 0.08);
    --holiday-bg: #b45309;        /* amber-700, 5.0:1 on white */
    --holiday-text: #ffffff;
    --bg: #f8fafc;
    --card-bg: #ffffff;
    --text: #0f172a;              /* slate-900 */
    --text-muted: #475569;        /* slate-600, 7.0:1 on white */
    --chip-bg: #e2e8f0;
    --chip-text: #334155;         /* slate-700, 9.5:1 on chip-bg */
    --border: #e2e8f0;
    --toggle-bg: #e2e8f0;
    --radius: 16px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.08);
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary: #5eead4;       /* teal-300, 9.5:1 on card */
        --primary-strong: #2dd4bf;
        --primary-on-text: #0f172a; /* dark text on light teal — 12:1 contrast */
        --primary-bg-tint: rgba(94, 234, 212, 0.12);
        --holiday-bg: #fbbf24;    /* amber-400 */
        --holiday-text: #1e293b;  /* dark text on amber, 8.7:1 */
        --bg: #0f172a;
        --card-bg: #1e293b;
        --text: #f1f5f9;
        --text-muted: #cbd5e1;    /* slate-300, 11.6:1 on bg */
        --chip-bg: #334155;
        --chip-text: #e2e8f0;     /* slate-200, 9.4:1 on chip-bg */
        --border: #334155;
        --toggle-bg: #1e293b;
        --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.4);
    }
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang TC', 'Noto Sans TC', 'Microsoft JhengHei', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

#loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    background-color: var(--primary);
    width: 0%;
    z-index: 1000;
    transition: width 0.3s ease;
}

#loading-bar.active {
    animation: loading 1.5s infinite ease-in-out;
}

@keyframes loading {
    0% { width: 0%; left: 0; }
    50% { width: 70%; left: 15%; }
    100% { width: 0%; left: 100%; }
}

#app {
    max-width: 640px;
    margin: 0 auto;
    padding: 20px 16px 80px;
}

.initial-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 80px 0;
    font-size: 1rem;
}

header {
    margin-bottom: 24px;
    text-align: center;
}

h1 {
    font-size: 1.4rem;
    margin: 0 0 6px;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.name-section {
    background: var(--card-bg);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.input-group {
    display: flex;
    gap: 8px;
}

input[type="text"] {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: 12px;
    font-size: 1rem;
    background: transparent;
    color: var(--text);
    min-height: 44px;
}

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

input:focus {
    outline: none;
    border-color: var(--primary);
}

button.primary {
    background: var(--primary);
    color: var(--primary-on-text);
    border: none;
    padding: 12px 20px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    min-height: 44px;
    cursor: pointer;
}

button.primary:hover {
    background: var(--primary-strong);
}

.name-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.95rem;
    gap: 8px;
    flex-wrap: wrap;
}

.name-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

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

.push-btn:hover {
    background: var(--primary-bg-tint);
    border-color: var(--primary);
    color: var(--primary);
}

.push-btn-on {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-bg-tint);
}

.push-btn-denied {
    border-color: var(--text-muted);
    color: var(--text-muted);
    opacity: 0.6;
}

.name-display-secondary {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.link-btn-subtle {
    border: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.8rem;
    padding: 4px 8px;
    min-height: auto;
}

.link-btn-subtle:hover {
    color: var(--primary);
    background: transparent;
}

.rename-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.rename-label {
    font-size: 0.95rem;
    color: var(--text);
}

.rename-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.rename-cancel {
    align-self: flex-end;
    border: none;
    color: var(--text-muted);
    background: transparent;
    font-size: 0.85rem;
}

.name-display strong {
    color: var(--primary);
}

.link-btn {
    color: var(--primary);
    background: none;
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    min-height: 44px;
    cursor: pointer;
    flex-shrink: 0;
}

.link-btn:hover {
    background: var(--primary-bg-tint);
}

.month-picker-wrap {
    margin: 16px 0 0;
    overflow: hidden;
    border-radius: 12px;
    background: var(--toggle-bg);
    padding: 4px;
}

.month-picker {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.month-picker::-webkit-scrollbar {
    display: none;
}

.month-picker button {
    flex: 0 0 auto;
    min-width: 64px;
    border: none;
    background: transparent;
    padding: 10px 14px;
    min-height: 44px;
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-weight: 600;
    scroll-snap-align: center;
    white-space: nowrap;
}

.month-picker button.active {
    background: var(--card-bg);
    color: var(--primary);
    font-weight: 700;
    box-shadow: var(--shadow);
}

.section-header {
    font-weight: 700;
    color: var(--text-muted);
    margin: 8px 4px 12px;
    font-size: 0.95rem;
}

.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg);
    padding: 8px 4px;
    margin: 8px -4px 12px;
    backdrop-filter: blur(6px);
}

.resort-btn {
    background: var(--primary-bg-tint);
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    min-height: 36px;
    line-height: 1;
}

.resort-btn:hover {
    background: var(--primary);
    color: var(--primary-on-text);
}

.sort-toggle {
    display: inline-flex;
    background: var(--toggle-bg);
    padding: 3px;
    border-radius: 10px;
    gap: 2px;
}

.sort-toggle button {
    border: none;
    background: transparent;
    padding: 6px 14px;
    min-height: 36px;
    border-radius: 7px;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.sort-toggle button.active {
    background: var(--card-bg);
    color: var(--primary);
    font-weight: 700;
    box-shadow: var(--shadow);
}

.slot-list {
    display: grid;
    gap: 12px;
    transition: opacity 0.2s, filter 0.2s;
}

.slot-list.slot-list-locked {
    opacity: 0.55;
    filter: saturate(0.5);
    position: relative;
}

.slot-list.slot-list-locked::before {
    content: '請先輸入名字後再投票';
    position: absolute;
    top: -28px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    background: var(--bg);
    padding: 0 12px;
}

.slot-list.slot-list-locked .slot-card {
    cursor: not-allowed;
}

.slot-card {
    display: flex;
    flex-direction: column;
    padding: 16px;
    background: var(--card-bg);
    border: 2px solid transparent;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    width: 100%;
    color: var(--text);
    font: inherit;
}

.slot-card:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.slot-card:hover {
    border-color: var(--border);
}

.slot-card.voted {
    border-color: var(--primary);
    background: var(--primary-bg-tint);
}

.slot-main {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 8px;
}

.slot-info {
    flex: 1;
    min-width: 0;
}

.slot-label {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.4;
}

.vote-count {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    flex-shrink: 0;
    min-width: 32px;
    text-align: right;
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    border-radius: 6px;
    margin-top: 6px;
}

.badge-holiday {
    background: var(--holiday-bg);
    color: var(--holiday-text);
}

.voters-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.voters-list-center {
    justify-content: center;
}

.voter-chip {
    padding: 4px 10px;
    background: var(--chip-bg);
    color: var(--chip-text);
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 500;
}

.voter-chip-self {
    background: var(--primary);
    color: var(--primary-on-text);
    font-weight: 700;
}

footer {
    margin-top: 32px;
    text-align: center;
    border-top: 1px solid var(--border);
    padding-top: 20px;
}

.total-voters {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 12px;
}

#toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    left: 50%;
    transform: translateX(-50%);
    background: #0f172a;
    color: #ffffff;
    padding: 12px 24px;
    border-radius: 24px;
    z-index: 2000;
    font-size: 0.9rem;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.4);
    animation: slideUp 0.25s ease;
    max-width: calc(100vw - 32px);
}

@keyframes slideUp {
    from { transform: translate(-50%, 20px); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

.hidden { display: none; }

/* Compact tweaks for very narrow screens (≤360px) */
@media (max-width: 360px) {
    #app { padding: 16px 12px 60px; }
    h1 { font-size: 1.25rem; }
    .slot-card { padding: 14px; }
    .slot-label { font-size: 1rem; }
    .vote-count { font-size: 1.5rem; }
}
