:root {
    --bg: #333232;
    --paper: #2b2b2a;
    --text: #ffffff;
    --muted: #cccccc;
    --line: #494949;
    --accent: #3a7bd5;
    --accent-dark: #0056b3;
    --accent-soft: #494949;
    --success: #4CAF50;
    --success-bg: #243a25;
    --error: #F44336;
    --error-bg: #3a2220;
    --shadow: 0 16px 38px rgba(0, 0, 0, 0.26);
    --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.22);
    --content-max: 100%;
    --page-gutter: clamp(16px, 3.5vw, 64px);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent);
    text-decoration: none;
    text-underline-offset: 3px;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
a,
input,
select,
textarea {
    transition: border-color 140ms ease, color 140ms ease, background-color 140ms ease;
}

:focus-visible {
    outline: 3px solid rgba(58, 123, 213, 0.34);
    outline-offset: 3px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(51, 50, 50, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.nav {
    width: min(100%, var(--content-max));
    min-height: 58px;
    margin: 0 auto;
    padding: 0 var(--page-gutter);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}

.wordmark {
    color: var(--text);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: 0;
}

.wordmark:hover {
    color: var(--accent);
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px 14px;
    font-size: 0.95rem;
}

.nav-links a,
.link-button {
    border-radius: 999px;
    padding: 7px 10px;
    color: var(--muted);
    font-weight: 650;
}

.nav-links a:hover,
.link-button:hover {
    background: var(--accent-soft);
    color: var(--text);
    text-decoration: none;
}

.nav-links a.active,
.nav-links a[aria-current="page"] {
    background: var(--accent);
    color: white;
}

.logout-form {
    margin: 0;
}

.link-button {
    border: 0;
    background: transparent;
    cursor: pointer;
}

.messages {
    width: min(100%, var(--content-max));
    margin: 0 auto;
    padding: 0 var(--page-gutter);
}

.flash {
    margin-top: 12px;
    padding: 9px 12px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 0.95rem;
}

.flash.success {
    color: var(--success);
    background: var(--success-bg);
    border-color: var(--success);
}

.flash.error {
    color: var(--error);
    background: var(--error-bg);
    border-color: var(--error);
}

.inline-flash {
    margin: 0 0 16px;
}

.page {
    width: min(100%, var(--content-max));
    margin: 0 auto;
    padding: 28px var(--page-gutter) 56px;
}

.narrow-page {
    width: min(100%, 640px);
    padding-left: 18px;
    padding-right: 18px;
}

.page-title h1,
.section-head h1,
.form-card h1 {
    margin: 0 0 18px;
    font-size: 2rem;
    line-height: 1.1;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.78rem;
    letter-spacing: 0;
}

.search-panel {
    max-width: 960px;
}

.compact-search {
    max-width: none;
}

.search-panel label,
.form-card label,
.comment-form label,
.report-card label {
    display: block;
    margin: 14px 0 7px;
    color: var(--muted);
    font-weight: 700;
    font-size: 0.9rem;
}

.search-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="file"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    color: var(--text);
    padding: 12px 13px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(58, 123, 213, 0.24);
}

input[type="file"] {
    padding: 10px;
}

input[type="file"]::file-selector-button {
    margin-right: 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--accent-soft);
    color: var(--text);
    padding: 8px 12px;
    font-weight: 700;
    cursor: pointer;
}

textarea {
    resize: vertical;
}

.primary-button,
.secondary-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid transparent;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
}

.primary-button {
    color: white;
    background: var(--accent);
}

.primary-button:hover {
    background: var(--accent-dark);
    text-decoration: none;
}

.secondary-button {
    color: white;
    background: var(--accent-soft);
    border-color: var(--accent);
}

.secondary-button:hover {
    background: #5a5a5a;
    text-decoration: none;
}

.compact-button {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.9rem;
}

.full-button {
    width: 100%;
    margin-top: 18px;
}

.paper-card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    box-shadow: var(--shadow);
}

.section-head,
.page-title {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin: 12px 0 16px;
}

.page-title h1,
.section-head h1,
.section-head h2 {
    margin: 0;
}

.section-head h2 {
    font-size: 1.35rem;
}

.deck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}

.deck-card {
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.deck-card:hover {
    border-color: var(--accent);
}

.deck-card a {
    display: flex;
    flex-direction: column;
    min-height: 178px;
    padding: 18px;
    color: var(--text);
}

.deck-card a:visited {
    color: var(--text);
}

.deck-card a:hover {
    text-decoration: none;
}

.deck-card h2 {
    margin: 22px 0 8px;
    color: var(--text);
    font-size: 1.2rem;
    line-height: 1.2;
}

.deck-card p {
    margin: 0;
    color: var(--muted);
}

.deck-count {
    display: inline-flex;
    align-self: flex-start;
    padding: 5px 9px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--text);
    font-weight: 700;
    font-size: 0.78rem;
}

.deck-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: auto;
    padding-top: 24px;
    color: var(--muted);
    font-size: 0.88rem;
}

.deck-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
}

.deck-list {
    min-height: 180px;
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 18px;
    margin-top: 22px;
}

.pagination a {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--paper);
    padding: 6px 11px;
    font-weight: 700;
}

.pagination a:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    text-decoration: none;
}

.detail-page {
    display: grid;
    gap: 20px;
}

.detail-head {
    padding: 22px;
    display: grid;
    grid-template-columns: 1fr minmax(220px, auto);
    gap: 20px;
    align-items: start;
}

.detail-head h1 {
    margin: 0 0 8px;
    font-size: clamp(2rem, 8vw, 3.5rem);
    line-height: 1.05;
}

.rating-block {
    display: grid;
    gap: 10px;
    justify-items: start;
}

