:root {
    --page-bg: #f0f4f8;
    --wrap-bg: #bccce0;
    --wrap-fg: #0a0a0a;
    --line: #000000;
    --shadow: #312f2f;
    --accent: #88a4c8;
    --admin-bg: #dee0bc;
    --danger: #a14f4a;
    --term-bg: #000000;
    --term-fg: #dee0bc;
    --term-dim: #88a4c8;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--page-bg) url("garden.svg");
    font-family: "JetBrains Mono", "Noto Sans Mono", "Courier New", monospace;
}

#wrap {
    border: 2px solid #0a0a0a;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 48px);
    height: calc(100dvh - 48px);
    max-width: 800px;
    margin: 24px auto;
    background: var(--wrap-bg);
    color: var(--wrap-fg);
    box-shadow: 12px 12px 0 var(--shadow);
}

a {
    color: inherit;
}

button, .menu a {
    border: 1px outset var(--line);
    padding: 2px 6px;
    background: var(--page-bg);
    color: inherit;
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

/* Header + footer bars: tinted while signed in as admin */
#topbar {
    padding: 8px;
    border-bottom: 2px dotted var(--line);
}

footer {
    display: flex;
    justify-content: space-between;
    padding: 4px 8px;
    border-top: 2px dotted var(--line);
}

body.admin #topbar, body.admin footer {
    background: var(--admin-bg);
}

.menu, .menu-right {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.menu a {
    width: 8ch;
}

.menu-right {
    margin-left: auto;
}

.menu a[aria-current="page"] {
    background: var(--accent);
}

#admin-btn {
    width: 8ch;
    background: var(--admin-bg);
}

body:not(.admin) .admin-only {
    display: none;
}

/* Fixed row under the nav: holds the + button and keeps the top airy */
#toolbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    height: 48px;
    padding: 0 8px;
}

#add-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    font-size: 1.25rem;
    line-height: 1;
    background: #bce0d0;
}

main {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.page {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
}

/* Standard spacing around every content block */
section, #chat-canvas {
    margin: 8px 16px;
}

h2 {
    font-size: 1rem;
    margin: 0;
}

.plain-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.muted {
    opacity: 0.7;
    font-size: 0.85em;
}

button.del {
    height: 24px;
    width: 24px;
    padding: 0 4px;
    background: var(--danger);
}

.row {
    display: flex;
    align-items: baseline;
    gap: 0 12px;
}

.row .del, .row .tools {
    margin-left: auto;
}

.tools {
    display: flex;
    gap: 4px;
}

button.move {
    width: 24px;
    height: 24px;
    padding: 0;
}

/* Home posts: the list carries the margin so the empty-state text lines up too */
#post-list {
    margin: 8px 16px;
}

#post-list section {
    margin: 0 0 20px;
    padding: 10px 12px;
    border: 1px dotted var(--line);
}

.post-body {
    margin: 6px 0 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Stuff: uniform cards */
#stuff-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    max-width: 640px;
    margin: 0 auto;
}

.card {
    position: relative;
    border: 1px solid var(--line);
    background: var(--page-bg);
}

.card-body {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
}

.thumb {
    display: block;
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: var(--accent);
}

.card-text {
    padding: 6px 8px 0;
    height: calc(4 * 1.4em + 6px);
    line-height: 1.4;
    overflow: hidden;
}

.card-url {
    padding: 2px 8px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card .del {
    position: absolute;
    top: 4px;
    right: 4px;
}

/* Links: title row (with move/delete tools), description below; headers inline */
#link-list li {
    margin-bottom: 8px;
}

.link-desc {
    display: block;
}

#link-list .link-header {
    margin-top: 12px;
    font-weight: 600;
}

#link-list li:first-child.link-header {
    margin-top: 0;
}

/* Files */
#file-list li {
    margin-bottom: 6px;
}

/* Chat: dark canvas with the log growing up from the input */
#chat {
    flex: 1 1 0;
    min-height: 0;
}

#chat-canvas {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--term-bg);
    color: var(--term-fg);
    border-radius: 2%;
}

#chat-messages {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 8px 16px 0;
}

/* Pushes messages to the bottom while keeping the list scrollable */
#chat-messages li:first-child {
    margin-top: auto;
}

#chat-messages li {
    display: grid;
    grid-template-columns: max-content max-content 1fr auto;
    column-gap: 2ch;
    margin: 0 0 2px;
}

.msg-time, .msg-name {
    color: var(--term-dim);
}

.msg-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

#chat-form {
    margin: 0;
    padding: 12px 16px 16px;
}

#chat-input {
    display: flex;
    padding: 6px 8px;
    border: 1px solid #f2f5f9;
    border-radius: 6px;
    line-height: 1.4;
    cursor: text;
}

#chat-input span {
    color: var(--term-dim);
    white-space: pre;
}

#chat-text {
    flex: 1;
    height: calc(6 * 1.4em);
    padding: 0;
    border: none;
    outline: none;
    resize: none;
    background: none;
    color: var(--term-fg);
    font: inherit;
    line-height: inherit;
}

/* Status: 2-column widget grid */
#widget-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.widget {
    border: 1px solid var(--line);
    padding: 8px;
    background: var(--page-bg);
}

.widget dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 2px 16px;
    margin: 6px 0 0;
}

.widget dt {
    opacity: 0.7;
}

.widget dd {
    margin: 0;
}

/* Add-entry dialog */
#editor {
    width: min(480px, calc(100vw - 32px));
    border: 2px solid var(--line);
    background: var(--wrap-bg);
    color: var(--wrap-fg);
    font: inherit;
}

#editor label {
    display: block;
    margin-bottom: 8px;
}

#editor input:not([type="file"]), #editor textarea {
    display: block;
    width: 100%;
    margin-top: 2px;
    padding: 4px;
    border: 1px solid var(--line);
    background: var(--page-bg);
    font: inherit;
}

#editor textarea {
    height: 12em;
    resize: vertical;
}

#editor-error {
    min-height: 1.2em;
    margin: 0;
    color: var(--danger);
}

.editor-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

@media (max-width: 600px) {
    #wrap {
        height: 100vh;
        height: 100dvh;
        margin: 0;
        box-shadow: none;
    }

    #widget-grid, #stuff-list {
        grid-template-columns: 1fr;
    }
}
