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

:root {
    --bg: #f5f2ed;
    --bg2: #edeae3;
    --surface: #ffffff;
    --surface2: #f9f7f4;
    --border: #dedad3;
    --text: #1a1816;
    --text2: #6b6560;
    --text3: #a09a93;
    --accent: #c8502a;
    --accent-light: #f0e8e3;
    --accent2: #2a6bc8;
    --green: #2a8a5a;
    --green-light: #e3f0ea;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.1);
    --radius: 10px;
    --transition: 0.18s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] {
    --bg: #141210;
    --bg2: #1c1917;
    --surface: #242019;
    --surface2: #2c2823;
    --border: #3a3530;
    --text: #f0ece6;
    --text2: #9a9289;
    --text3: #5a5450;
    --accent: #e8714a;
    --accent-light: #2d1f18;
    --accent2: #5a9ae8;
    --green: #4aae7a;
    --green-light: #162b20;
    --shadow: 0 2px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
}

html { font-size: 16px; }

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background var(--transition), color var(--transition);
    line-height: 1.6;
}

/* ── HEADER ── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 2rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(8px);
}

.logo {
    font-family: 'Playfair Display', serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
}

.logo span { color: var(--accent); }

.header-actions { display: flex; gap: 0.5rem; align-items: center; }

.btn {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    padding: 0.45rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text2);
    cursor: pointer;
    transition: all var(--transition);
    letter-spacing: 0.01em;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.btn:hover { background: var(--bg2); color: var(--text); border-color: var(--text3); }

.btn-accent {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-accent:hover { opacity: 0.88; color: #fff; border-color: var(--accent); }

.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--bg2); border-color: var(--border); }

/* ── MAIN LAYOUT ── */
main {
    max-width: 960px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem 5rem;
}

.intro {
    margin-bottom: 2.5rem;
    animation: fadeUp 0.5s ease both;
}

.intro h1 {
    font-family: 'Playfair Display', serif;
    font-size: clamp(1.6rem, 4vw, 2.4rem);
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin-bottom: 0.5rem;
}

.intro p {
    color: var(--text2);
    font-size: 0.95rem;
    font-weight: 300;
    max-width: 480px;
}

/* ── SECTIONS ── */
.section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
    animation: fadeUp 0.4s ease both;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.1rem;
}

.section-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.05rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge {
    font-family: 'DM Sans', sans-serif;
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    background: var(--accent-light);
    color: var(--accent);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ── QUESTION INPUT ── */
.question-wrap { position: relative; }

.question-input {
    width: 100%;
    font-family: 'DM Sans', sans-serif;
    font-size: 1rem;
    font-weight: 400;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--bg);
    color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.question-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.question-input::placeholder { color: var(--text3); }

/* ── TAG LISTS ── */
.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.8rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem 0.35rem 0.85rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 0.83rem;
    font-weight: 400;
    color: var(--text);
    transition: all var(--transition);
    animation: popIn 0.2s ease both;
}

.tag.criterion-tag { flex-direction: column; align-items: flex-start; border-radius: 8px; padding: 0.5rem 0.8rem; min-width: 120px; }
.tag.criterion-tag .tag-name { font-size: 0.83rem; font-weight: 500; }
.tag.criterion-tag .tag-weight-row { display: flex; align-items: center; gap: 0.4rem; width: 100%; }
.tag.criterion-tag .weight-label { font-size: 0.72rem; color: var(--text3); white-space: nowrap; }
.tag.criterion-tag .weight-val { font-size: 0.72rem; font-weight: 500; color: var(--accent); min-width: 20px; }

.tag-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text3);
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
    transition: color var(--transition);
    display: flex;
    align-items: center;
}
.tag-remove:hover { color: var(--accent); }

.weight-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 70px;
    height: 3px;
    border-radius: 99px;
    background: var(--border);
    outline: none;
    cursor: pointer;
}
.weight-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

/* ── ADD INPUT ROW ── */
.add-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.add-input {
    flex: 1;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.88rem;
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.add-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.add-input::placeholder { color: var(--text3); }

/* ── MATRIX TABLE ── */
.matrix-wrap {
    overflow-x: auto;
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 420px;
}

thead th {
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text3);
    padding: 0.5rem 0.75rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

thead th.option-head { text-align: left; padding-left: 1rem; }

tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface2); }

tbody td {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: center;
    vertical-align: middle;
}

tbody td.option-cell {
    text-align: left;
    font-weight: 500;
    font-size: 0.9rem;
    padding-left: 1rem;
    white-space: nowrap;
    color: var(--text);
}

.score-input {
    width: 52px;
    text-align: center;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.88rem;
    font-weight: 500;
    padding: 0.3rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
    -moz-appearance: textfield;
}

.score-input::-webkit-inner-spin-button,
.score-input::-webkit-outer-spin-button { -webkit-appearance: none; }

.score-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

