/* === Fonts === */
@font-face {
    font-family: "Iosevka Etoile";
    src: url("/_/fonts/IosevkaEtoile.woff2") format("woff2");
    font-display: swap;
}
@font-face {
    font-family: "Iosevka Slab";
    src: url("/_/fonts/IosevkaSlab.woff2") format("woff2");
    font-display: swap;
}

/* === Theme === */
:root {
    --bg: #2e2e2e;
    --bg-panel: #434343;
    --bg-panel-hover: #585858;
    --text: #e6e6e6;
    --text-muted: #cfcfcf;
    --primary: #87458a;
    --primary-hover: #d64d95;
    --secondary: #c48401;
    --link: #01b6c4;
    --link-hover: #d6d24d;
    --danger: #c40141;
    --danger-hover: #d03467;
}

/* === Base === */
body {
    background-color: var(--bg);
    min-height: 100vh;
    margin: 0;
    overflow: auto;
    padding: 0;
    color: var(--text);
    font:
        1rem "Iosevka Etoile",
        monospace;
    display: flex;
    flex-direction: column;
}

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

/* === Links === */
a {
    color: var(--text);
    text-decoration: none;
}
a:hover {
    color: var(--primary-hover);
}

.content a {
    color: var(--link);
}
.content a:hover {
    color: var(--link-hover);
}

/* Broken wiki link: target folder does not exist */
.content a.broken {
    color: var(--primary-hover);
    text-decoration: line-through;
}
.content a.broken:hover {
    color: var(--link-hover);
}

/* === Header === */
header {
    padding: 0.75rem 1rem;
    border-bottom: 1px dashed var(--secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
    flex: 1;
}

.logo {
    width: 1.1em;
    height: 1.1em;
    vertical-align: center;
}

.sep {
    color: var(--secondary);
}

.btn {
    background: none;
    border: none;
    color: var(--text);
    font: inherit;
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
}
.btn::before {
    content: "[";
    color: var(--secondary);
}
.btn::after {
    content: "]";
    color: var(--secondary);
}
.btn:hover {
    color: var(--primary-hover);
}

/* === Button modifiers === */
/* For inline buttons */
.btn-small {
    font-size: 0.65rem;
    font-weight: normal;
    vertical-align: middle;
}

/* For toolbars */
.btn-tool {
    font-size: 0.85rem;
    padding: 0 0.15rem;
}

/* Destructive action */
.danger {
    color: var(--danger);
}
.danger:hover {
    color: var(--danger-hover);
}

/* === Main === */
main {
    max-width: 860px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    width: 100%;
    flex: 1;
}

/* === Markdown content === */
.content {
    margin-bottom: 2rem;
}

.content h1,
.content h2,
.content h3,
.content h4,
.content h5,
.content h6 {
    color: var(--text);
    margin: 1.25rem 0 0.5rem;
    line-height: 1.3;
}
.content h1 {
    font-size: 1.75rem;
    border-bottom: 1px dashed var(--secondary);
    padding-bottom: 0.25rem;
}
.content h2 {
    font-size: 1.4rem;
}
.content h3 {
    font-size: 1.15rem;
}
.content p {
    margin: 0.75rem 0;
}
.content ul,
.content ol {
    margin: 0.75rem 0 0.75rem 1.5rem;
}
.content li {
    margin: 0.25rem 0;
}
.content blockquote {
    border-left: 3px solid var(--secondary);
    padding: 0.25rem 1rem;
    color: var(--text-muted);
    margin: 0.75rem 0;
}
.content code {
    font-family: "Iosevka Etoile", monospace;
    font-size: 0.875em;
    background: var(--bg-panel);
    padding: 0.1em 0.35em;
}
.content pre {
    background: var(--bg-panel);
    border: 1px solid var(--secondary);
    padding: 1rem;
    overflow-x: auto;
    margin: 0.75rem 0;
}
.content pre code {
    background: none;
    padding: 0;
}
.content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.9rem;
}
.content th,
.content td {
    border: 1px solid var(--secondary);
    padding: 0.4rem 0.75rem;
    text-align: left;
}
.content th {
    background: var(--bg-panel);
    color: var(--text);
}
.content hr {
    border: none;
    border-top: 1px dashed var(--secondary);
    margin: 1.5rem 0;
}
.content img {
    max-width: 100%;
}

a.heading-anchor {
    color: var(--text-muted);
    margin-right: 0.4em;
    font-weight: normal;
}
a.heading-anchor:hover {
    color: var(--primary-hover);
}

