:root {
    --bg-color: #121212;
    --card-bg: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent: #2e7d32;
    --delete-color: #d32f2f;
    --copy-btn: #1565c0;
    --border-color: #333;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    margin: 0;
    padding: 10px;
    line-height: 1.5;
    overscroll-behavior-y: none;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
}

header {
    text-align: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #b388ff;
}

#reset-container {
    display: none;
    margin-top: 10px;
}

#controls {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap;
}

.reset-btn {
    background: #1b1b1b;
    border: 1px solid #3a3a3a;
    color: #ff5e96;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    letter-spacing: 0.2px;
}

.clear-btn {
    background: #1b1b1b;
    border: 1px solid #3a3a3a;
    color: var(--text-primary);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    cursor: pointer;
    letter-spacing: 0.2px;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    font-size: 0.85rem;
    user-select: none;
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 0;
}

.toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    accent-color: var(--accent);
}

/* Mobile hint - hidden by default, shown on mobile */
.mobile-hint {
    display: none;
    background: linear-gradient(135deg, rgba(179, 136, 255, 0.15) 0%, rgba(46, 125, 50, 0.15) 100%);
    border: 1px solid rgba(179, 136, 255, 0.3);
    border-radius: 8px;
    padding: 10px 15px;
    margin: 0 auto 15px auto;
    max-width: 800px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.mobile-hint.hidden {
    display: none !important;
}

.mobile-hint strong {
    color: #b388ff;
}

.hint-dismiss {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    opacity: 0.7;
}

.hint-dismiss:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 768px) {
    .mobile-hint:not(.hidden) {
        display: flex;
    }
}

#challenge-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 800px;
    margin: 0 auto;
    padding-bottom: 150px;
    /* Extra space for trash can */
    position: relative;
}

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: relative;
    touch-action: pan-y;
    transform: translate3d(0, 0, 0);
    /* Hardware acceleration */
}

.ec-themed {
    border-left: 4px solid var(--ec-color);
}

.ec-prefix {
    font-weight: 700;
    color: var(--ec-color);
}

.ec-1 {
    --ec-color: #5aa8ff;
}

.ec-2 {
    --ec-color: #81c784;
}

.ec-3 {
    --ec-color: #ffb74d;
}

.ec-4 {
    --ec-color: #ba68c8;
}

.ec-5 {
    --ec-color: #4db6ac;
}

.ec-6 {
    --ec-color: #e57373;
}

.ec-7 {
    --ec-color: #ff8a65;
}

.ec-8 {
    --ec-color: #f06292;
}

.ec-9 {
    --ec-color: #aed581;
}

.ec-10 {
    --ec-color: #ffd54f;
}

.ec-11 {
    --ec-color: #9575cd;
}

.ec-12 {
    --ec-color: #26c6da;
}

.card.done {
    opacity: 0.6;
    background-color: #181818;
    border-color: #222;
}

.card.done .task-text {
    text-decoration: line-through;
    color: var(--text-secondary);
}

/* Ghost styling (the item floating under finger) */
.card.dragging-ghost {
    position: fixed;
    z-index: 9999;
    width: calc(100% - 40px);
    max-width: 760px;
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.6);
    background: #2c2c2c;
    opacity: 0.95;
    pointer-events: none;
    transform: scale(1.02);
    border: 1px solid var(--accent);
    top: 0;
    left: 0;
    will-change: top, left;
    transition: opacity 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

/* Delete mode styling for ghost */
.card.dragging-ghost.deleting {
    opacity: 0.6;
    border: 3px solid #ff4444;
    background: linear-gradient(135deg, #2c2c2c 0%, #3d1a1a 100%);
    box-shadow: 0 15px 30px rgba(255, 0, 0, 0.3);
}

/* Placeholder styling (the hole in the list) */
.card.placeholder {
    background: rgba(255, 255, 255, 0.02);
    border: 2px dashed #444;
    opacity: 0.5;
}

.card.placeholder>* {
    opacity: 0;
    /* Hide content but keep size */
}

.card-header {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.drag-handle {
    cursor: grab;
    color: #666;
    font-size: 1.5rem;
    padding: 5px 15px 5px 0;
    /* Bigger touch target */
    touch-action: none;
    /* Crucial for preventing scroll */
}

.drag-handle:active {
    color: var(--accent);
}

.checkbox-wrapper {
    padding-top: 4px;
}

input[type="checkbox"] {
    appearance: none;
    width: 24px;
    height: 24px;
    border: 2px solid var(--text-secondary);
    border-radius: 4px;
    background: transparent;
    position: relative;
    display: inline-block;
}

input[type="checkbox"]:checked {
    background-color: var(--accent);
    border-color: var(--accent);
}

input[type="checkbox"]:checked::after {
    content: '✔';
    color: white;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.task-text {
    flex: 1;
    font-size: 1rem;
    word-wrap: break-word;
    outline: none;
    user-select: text;
    -webkit-user-select: text;
}

.task-text:focus {
    background: #333;
    color: #fff;
    padding: 2px;
    border-radius: 4px;
}

.actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 5px;
    border-top: 1px solid #333;
    padding-top: 8px;
    gap: 8px;
}

.tree-preview {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-right: auto;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    overflow: visible;
    text-overflow: clip;
    max-width: none;
    flex: 1;
    min-width: 0;
    outline: none;
}

.tree-preview:focus {
    background: #2b2b2b;
    color: #fff;
    padding: 2px 4px;
    border-radius: 4px;
}

.copy-btn {
    background: var(--copy-btn);
    color: white;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.copy-btn.copied {
    background: var(--accent);
}

#trash-zone {
    position: fixed;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: rgba(211, 47, 47, 0.7);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    transition: bottom 0.2s ease, transform 0.15s ease, background-color 0.15s ease;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#trash-zone.visible {
    bottom: 15px;
}

#trash-zone.active {
    background-color: rgba(183, 28, 28, 0.95);
    transform: translateX(-50%) scale(1.15);
}

#trash-zone .icon {
    font-size: 1.4rem;
}

@media (max-width: 400px) {
    .card {
        padding: 12px;
    }

    .task-text {
        font-size: 0.95rem;
    }
}

/* Hide drag handle on mobile - use long press instead */
@media (max-width: 768px) {
    .drag-handle {
        display: none;
    }

    .card {
        touch-action: pan-y;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }

    /* Prevent context menu on long press */
    .card * {
        -webkit-touch-callout: none;
    }

    .tree-preview {
        white-space: pre-wrap;
        overflow: visible;
        text-overflow: clip;
        max-width: none;
    }
}

@media (max-width: 520px) {
    #controls {
        flex-direction: column;
        align-items: center;
    }

    .reset-btn,
    .clear-btn,
    .toggle {
        width: auto;
        max-width: 100%;
        justify-content: center;
        text-align: center;
    }

    .toggle {
        white-space: normal;
    }
}

footer {
    text-align: center;
    padding: 20px 10px;
    margin-top: 20px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.85rem;
}

footer a {
    color: #b388ff;
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}