:root {
    --bg: #EDE8DB;
    --brown: #80572B;
    --brown-light: #a87942;
    --brown-dark: #5c3d1e;
    --brown-faint: rgba(128, 87, 43, 0.08);
    --brown-border: rgba(128, 87, 43, 0.18);
    --brown-line: #80572B;
    --text: #3d2a14;
    --text-muted: #8c7560;
    --card-bg: rgba(255, 255, 255, 0.5);
    --card-hover: rgba(255, 255, 255, 0.75);
    --radius: 12px;
}

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

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

body {
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

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

/* ── Header ──────────────────────────────────────────────────────── */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.2rem 2rem;
    border-bottom: 1px solid var(--brown-border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.star {
    width: 28px;
    height: 28px;
    color: var(--brown);
}

.logo-text {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    color: var(--brown);
}

/* ── User Badge ─────────────────────────────────────────────────── */

.user-badge-area {
    position: relative;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--brown-border);
    border-radius: var(--radius);
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    transition: background 0.15s;
}

.user-badge:hover {
    background: var(--card-hover);
}

.user-badge-empty {
    color: var(--text-muted);
    font-style: italic;
}

.badge-avatar svg {
    width: 28px;
    height: 28px;
    display: block;
}

.badge-name {
    font-weight: 600;
}

.user-editor-overlay {
    position: fixed;
    top: 0.75rem;
    right: 1.5rem;
    z-index: 300;
}

.user-editor {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: white;
    border: 1px solid var(--brown-border);
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
}

.editor-preview svg {
    width: 32px;
    height: 32px;
    display: block;
}

.user-editor-name {
    position: relative;
}

.user-editor-name input {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--brown-border);
    border-radius: 6px;
    background: var(--bg);
    font-size: 0.85rem;
    color: var(--text);
    outline: none;
    width: 110px;
}

.user-editor-name input:focus {
    border-color: var(--brown-light);
}

.user-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--brown-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
    max-height: 150px;
    overflow-y: auto;
}

.user-suggestion {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
}

.user-suggestion:hover {
    background: var(--brown-faint);
}

.suggestion-avatar svg {
    width: 20px;
    height: 20px;
    display: block;
}

.shape-picker {
    display: grid;
    grid-template-columns: repeat(6, auto);
    gap: 1px;
}

.shape-option {
    width: 28px;
    height: 28px;
    padding: 2px;
    border: 2px solid transparent;
    border-radius: 4px;
    background: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.1s;
}

.shape-option svg {
    width: 20px;
    height: 20px;
}

.shape-option.selected {
    border-color: var(--brown);
    background: var(--brown-faint);
}

.color-picker {
    display: grid;
    grid-template-columns: repeat(5, auto);
    gap: 3px;
    justify-items: center;
}

.color-option {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s;
}

.color-option.selected {
    border-color: var(--brown-dark);
    transform: scale(1.2);
}

.user-save-btn {
    padding: 0.4rem 0.8rem;
    border: none;
    border-radius: 6px;
    background: var(--brown);
    color: var(--bg);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.user-save-btn:hover {
    background: var(--brown-dark);
}

/* ── Footer ──────────────────────────────────────────────────────── */

.site-footer {
    text-align: center;
    padding: 2rem 1rem;
    font-size: 0.75rem;
    color: #d5d0c4;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.github-link {
    color: #d5d0c4;
    transition: color 0.2s;
}

.github-link:hover {
    color: var(--brown-light);
}

/* ── Pages ───────────────────────────────────────────────────────── */

.page {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

h1 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 2rem;
    color: var(--brown-dark);
    margin-bottom: 1.5rem;
    font-weight: 400;
}

h2 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.5rem;
    color: var(--brown-dark);
    font-weight: 400;
}

.back-link {
    display: inline-block;
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    transition: color 0.15s;
}

.back-link:hover {
    color: var(--brown);
}

.error {
    color: #a03020;
    font-style: italic;
    background: rgba(160, 48, 32, 0.08);
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
}

/* ── Create Form ─────────────────────────────────────────────────── */

/* ── Page header (title + add button) ───────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.page-header h1 {
    margin: 0;
}

.add-btn {
    padding: 0.4rem 1rem;
    border: 1px solid var(--brown-border);
    border-radius: var(--radius);
    background: var(--card-bg);
    color: var(--brown);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.add-btn:hover {
    background: var(--brown);
    color: var(--bg);
}

.add-btn-group {
    display: flex;
    gap: 0.5rem;
}

/* ── Topic Grid ──────────────────────────────────────────────────── */

.topic-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.2rem;
}

.topic-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    padding: 2rem 1.5rem;
    background: var(--card-bg);
    border: 1px solid var(--brown-border);
    border-radius: var(--radius);
    text-align: center;
    transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
    cursor: pointer;
}