/* === File listing === */
.listing {
    border: 1px solid var(--secondary);
}
main > h2 {
    color: var(--text);
    margin: 1.25rem 0 0.5rem;
    line-height: 1.3;
    font-size: 1.4rem;
}
.listing-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
}
.listing-item + .listing-item {
    border-top: 1px solid var(--secondary);
}
.listing-item:hover {
    background: var(--bg-panel-hover);
}
.listing-item .icon {
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}
.listing-item a {
    flex: 1;
    overflow-wrap: anywhere;
    color: inherit;
}
.listing-item .meta {
    color: var(--text-muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

/* === Editor toolbar === */
.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    border: 1px solid var(--secondary);
    border-bottom: none;
    padding: 0.4rem 0.6rem;
    background: var(--bg-panel-hover);
}

.toolbar-sep {
    width: 1px;
    background: var(--secondary);
    margin: 0 0.2rem;
    align-self: stretch;
}

/* === Dropdowns === */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    display: none;
    z-index: 100;
    background: var(--bg-panel);
    border: 1px solid var(--secondary);
    min-width: 9rem;
}

.dropdown-menu.align-right {
    left: auto;
    right: 0;
}

.dropdown-menu.open-up {
    top: auto;
    bottom: 100%;
    margin-bottom: 0.4rem;
}

.dropdown-menu.is-open {
    display: block;
}

.dropdown-menu.scrollable {
    max-height: 14rem;
    overflow-y: auto;
}

/* === Floating action button === */
.fab {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 50;
}

.btn-fab {
    background: var(--bg-panel);
    border: 1px solid var(--secondary);
    width: 3rem;
    height: 3rem;
    font-size: 1.5rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-fab::before,
.btn-fab::after {
    content: none;
}
.btn-fab:hover {
    background: var(--bg-panel-hover);
    color: var(--primary-hover);
}

.dropdown-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    width: 100%;
    border: none;
    border-radius: 0;
    padding: 0.3rem 0.75rem;
    white-space: nowrap;
    box-sizing: border-box;
}

/* === Edit form === */
.edit-form {
    display: flex;
    flex-direction: column;
}

body.editor-wide main {
    max-width: none;
}

textarea {
    width: 100%;
    min-height: 60vh;
    background: var(--bg);
    border: 1px solid var(--secondary);
    border-top: none;
    color: var(--text);
    font-family: "Iosevka Slab", monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    padding: 1rem;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
}

/* === Search === */
.search-form {
    display: flex;
    gap: 0.25rem;
}
.search-input {
    background: var(--bg-panel);
    border: 1px solid var(--secondary);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    padding: 0.3rem 0.5rem;
    min-width: 0;
    width: 12rem;
    max-width: 100%;
    outline: none;
}
.search-input:focus {
    border-color: var(--primary-hover);
}
.search-card {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px dashed var(--secondary);
    word-break: break-word;
}
.search-card:last-child {
    border-bottom: none;
}
.search-card a {
    color: var(--link);
    font-size: 1.1rem;
}
.search-card a:hover {
    color: var(--link-hover);
}

/* === Muted text === */
.muted {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* === Page footer === */
footer {
    padding: 0.75rem 1rem;
    border-top: 1px dashed var(--secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* === Companion status === */
.companion-status {
    margin-left: auto;
}
.companion-icon {
    font-size: 0.9rem;
    line-height: 1;
    padding: 0.1rem 0.3rem;
}
.companion-on {
    color: var(--link);
}
.companion-off {
    color: var(--text-muted);
}
.companion-flyout {
    min-width: 14rem;
    padding: 0.4rem;
}
.companion-line {
    padding: 0.25rem 0.5rem;
    font-size: 0.85rem;
}

/* === Task lists === */
.content li:has(> input.task-checkbox:checked) {
    color: var(--text-muted);
    text-decoration: line-through;
}

/* === Photo grid === */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.4rem;
    margin-top: 0.75rem;
}

.photo-grid a {
    display: block;
    line-height: 0;
}

.photo-grid img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
    background: var(--bg-panel) url("/_/icons/thumb-placeholder.svg") center/2rem no-repeat;
}

/* === Empty state === */
.empty {
    padding: 1rem;
    text-align: center;
}

/* === hr === */
hr {
    border: none;
    border-top: 1px dashed var(--secondary);
    margin: 1rem 0;
}

/* === Scrollbars === */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: #111;
}
::-webkit-scrollbar-thumb {
    background: var(--primary);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary-hover);
}

/* === Table of contents === */
.toc {
    position: fixed;
    top: 1rem;
    right: 1rem;
    width: 14rem;
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    border: 1px solid var(--secondary);
    background: var(--bg);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.panel-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px dashed var(--secondary);
    padding-bottom: 0.25rem;
    margin-bottom: 0.4rem;
}

.toc ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc li {
    margin: 0.15rem 0;
}

.toc a {
    color: var(--link);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.toc a:hover {
    color: var(--link-hover);
}

.toc-h3 {
    padding-left: 0.8rem;
}
.toc-h4 {
    padding-left: 1.6rem;
}

.panel-toggle {
    display: none;
}

/* === Modal === */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}

.modal {
    background: var(--bg-panel);
    border: 1px solid var(--secondary);
    width: 100%;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    margin-top: 6rem;
    position: relative;
}

.modal.is-dragged {
    margin: 0;
}

.modal-header {
    padding: 0.6rem 1rem;
    border-bottom: 1px dashed var(--secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text);
    cursor: move;
    user-select: none;
}

