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

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --surface2: #0f3460;
    --accent: #e94560;
    --text: #eee;
    --text-dim: #888;
    --done: #555;
    --radius: 10px;
    --gap: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-tap-highlight-color: transparent;
}

#app {
    max-width: 500px;
    margin: 0 auto;
    padding: var(--gap);
    padding-top: env(safe-area-inset-top, 12px);
    padding-bottom: calc(env(safe-area-inset-bottom, 12px) + 20px);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--gap);
}

header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    flex: 1;
}

#refresh-btn, #settings-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px;
}

#refresh-btn:active {
    transform: rotate(180deg);
    transition: transform 0.3s;
}

#settings-panel {
    background: var(--surface);
    border-radius: var(--radius);
    padding: var(--gap);
    margin-bottom: var(--gap);
    display: flex;
    gap: 8px;
    align-items: end;
}

#settings-panel label {
    flex: 1;
    font-size: 0.8rem;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#settings-panel input {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--surface2);
    background: var(--bg);
    color: var(--text);
    font-size: 0.9rem;
}

#settings-panel button {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}

#add-recurrence {
    width: 75px;
    padding: 8px 4px;
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
}

#add-form {
    display: flex;
    gap: 6px;
    margin-bottom: var(--gap);
    flex-wrap: wrap;
}

#add-text {
    flex: 1;
    padding: 10px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
}

#add-priority {
    width: 60px;
    padding: 8px 4px;
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
}

#add-tag {
    width: 70px;
    padding: 8px;
    border-radius: var(--radius);
    border: 1px solid var(--surface2);
    background: var(--surface);
    color: var(--text);
    font-size: 0.85rem;
}

#add-form button {
    padding: 10px 16px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
}

#filters {
    display: flex;
    gap: 6px;
    margin-bottom: var(--gap);
    align-items: center;
}

.filter-btn {
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--surface2);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
}

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

#filter-tag {
    margin-left: auto;
    padding: 6px 8px;
    border-radius: 20px;
    border: 1px solid var(--surface2);
    background: transparent;
    color: var(--text);
    font-size: 0.85rem;
}

#filter-tag option {
    background: var(--surface);
}

#todo-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.todo-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--surface);
    border-radius: var(--radius);
    border-left: 4px solid transparent;
}

.todo-item.p1 { border-left-color: #4a9; }
.todo-item.p2 { border-left-color: #fa0; }
.todo-item.p3 { border-left-color: var(--accent); }

.todo-item.done {
    opacity: 0.5;
}

.todo-item.done .todo-text {
    text-decoration: line-through;
    color: var(--done);
}

.todo-check {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--text-dim);
    background: transparent;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    color: transparent;
}

.todo-item.done .todo-check {
    border-color: var(--accent);
    color: var(--accent);
}

.todo-content {
    flex: 1;
    min-width: 0;
}

.todo-text {
    font-size: 0.95rem;
    line-height: 1.3;
}

.todo-meta {
    display: flex;
    gap: 6px;
    margin-top: 2px;
    align-items: center;
}

.todo-tag {
    font-size: 0.7rem;
    color: var(--text-dim);
    background: var(--bg);
    padding: 2px 8px;
    border-radius: 10px;
}

.todo-recurrence {
    font-size: 0.7rem;
    color: #6af;
    background: rgba(102, 170, 255, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
}

.todo-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

.todo-edit, .todo-delete {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.todo-item:hover .todo-edit,
.todo-item:hover .todo-delete,
.todo-item:active .todo-edit,
.todo-item:active .todo-delete {
    opacity: 1;
}

/* Mobile: always show action buttons */
@media (hover: none) {
    .todo-edit, .todo-delete { opacity: 0.6; }
}

/* Edit form */
.todo-item.editing {
    border-left-color: var(--accent);
}

.edit-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.edit-text {
    width: 100%;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid var(--surface2);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
}

.edit-row {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.edit-row select, .edit-row input {
    padding: 6px;
    border-radius: 6px;
    border: 1px solid var(--surface2);
    background: var(--bg);
    color: var(--text);
    font-size: 0.8rem;
}

.edit-row input { width: 60px; }

.edit-save {
    padding: 6px 12px;
    border-radius: 6px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
}

.edit-cancel {
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid var(--surface2);
    background: transparent;
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
}

#empty-state {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 0;
    font-size: 0.95rem;
}

.hidden { display: none !important; }

input::placeholder { color: var(--text-dim); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