.topic-card:hover {
    background: var(--card-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(128, 87, 43, 0.1);
}

.card-star {
    width: 32px;
    height: 32px;
    color: var(--brown);
    opacity: 0.5;
    transition: opacity 0.15s;
}

.topic-card:hover .card-star {
    opacity: 1;
}

.card-title {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.15rem;
    color: var(--brown-dark);
}

.card-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ── Question List ───────────────────────────────────────────────── */

.question-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.question-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border: 1px solid var(--brown-border);
    border-radius: var(--radius);
    transition: background 0.15s, transform 0.15s;
    cursor: pointer;
}

.question-card:hover {
    background: var(--card-hover);
    transform: translateX(4px);
}

.question-text {
    font-size: 1rem;
    color: var(--text);
}

.question-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
    margin-left: 1rem;
}

.kind-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    background: var(--brown-faint);
    color: var(--brown);
    font-weight: 600;
}

.answer-count {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ── Delete button ──────────────────────────────────────────────── */

.delete-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}

.topic-card:hover .delete-btn,
.question-card:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    color: #c0392b;
    background: rgba(192, 57, 43, 0.1);
}

/* ── Voting Circle (closed questions) ────────────────────────────── */

.question-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.question-page .back-link {
    align-self: flex-start;
}

.question-title {
    margin-bottom: 0.5rem;
}

.opinion-text {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 1.1rem;
    color: var(--brown);
    min-height: 3.3em;
    margin-bottom: 1.5rem;
    font-style: italic;
}

.vote-circle-container {
    position: relative;
    width: min(500px, 85vw);
    height: min(500px, 85vw);
    margin-top: 2rem;
    touch-action: none;
    user-select: none;
}

.vote-circle {
    position: absolute;
    inset: 7%;
    border-radius: 50%;
    border: 2px solid var(--brown-border);
    background: var(--brown-faint);
    cursor: default;
}

.answer-add-btn {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    border: 2px solid var(--brown-border);
    background: var(--bg);
    color: var(--brown);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    z-index: 8;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.vote-circle-container:hover .answer-add-btn {
    opacity: 0.5;
}

.answer-add-btn:hover {
    opacity: 1 !important;
    background: var(--brown);
    color: var(--bg);
}

.answer-dot {
    position: absolute;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--brown);
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 2;
}

.answer-label {
    position: absolute;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--brown-dark);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    white-space: nowrap;
}

.answer-label-actions {
    display: flex;
    gap: 0.1rem;
    opacity: 0;
    transition: opacity 0.15s;
}

.answer-label:hover .answer-label-actions {
    opacity: 1;
}

.answer-btn {
    width: 1.3rem;
    height: 1.3rem;
    border: none;
    border-radius: 50%;
    background: var(--brown-border);
    color: var(--brown-dark);
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: background 0.15s;
}

.answer-btn:hover {
    background: var(--brown);
    color: var(--bg);
}

/* ── Label alignment classes ──────────────────────────────────────── */

.answer-label.align-right {
    transform: translate(0, -50%);
}

.answer-label.align-left {
    transform: translate(-100%, -50%);
    flex-direction: row-reverse;
}

.answer-label.align-top {
    transform: translate(-50%, -100%);
    flex-direction: column;
}

.answer-label.align-bottom {
    transform: translate(-50%, 0);
    flex-direction: column;
}

.answer-label.align-top-right {
    transform: translate(0, -100%);
}

.answer-label.align-bottom-right {
    transform: translate(0, 0);
}

.answer-label.align-top-left {
    transform: translate(-100%, -100%);
    flex-direction: row-reverse;
}

.answer-label.align-bottom-left {
    transform: translate(-100%, 0);
    flex-direction: row-reverse;
}

.vote-avatar {
    position: absolute;
    transform: translate(-50%, -50%);
    z-index: 5;
    pointer-events: none;
    opacity: 0.7;
    transition: none;
}

.vote-avatar svg {
    width: 26px;
    height: 26px;
    display: block;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.2));
}

.vote-avatar svg circle,
.vote-avatar svg rect,
.vote-avatar svg polygon,
.vote-avatar svg path {
    stroke: #EDE8DB;
    stroke-width: 3;
    stroke-linejoin: round;
    paint-order: stroke fill;
}

.vote-avatar-me {
    z-index: 10;
    opacity: 1;
    cursor: grab;
    pointer-events: auto;
    transition: none;
    will-change: left, top;
}

.vote-avatar-me svg {
    width: 32px;
    height: 32px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.vote-avatar-me svg circle,
.vote-avatar-me svg rect,
.vote-avatar-me svg polygon,
.vote-avatar-me svg path {
    stroke-width: 4;
}

.vote-avatar-me.dragging {
    cursor: grabbing;
}

.vote-avatar-me.dragging svg {
    transform: scale(1.15);
    filter: none;
}

.avatar-name {
    display: block;
    text-align: center;
    font-size: 0.6rem;
    color: var(--text-muted);
    white-space: nowrap;
    margin-top: 1px;
    pointer-events: none;
}

/* ── Open Question: 2D Plane ─────────────────────────────────────── */

.open-question-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 1;
    padding: 2rem;
}

