* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    background: #f4f4f5;
    color: #18181b;
    line-height: 1.5;
}

main, .container {
    max-width: 46rem;
    margin: 0 auto;
    padding: 1rem;
}

h1 {
    font-size: 1.4rem;
    margin: 1.25rem 0 0.5rem;
}

h2 {
    font-size: 1.1rem;
    margin: 1.5rem 0 0.5rem;
}

input, button {
    font: inherit;
    padding: 0.45rem 0.7rem;
    border: 1px solid #a1a1aa;
    border-radius: 6px;
    background: #fff;
}

button {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
    cursor: pointer;
}

button:hover { background: #1d4ed8; }

input:focus {
    outline: 2px solid #93c5fd;
    border-color: #2563eb;
}

form.inline {
    display: flex;
    gap: 0.4rem;
    align-items: center;
    flex-wrap: wrap;
}

form.inline input[type="text"] { min-width: 0; flex: 1 1 12rem; width: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #e4e4e7;
    border-radius: 8px;
    margin-top: 0.75rem;
}

td, th {
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid #e4e4e7;
    text-align: left;
    vertical-align: middle;
}

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

img.thumb {
    max-width: 12rem;
    max-height: 12rem;
    width: 12rem;
    height: 12rem;
    object-fit: contain;
    display: block;
    border-radius: 4px;
}

.login-card {
    background: #fff;
    border: 1px solid #e4e4e7;
    border-radius: 8px;
    padding: 1.5rem;
    max-width: 22rem;
    margin-top: 2rem;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.upload form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

.votebar {
    display: flex;
    gap: 1rem;
    align-items: center;
    flex-wrap: wrap;
    background: #fff;
    border: 1px solid #e4e4e7;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-top: 0.75rem;
}

.votebar #status { color: #16a34a; }

.vote-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.card {
    background: #fff;
    border: 1px solid #e4e4e7;
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.card img {
    width: 100%;
    height: 10rem;
    object-fit: contain;
    background: #fafafa;
    border-radius: 4px;
}

.card .row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.card .row .count {
    flex: 1;
    text-align: center;
    font-weight: 600;
    font-size: 1.1rem;
}

.card button {
    width: 2.2rem;
    padding: 0.3rem 0;
    font-weight: 700;
}

.card button:disabled {
    background: #a1a1aa;
    border-color: #a1a1aa;
    cursor: default;
}

@media (max-width: 40rem) {
    body { font-size: 1.05rem; }
    main, .container { padding: 0.75rem; }
    h1 { font-size: 1.5rem; }
    input, button {
        font-size: 1rem;
        padding: 0.6rem 0.9rem;
    }
    /* make touch targets full-width and easy to tap */
    .login-card form button,
    .upload form button { width: 100%; }
    .upload form input[type="file"] { width: 100%; }

    table, tbody, tr, td {
        display: block;
        width: 100%;
    }
    thead { display: none; }
    tr {
        border: 1px solid #e4e4e7;
        border-radius: 8px;
        background: #fff;
        margin-bottom: 0.75rem;
        padding: 0.25rem 0.5rem;
    }
    td { border-bottom: none; padding: 0.4rem 0.5rem; }
    td:first-child { font-weight: 600; }

    /* results table becomes cards: "1st place - 20 votes", submitter, image */
    table.results tr { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 0.25rem; }
    td.rank { order: 0; font-weight: 600; width: auto; }
    td.rank::after { content: " place -"; }
    td.votes { order: 1; font-weight: 600; width: auto; }
    td.votes::after { content: " votes"; }
    td.submitter { order: 2; flex: 1 1 100%; }
    td.submitter::before { content: "Submitted by "; font-weight: normal; }
    td.preview { order: 3; flex: 1 1 100%; }
    td.preview img.thumb { margin-left: 0; }

    form.inline input[type="text"] { flex: 1 1 100%; }
}

nav {
    background: #fff;
    border-bottom: 1px solid #e4e4e7;
    padding: 0.6rem 1rem;
    display: flex;
    gap: 1rem;
    font-weight: 600;
}

nav form { display: inline; }
nav button.linklike {
    background: none;
    border: none;
    padding: 0;
    color: #2563eb;
    font-weight: 600;
}
nav button.linklike:hover { text-decoration: underline; background: none; }

td .title {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