td.total-cell {
    font-weight: 700;
    font-size: 0.92rem;
    color: var(--text);
}

.rank-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 0.75rem;
    font-weight: 700;
    background: var(--bg2);
    color: var(--text2);
}

.rank-1 .rank-pill { background: var(--accent); color: #fff; }

tr.rank-1 td.option-cell { color: var(--accent); }

/* ── RESULTS PANEL ── */
.results-panel {
    margin-top: 1.5rem;
}

.result-bar-wrap { margin-bottom: 0.85rem; }

.result-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 0.3rem;
}

.result-name {
    font-size: 0.88rem;
    font-weight: 500;
}

.result-score {
    font-size: 0.82rem;
    color: var(--text2);
    font-family: 'DM Sans', sans-serif;
}

.bar-track {
    height: 6px;
    background: var(--bg2);
    border-radius: 99px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 99px;
    background: var(--accent);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.bar-fill.rank-1 { background: var(--accent); }
.bar-fill.rank-2 { background: var(--accent2); }
.bar-fill.rank-3 { background: var(--green); }
.bar-fill.rank-n { background: var(--text3); }

/* ── WINNER CARD ── */
.winner-card {
    background: var(--accent-light);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    animation: fadeUp 0.3s ease both;
}

.winner-trophy { font-size: 1.6rem; }

.winner-text h3 {
    font-family: 'Playfair Display', serif;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--accent);
}

.winner-text p {
    font-size: 0.82rem;
    color: var(--text2);
    font-weight: 300;
}

/* ── EMPTY STATE ── */
.empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text3);
    font-size: 0.88rem;
    font-weight: 300;
    font-style: italic;
}

/* ── TOAST ── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--text);
    color: var(--bg);
    font-size: 0.83rem;
    font-weight: 500;
    padding: 0.6rem 1.2rem;
    border-radius: 99px;
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── ANIMATIONS ── */
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.85); }
    to   { opacity: 1; transform: scale(1); }
}

/* ── EXPORT TARGET ── */
#export-target {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
}

/* ── DIVIDER ── */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.25rem 0;
}

/* ── HINT TEXT ── */
.hint {
    font-size: 0.75rem;
    color: var(--text3);
    font-weight: 300;
    margin-top: 0.4rem;
}

/* ── RESPONSIVE ── */
@media (max-width: 600px) {
    /* Header */
    header {
        padding: 0.75rem 1rem;
        gap: 0.5rem;
    }

    .logo { font-size: 1.2rem; }

    .header-actions { gap: 0.25rem; }

    /* Hide button text labels on mobile, keep icons */
    .btn-ghost .btn-label { display: none; }

    /* Shrink buttons on mobile */
    .btn {
        padding: 0.4rem 0.65rem;
        font-size: 0.78rem;
    }

    .btn-accent { padding: 0.4rem 0.75rem; }

    /* Main */
    main { padding: 1.25rem 0.875rem 4rem; }

    .intro { margin-bottom: 1.75rem; }

    .intro h1 { font-size: 1.5rem; }

    /* Sections */
    .section { padding: 1rem; }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    /* Add row — stack vertically on very small screens */
    .add-row {
        flex-direction: column;
        align-items: stretch;
    }

    .add-row .btn {
        width: 100%;
        justify-content: center;
    }

    .add-input { width: 100%; }

    /* Criteria tags — full width on mobile */
    .tag-list { gap: 0.4rem; }

    .tag.criterion-tag {
        width: 100%;
        min-width: unset;
    }

    .weight-slider { flex: 1; width: auto; min-width: 0; }

    /* Matrix — horizontal scroll with sticky first column */
    .matrix-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 6px;
        border: 1px solid var(--border);
    }

    table { min-width: unset; font-size: 0.8rem; }

    thead th {
        padding: 0.4rem 0.5rem;
        font-size: 0.7rem;
    }

    /* Sticky option column */
    thead th.option-head,
    tbody td.option-cell {
        position: sticky;
        left: 0;
        background: var(--surface);
        z-index: 2;
        border-right: 1px solid var(--border);
        max-width: 90px;
        white-space: normal;
        word-break: break-word;
        padding-left: 0.6rem;
    }

    tbody tr:hover td.option-cell { background: var(--surface2); }
    tr.rank-1 td.option-cell { background: var(--surface); }

    tbody td {
        padding: 0.5rem 0.4rem;
    }

    /* Smaller score inputs on mobile */
    .score-input {
        width: 40px;
        font-size: 0.82rem;
        padding: 0.25rem 0.2rem;
    }

    /* Results */
    .result-meta { flex-wrap: wrap; gap: 0.15rem; }
    .result-score { font-size: 0.78rem; }

    /* Winner card */
    .winner-card { padding: 0.8rem 1rem; gap: 0.75rem; }
    .winner-trophy { font-size: 1.3rem; }
    .winner-text h3 { font-size: 0.95rem; }
}