.open-question-page .back-link {
    align-self: flex-start;
}

.open-plane {
    position: relative;
    width: 100%;
    flex: 1;
    min-height: 300px;
    overflow: visible;
}

.open-answer-form {
    display: flex;
    flex-direction: column;
    margin-top: 1.5rem;
    width: 100%;
    max-width: 600px;
}

.open-answer-form textarea {
    width: 100%;
    padding: 0.65rem 1rem;
    border: 1px solid var(--brown-border);
    border-radius: var(--radius);
    background: var(--card-bg);
    font-size: 0.95rem;
    color: var(--text);
    outline: none;
    resize: vertical;
    min-height: 2.5em;
    max-height: 6em;
    font-family: inherit;
    transition: border-color 0.15s;
}

.open-answer-form textarea:focus {
    border-color: var(--brown-light);
}

.open-answer-form textarea::placeholder {
    color: var(--text-muted);
}

.token-counter {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
    min-height: 1.2em;
    padding: 0.15rem 0.25rem;
    transition: color 0.15s;
}

.token-counter.over-limit {
    color: #c0392b;
    font-weight: 600;
}

/* ── Axis Controls ─────────────────────────────────────────────── */

.axis-controls {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    align-self: flex-end;
    margin-top: 1rem;
}

.axis-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.axis-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    min-width: 1.2rem;
}

.axis-input {
    width: 130px;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--brown-border);
    border-radius: 6px;
    background: var(--card-bg);
    font-size: 0.8rem;
    color: var(--text);
    outline: none;
}

.axis-input:focus {
    border-color: var(--brown-light);
}

.axis-input::placeholder {
    color: var(--text-muted);
}

.axis-send-btn {
    padding: 0.3rem 0.6rem;
    border: none;
    border-radius: 6px;
    background: var(--brown);
    color: var(--bg);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}

.axis-send-btn:hover {
    background: var(--brown-dark);
}

.plane-empty-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: Georgia, "Times New Roman", serif;
    font-style: italic;
    color: var(--text-muted);
    font-size: 1.05rem;
    padding: 2rem;
}

.plane-point {
    position: absolute;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    z-index: 2;
    transition: left 0.8s ease-in-out, top 0.8s ease-in-out;
}

.plane-point:hover {
    z-index: 30;
}

.plane-avatar svg {
    width: 32px;
    height: 32px;
    display: block;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.15));
}

.plane-excerpt {
    position: absolute;
    bottom: calc(100% + 0.2rem);
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    max-height: 3.6em;
    overflow: hidden;
    font-size: 0.7rem;
    line-height: 1.3;
    color: var(--text-muted);
    pointer-events: none;
    text-align: center;
}

.plane-point:hover .plane-excerpt {
    width: 200px;
    max-height: 12em;
    overflow-y: auto;
    z-index: 30;
    background: var(--card-bg);
    border: 1px solid var(--brown-border);
    border-radius: 6px;
    padding: 0.3rem 0.4rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    color: var(--text);
    text-align: left;
    pointer-events: auto;
}

.plane-name {
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ── Responsive ──────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .site-header {
        padding: 1rem;
    }

    .page {
        padding: 1.2rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    .topic-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 0.8rem;
    }

    .topic-card {
        padding: 1.5rem 1rem;
    }

    .user-editor-overlay {
        top: 0.5rem;
        right: 0.5rem;
        left: 0.5rem;
    }

    .user-editor {
        flex-wrap: wrap;
        gap: 0.35rem 0.5rem;
        padding: 0.5rem;
    }

    /* Row 1: name fills left, preview + Enter on right */
    .user-editor-name {
        order: 0;
        flex: 1;
    }

    .user-editor-name input {
        width: 100%;
        box-sizing: border-box;
    }

    .editor-preview {
        order: 1;
    }

    .user-save-btn {
        order: 2;
    }

    /* Row 2: shapes span full width */
    .shape-picker {
        order: 3;
        width: 100%;
        grid-template-columns: repeat(12, 1fr);
        gap: 0;
        justify-items: center;
    }

    .shape-option {
        width: 26px;
        height: 26px;
    }

    .shape-option svg {
        width: 18px;
        height: 18px;
    }

    /* Row 3: colors span full width */
    .color-picker {
        order: 4;
        width: 100%;
        grid-template-columns: repeat(10, 1fr);
        gap: 2px;
    }

    .color-option {
        width: 20px;
        height: 20px;
    }

    .editor-preview svg {
        width: 28px;
        height: 28px;
    }

    .axis-controls {
        align-self: stretch;
    }

    .axis-input {
        flex: 1;
        width: auto;
        min-width: 0;
    }
}