.modal-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    word-break: break-word;
}

.modal-footer {
    padding: 0.6rem 1rem;
    border-top: 1px dashed var(--secondary);
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
}

.modal-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--secondary);
    color: var(--text);
    font: inherit;
    font-family: "Iosevka Slab", monospace;
    padding: 0.4rem 0.6rem;
    outline: none;
}

.modal-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* === Tree picker === */
.tree-picker {
    max-height: 60vh;
    overflow-y: auto;
    border: 1px solid var(--secondary);
    background: var(--bg);
}
.tree-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.5rem;
    cursor: pointer;
    min-height: 2rem;
}
.tree-row:hover {
    background: var(--bg-panel-hover);
}
.tree-row.is-selected {
    background: var(--bg-panel-hover);
    border-left: 3px solid var(--primary);
    padding-left: calc(0.5rem - 3px);
}
.tree-row.is-disabled {
    color: var(--text-muted);
    cursor: default;
}
.tree-row.is-disabled:hover {
    background: none;
}
.tree-chevron {
    width: 1.25rem;
    text-align: center;
    color: var(--secondary);
    flex-shrink: 0;
}
.tree-chevron.is-leaf {
    visibility: hidden;
}
.tree-marker {
    width: 1rem;
    text-align: center;
    color: var(--text-muted);
    flex-shrink: 0;
}
.tree-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tree-children {
    padding-left: 1.5rem;
}
.tree-selected-path {
    font-size: 0.85rem;
    padding: 0.25rem 0;
    word-break: break-all;
}

/* === Movie info box === */
.movie-info {
    margin: 0.75rem 0;
}
.movie-info::after {
    content: "";
    display: block;
    clear: both;
}
.movie-info .movie-poster {
    float: right;
    max-width: 200px;
    margin: 0 0 0.75rem 1rem;
}
.movie-info table {
    width: auto;
}
@media (max-width: 600px) {
    .movie-info .movie-poster {
        float: none;
        display: block;
        margin: 0 auto 0.75rem;
    }
}

/* === Diary Calendar === */
.diary-cal {
    position: fixed;
    top: 1rem;
    left: 1rem;
    width: 13rem;
    border: 1px solid var(--secondary);
    background: var(--bg);
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
}

.diary-cal-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    margin-bottom: 0.4rem;
    font-size: 0.85rem;
}

.diary-cal-nav .diary-cal-drop + .diary-cal-heading {
    margin-left: 0.75rem;
}

.diary-cal-heading {
    color: var(--link);
}

.diary-cal-heading:hover {
    color: var(--link-hover);
}

.diary-cal-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-bottom: 0.4rem;
}

.diary-cal-grid th,
.diary-cal-grid td {
    text-align: center;
    padding: 0.1rem 0.15rem;
    font-weight: normal;
    color: var(--text-muted);
}

.diary-cal-grid td a {
    color: var(--link);
    display: block;
}

.diary-cal-grid td a:hover {
    color: var(--link-hover);
}

.diary-cal-grid td.cal-empty a {
    color: var(--text-muted);
}

.diary-cal-grid td.cal-empty a:hover {
    color: var(--link-hover);
}

.diary-cal-grid td.cal-today {
    background: var(--bg-panel);
}

.diary-cal-grid td.cal-current,
.diary-cal-grid td.cal-current a {
    color: var(--primary-hover);
}

.dropdown-item.cal-current {
    color: var(--primary-hover);
}

/* === Responsive === */
@media (max-width: 1100px) {
    .panel-toggle {
        display: block;
        background: none;
        border: 1px solid var(--secondary);
        color: var(--text);
        font: inherit;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        cursor: pointer;
        padding: 0.4rem 0.75rem;
        margin: 1rem auto;
        width: calc(100% - 2rem);
        max-width: 860px;
    }
    .panel-toggle::before {
        content: "▸ ";
        color: var(--secondary);
    }
    .panel-toggle[aria-expanded="true"]::before {
        content: "▾ ";
    }
    .toc,
    .diary-cal {
        position: static;
        display: none;
        width: calc(100% - 2rem);
        max-width: 860px;
        margin: 0 auto 1rem;
        max-height: none;
    }
    .toc.is-open,
    .diary-cal.is-open {
        display: block;
    }
}

@media (max-width: 600px) {
    header,
    footer {
        padding: 0.5rem 0.75rem;
    }
    main {
        padding: 1rem 0.75rem;
    }
    textarea {
        min-height: 50vh;
    }
    .panel-toggle,
    .toc.is-open,
    .diary-cal.is-open {
        width: calc(100% - 1.5rem);
    }
    .modal-backdrop {
        padding: 0.5rem;
        align-items: flex-start;
    }
    .modal {
        max-width: none;
        margin-top: 1rem;
    }
    .modal-header {
        cursor: default;
    }
    .listing-item {
        flex-wrap: wrap;
    }
    .listing-item .meta {
        flex-basis: 100%;
        padding-left: calc(1.25rem + 0.75rem);
    }
}