.rating-line {
    display: flex;
    align-items: baseline;
    gap: 8px;
    color: var(--muted);
}

.rating-line strong {
    color: var(--text);
    font-size: 1.2rem;
}

.stars {
    display: inline-flex;
    gap: 4px;
}

.stars form {
    margin: 0;
}

.star-button {
    width: 34px;
    height: 34px;
    padding: 3px;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.star-button:hover {
    opacity: 0.9;
}

.star-button svg {
    width: 100%;
    height: 100%;
    fill: #494949;
    stroke: #888888;
    stroke-width: 1;
}

.star-button.selected svg,
.stars[data-pending="1"] form:nth-child(-n+1) svg,
.stars[data-pending="2"] form:nth-child(-n+2) svg,
.stars[data-pending="3"] form:nth-child(-n+3) svg,
.stars[data-pending="4"] form:nth-child(-n+4) svg,
.stars[data-pending="5"] form:nth-child(-n+5) svg {
    fill: var(--accent);
    stroke: var(--accent-dark);
}

.card-preview-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.flip-card {
    height: 152px;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--text);
    perspective: 1000px;
    cursor: pointer;
}

.flip-inner {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform 180ms ease;
}

.flip-card.flipped .flip-inner {
    transform: rotateY(180deg);
}

.flip-side {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    overflow-wrap: anywhere;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--text);
    backface-visibility: hidden;
}

.flip-front {
    background: var(--paper);
}

.flip-back {
    background: var(--accent-soft);
    transform: rotateY(180deg);
}

.flip-card:hover .flip-side {
    border-color: var(--accent);
}

.report-card,
.form-card,
.table-card,
.comments-block {
    padding: 20px;
}

.form-card {
    box-shadow: var(--shadow-sm);
}

.auth-switch {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.auth-switch p {
    margin: 0 0 10px;
    color: var(--muted);
    text-align: center;
}

.report-card summary {
    cursor: pointer;
    font-weight: 800;
}

.comment-form {
    margin-bottom: 20px;
}

.comment-form .primary-button,
.report-card .secondary-button {
    margin-top: 12px;
}

.comments-block h2 {
    margin: 0 0 12px;
}

.comment-list {
    display: grid;
    gap: 12px;
}

.comment {
    padding: 14px 0 0;
    border-top: 1px solid var(--line);
}

.comment:first-child {
    border-top: 0;
}

.comment p {
    margin: 7px 0 0;
}

.comment-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 0.9rem;
}

.comment-head strong {
    color: var(--text);
}

.reports-head {
    margin-top: 28px;
}

.reports-head span {
    color: var(--muted);
    font-weight: 700;
}

.reports-card {
    padding: 18px;
}

.report-item {
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
}

.report-item:first-of-type {
    padding-top: 0;
}

.report-item:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.report-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.report-head a {
    font-weight: 800;
}

.report-head span,
.report-item small {
    color: var(--muted);
}

.report-item p {
    margin: 8px 0 4px;
}

.reported-card {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 10px;
}

.reported-card span {
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #333332;
    overflow-wrap: anywhere;
}

.report-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.report-footer form {
    margin: 0;
}

.form-card form {
    display: grid;
}

.field-note,
.small-note,
.empty-state {
    color: var(--muted);
}

.empty-state {
    margin: 0;
    border: 1px dashed var(--line);
    border-radius: var(--radius);
    background: #2b2b2a;
    padding: 18px;
}

.field-note {
    margin: 8px 0 0;
    font-size: 0.9rem;
}

.field-error {
    margin: 6px 0 0;
    color: var(--error);
    font-size: 0.9rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.table-card {
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

th,
td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 800;
}

tbody tr:hover {
    background: #3d3d3c;
}

tr:last-child td {
    border-bottom: 0;
}

.uploaded-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.deck-tools summary {
    list-style: none;
    cursor: pointer;
}

.deck-tools summary::-webkit-details-marker {
    display: none;
}

.edit-chip {
    display: inline-block;
    padding: 5px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
}

.deck-tools summary:hover .edit-chip,
.deck-tools[open] .edit-chip {
    border-color: var(--accent);
    color: var(--text);
    background: var(--accent-soft);
}

.deck-tool-forms {
    display: grid;
    gap: 10px;
    width: 320px;
    max-width: 100%;
    margin-top: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #2f2f2e;
}

.deck-tool-form {
    display: grid;
    gap: 6px;
}

.deck-tool-form + .deck-tool-form {
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.deck-tool-form label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
    margin: 0;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 800;
}

.label-hint {
    color: var(--muted);
    font-weight: 500;
    font-size: 0.78rem;
}

.tool-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
}

.tool-row input[type="file"] {
    min-width: 0;
    padding: 6px;
    font-size: 0.88rem;
}

.tool-row input[type="file"]::file-selector-button {
    margin-right: 10px;
    padding: 6px 10px;
    font-size: 0.85rem;
}

.tool-button {
    min-width: 84px;
}

@media (max-width: 680px) {
    .nav {
        align-items: flex-start;
        flex-direction: column;
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .nav-links {
        justify-content: flex-start;
        gap: 6px;
    }

    .search-row,
    .detail-head,
    .section-head,
    .page-title {
        grid-template-columns: 1fr;
        display: grid;
        align-items: stretch;
    }

    .search-row .primary-button {
        width: 100%;
    }

    .comment-head {
        display: grid;
    }

    .uploaded-cell {
        min-width: 0;
    }

    .uploaded-row {
        flex-wrap: wrap;
        gap: 8px;
    }

    .tool-row {
        grid-template-columns: 1fr;
    }

    .tool-button {
        width: 100%;
    }
}
