:root {
    --bg: #f5f5f5;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f9f9f9;
    --text: #333333;
    --text-muted: #666666;
    --text-subtle: #999999;
    --border: #dddddd;
    --border-light: #eeeeee;
    --primary: #007bff;
    --primary-hover: #0056b3;
    --success: #28a745;
    --success-hover: #218838;
    --success-bg: #d4edda;
    --success-border: #28a745;
    --success-text: #155724;
    --danger: #dc3545;
    --danger-hover: #c82333;
    --ranked-bg: #f0f8ff;
    --ranked-border: #007bff;
    --unranked-bg: #f5f5f5;
    --unranked-border: #cccccc;
    --ghost-bg: #e3f2fd;
    --shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg: #1a1a1a;
    --bg-surface: #2d2d2d;
    --bg-surface-alt: #252525;
    --text: #e0e0e0;
    --text-muted: #a0a0a0;
    --text-subtle: #707070;
    --border: #404040;
    --border-light: #353535;
    --primary: #4a9eff;
    --primary-hover: #6db1ff;
    --success: #3cb371;
    --success-hover: #4ec980;
    --success-bg: #1a3a2a;
    --success-border: #3cb371;
    --success-text: #90ee90;
    --danger: #ff6b6b;
    --danger-hover: #ff8787;
    --ranked-bg: #1a2a3a;
    --ranked-border: #4a9eff;
    --unranked-bg: #252525;
    --unranked-border: #505050;
    --ghost-bg: #2a3f4f;
    --shadow: rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--primary);
    text-decoration: none;
}

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

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    font-size: 2em;
    margin-bottom: 10px;
}

h2 {
    font-size: 1.5em;
    margin: 20px 0 10px;
}

/* Home page */
.home {
    text-align: center;
    padding-top: 100px;
}

.home p {
    margin-bottom: 30px;
    color: var(--text-muted);
}

.create-ballot-form {
    max-width: 400px;
    margin: 0 auto;
    background: var(--bg-surface);
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 2px 8px var(--shadow);
}

.create-ballot-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.create-ballot-form input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 16px;
    margin-bottom: 15px;
    background: var(--bg-surface);
    color: var(--text);
}

.create-ballot-form button {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 500;
}

.create-ballot-form button:hover {
    background: var(--primary-hover);
}

/* Ballot page */
.ballot {
    background: var(--bg-surface);
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 2px 8px var(--shadow);
}

.ballot-header {
    margin-bottom: 20px;
}

.ballot-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-light);
}

.ballot-url-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    background: var(--bg-surface-alt);
    color: var(--text);
    cursor: pointer;
}

.ballot-url-input:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.copy-btn {
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: var(--bg-surface-alt);
    border-color: var(--primary);
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 500;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* Add item form */
.add-item-form {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.add-item-form input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 16px;
    background: var(--bg-surface);
    color: var(--text);
}

.add-item-form button {
    padding: 10px 20px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
}

.add-item-form button:hover {
    background: var(--success-hover);
}

.item-name {
    flex: 1;
    font-weight: 500;
}

.delete-form {
    display: inline;
    margin: 0;
}

.delete-btn {
    padding: 4px 10px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.delete-btn:hover {
    background: var(--danger-hover);
}

/* Ranking list */
.help-text {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 15px;
}

.zone-label {
    font-size: 16px;
    margin: 15px 0 8px;
    color: var(--text);
}

.ranking-list {
    list-style: none;
    min-height: 80px;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 20px;
}

.ranked-zone {
    background: var(--ranked-bg);
    border: 2px solid var(--ranked-border);
}

.unranked-zone {
    background: var(--unranked-bg);
    border: 2px dashed var(--unranked-border);
}

.ranked-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 8px;
    background: var(--bg-surface);
    cursor: grab;
    user-select: none;
}

.ranked-item:active {
    cursor: grabbing;
}

.drag-handle {
    margin-right: 10px;
    color: var(--text-subtle);
    font-size: 18px;
}

.sortable-ghost {
    opacity: 0.4;
    background: var(--ghost-bg);
}

/* Results list */
.results-list {
    list-style: none;
}

.results-list li {
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-bottom: 8px;
    background: var(--bg-surface-alt);
    font-weight: 500;
}

.results-list li:first-child {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

/* Theme toggle */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    transition: background 0.2s;
    z-index: 1000;
}

.theme-toggle:hover {
    background: var(--bg-surface-alt);
}

/* Ballot toggle button */
.toggle-btn {
    padding: 6px 16px;
    border: 2px solid;
    border-radius: 20px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.toggle-open {
    background: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success-text);
}

.toggle-open:hover {
    background: var(--success);
    color: white;
}

.toggle-closed {
    background: var(--bg-surface-alt);
    border-color: var(--danger);
    color: var(--danger);
}

.toggle-closed:hover {
    background: var(--danger);
    color: white;
}

/* Stats page */
.stats-list {
    margin-top: 30px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid var(--border-light);
}

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

.stat-label {
    font-weight: 500;
    color: var(--text);
}

.stat-value {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--primary);
}

/* About page */
.ballot ol,
.ballot ul {
    margin: 15px 0;
    padding-left: 25px;
    line-height: 1.8;
}

.ballot ol {
    list-style: decimal;
}

.ballot ul {
    list-style: disc;
}

.ballot li {
    margin: 8px 0;
}

.ballot ul ul {
    margin-top: 8px;
    margin-bottom: 0;
}

.ballot h2 {
    margin-top: 30px;
}

.ballot .back-link {
    margin-top: 40px;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
}

/* New ballot button in ballot controls */
.new-ballot-btn {
    padding: 6px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    display: inline-block;
}

.new-ballot-btn:hover {
    background: var(--bg-surface-alt);
    color: var(--text);
    text-decoration: none;
}

/* Name input row */
.your-name-row {
    margin: 8px 0 12px;
    text-align: center;
}

.your-name-row input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    background: var(--bg-surface-alt);
    color: var(--text);
    text-align: center;
    width: 250px;
    max-width: 100%;
}

.your-name-row input:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
    background: var(--bg-surface);
}

/* Participant info and popup */
.participant-info {
    position: relative;
    text-align: center;
    margin: 0 0 16px;
}

.participant-count {
    font-size: 13px;
    color: var(--text-subtle);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.2s;
}

.participant-count:hover {
    background: var(--bg-surface-alt);
    color: var(--text);
}

.ballot .participant-list {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 0;
    margin-top: 4px;
    min-width: 150px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 100;
    list-style: none;
}

.ballot .participant-list li {
    padding: 6px 16px;
    color: var(--text);
    font-size: 14px;
    white-space: nowrap;
}

.ballot .participant-list li:hover {
    background: var(--bg-surface-alt);
}

.ballot .participant-list .anonymous-label {
    color: var(--text-subtle);
    font-style: italic;
}

.ballot .participant-list .anonymous-label:hover {
    background: transparent;
    cursor: default;
}

/* Item meta container */
.item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* Item attribution */
.item-attribution {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}
