:root {
    color-scheme: light dark;

    --background-color: #FFFFFF;
    --panel-background-color: rgba(247, 247, 247, 0.5);
    --panel-item-background-color: rgba(239, 239, 239, 0.5);
    --drop-area-background-color: rgba(0,0,0,0.06);
    --table-background-color: #F7F7F7;
    --table-header-background-color: #EFEFEF;
    --error-color: #8b0000;
    --input-background-hover: color-mix(in srgb, CanvasText 5%, transparent);
}

@media (prefers-color-scheme: dark) {
    :root {
        --background-color: #1d1d1d;
        --panel-background-color: rgba(36, 36, 36, 0.5);
        --panel-item-background-color: rgba(44, 44, 44, 0.5);
        --drop-area-background-color: rgba(255,255,255,0.03);
        --table-background-color: #242424;
        --table-header-background-color: #2C2C2C;
        --error-color: #ff6b6b;
        --input-background-hover: color-mix(in srgb, CanvasText 8%, transparent);
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-family: ui-serif, "Times New Roman", serif;
    font-size: 62.5%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
    background-color: var(--background-color);
}

body {
    overflow: auto;
    font-size: 1.7rem;
    letter-spacing: 0.01em;
    line-height: 180%;
}

/* 
 ------------------------------------------------
 Home page content
 ------------------------------------------------
 */

main {
    flex-grow: 1;
    
    display: flex;
    flex-direction: column;
    align-items: center;
    
    padding: 60px 2em 30px 2em;
    
    min-height: 0;
}

main > section,
main > article {
    width: 100%;
    max-width: 600px;
    
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
}

main > section > ul {
    padding: 0;
    width: 100%;
}

main > section > ul > a {
    text-decoration: none;
    color: inherit;
}

main > section > ul > a > li {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 1rem;
    row-gap: 0;
    align-items: baseline;
    margin: 0.5em 0;
}

main > section > ul.counted > a > li {
    grid-template-columns: 1.4em 1fr auto;
}

main > section > ul > a:hover > li {
    color: LinkText !important;
}

main section a span.post-id {
    text-align: right;
}

main section a span.post-title {
    text-decoration: underline;
    text-decoration-thickness: 1px;
}

main section a span.post-date {
    text-align: right;
}

#compose {
    position: absolute;
    right: 0;
    anchor-name: --compose-anchor;
}

/*
 ------------------------------------------------
 Blog post content
 ------------------------------------------------
 */

body > main > svg {
    margin-bottom: 20px;
}

main article {
    display: flex;
    flex-direction: column;
    margin: 0;
    padding-bottom: 60px;
}

main > section > h1,
main article h1 {
    font-size: 3.2rem;
    line-height: normal;
}

main article h4 {
    margin-block-end: 0.3em;
}

main article p {
    margin: 0.5em 0;
}

main article sup {
    line-height: 0;
    font-size: 1.3rem;
}

main article p span.reference {
    font-size: 1.3rem;
}

main article li {
    padding: 0 0;
}

main article li p {
    margin-block-start: 0.5em;
    margin-block-end: 0.5em;
}

main article blockquote {
    font-style: italic;
    font-size: 1.25em;
    line-height: 160%;
    opacity: 0.8;
}

main article a {
    color: inherit;
}

main article table {
    background: var(--table-background-color);
    border-radius: 12px;
    font-size: 0.8em;
    padding: 6px;
    margin: 20px 0px;
}

main article table > thead th {
    background: var(--table-header-background-color);
    padding: 8px;
}

main article table > thead th:first-child {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
}

main article table > thead th:last-child {
    border-top-right-radius: 8px;
    border-bottom-right-radius: 8px;
}

main article table td {
    padding: 4px 6px;
}

main article ul {
    margin: 0.5em 0;
}

main article img {
    max-width: 100%;
}

main > a,
main > a > svg {
    color: inherit;
}

main article > a > svg.signature {
    transform: translateX(-16px);
}

main article > header {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
    gap: 16px;
    width: 100%;
    margin: 1em 0 2em 0;
}

main article > header .details {
    min-width: 0;
    display: flex;
    flex-direction: column;
    justify-content: stretch;
}

main article > header h1 {
    margin: 0;
}

main article > header h3 {
    margin: 0.6em 0;
}

main article > header p {
    margin: 0;
    font-size: 1.4rem;
}

main article > header ul {
    margin: 0.5em 0 0 0;
    padding: 0;
    font-size: 1.4rem;
}

main article > header ul > li {
    margin: 0;
    padding: 0;
    display: inline-block;
}

main article > header ul > li + li::before {
    content: " · ";
}

main article > header ul > li > a:hover {
    color: LinkText !important;
}

main article > header .artwork {
    display: flex;
    align-items: flex-start;
    justify-content: flex-end;
}

main article > header .artwork > img {
    max-width: 130px;
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
    border-radius: 5px;
}

main article section.post {
    padding-bottom: 30px;
}

main article section.post a {
    text-decoration: none;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 0.4rem;
    row-gap: 0;
    align-items: baseline;
}

main article section.post a:hover {
    color: LinkText !important;
}

main section.quotes article * {
    height: 0;
    overflow: hidden;
    margin: 0;
}

main section.quotes article blockquote {
    height: auto;
    margin: 20px 0;
    font-size: 1.5em;
}

main section.quotes article blockquote * {
    height: auto;
}

article.note > p.published-date {
    margin: 0;
}

/*
 ------------------------------------------------
 Note detail (inline editing)
 ------------------------------------------------
 */

.note-new,
article.note:has(.note-edit-area) {
    position: relative;
}

.note-new {
    margin-bottom: 2em;
}

.note-edit-area {
    position: relative;
    margin-top: 1em;
    display: none;
}

article.note:has(.note-edit-area) > button {
    position: absolute;
    top: -2px;
    right: -4px;
    padding: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

article.note:has(.note-edit-area):hover > button {
    opacity: 1;
}

article.note.editing > button {
    display: none;
}

article.note.editing .note-body {
    display: none;
}

article.note.editing .note-edit-area {
    display: block;
}

.note-new textarea,
article.note.editing textarea {
    width: calc(100% + 16px);
    border: none;
    outline: none;
    background: transparent;
    font: inherit;
    line-height: inherit;
    color: inherit;
    padding: 4px 72px 4px 8px;
    margin: 0 -8px;
    resize: none;
    border-radius: 6px;
    overflow: hidden;
    display: block;
}

.note-new textarea:hover,
article.note.editing textarea:hover,
.note-new textarea:focus,
article.note.editing textarea:focus {
    background: var(--input-background-hover);
    outline: none;
}

.note-new textarea::placeholder {
    color: currentColor;
    opacity: 0.35;
}

@keyframes note-saved-flash {
    0%   { opacity: 1; }
    40%  { opacity: 0.4; }
    100% { opacity: 1; }
}

article.note.note-saved {
    animation: note-saved-flash 0.5s ease;
}

article.note.note-unsaved > p.published-date::after,
.note-new.note-unsaved::before {
    content: " · unsaved";
    color: var(--error-color);
    font-style: italic;
    font-size: 1.3rem;
}

.note-new.note-unsaved::before {
    content: "unsaved · ";
    display: block;
}

article.note.note-error textarea,
.note-new.note-error textarea {
    outline: 1px solid var(--error-color);
    border-radius: 6px;
}

ol.instructions {
  list-style-position: inside;
  padding-left: 0;
  margin-left: 0;
  font-weight: 500;
}

ol.instructions > li > picture {
    text-align: center;
}

ol.instructions > li > picture {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 1rem auto;
}

ol.instructions > li > picture img {
    max-width: 100%;
}

hr {
    border: none;
    border-top: 1px solid;
}

article hr {
    margin: 1.5em 0;
}

/*
 ------------------------------------------------
 Preview
 ------------------------------------------------
 */

main > section > ul > a > li span.primary-info {
    text-decoration: underline;
    text-decoration-thickness: 1px;
}

/*
 ------------------------------------------------
 Panels
 ------------------------------------------------
 */

.panel {
    max-width: 640px;
    z-index: 1100;
    
    /* Translucent, blurred background */
    background: var(--panel-background-color);
    -webkit-backdrop-filter: blur(12px) saturate(120%);
    backdrop-filter: blur(12px) saturate(120%);
    border-radius: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.18);
    
    padding: 1em;
    overflow: hidden;
}

.panel ul {
    margin: 0;
    padding: 0;
    list-style: none;
    width: 100%;
}

.panel ul li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    cursor: pointer;
}

.panel ul li svg {
    width: 17px;
    max-height: 14px;
}

.panel hr {
    opacity: 0.2;
}

.popup {
    display: none;
    position: absolute;
}

.popup.open {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
}

#compose-panel {
    position-anchor: --compose-anchor;
    top: anchor(bottom);
    right: anchor(right);
    margin-bottom: 0.5rem;
    gap: 1rem;
}

.panel-header button {
    padding: 0;
}

#compose-panel ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

#compose-panel ul a {
    text-decoration: none;
    color: inherit;
}

#compose-panel ul a:hover {
    color: LinkText !important;
}


/*
 ------------------------------------------------
 Nav (list pages with search & filter)
 ------------------------------------------------
 */

main > section > nav {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 600px;
    margin-top: 2em;
}

main > section > nav > form {
    display: flex;
    flex: 1;
    margin: 0 0.5rem;
    opacity: 0;
    transition: opacity 200ms ease;
}

main > section > nav > form:hover,
main > section > nav > form:focus-within,
main > section > nav > form:has(input:not(:placeholder-shown)) {
    opacity: 1;
    transition: opacity 100ms ease;
}

main > section > nav > button {
    padding: 1px;
}

main > section > nav > form input[type="search"] {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font: inherit;
    font-family: system-ui, -apple-system, Helvetica, sans-serif;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background-color 0.3s ease;
}

main > section > nav > form input[type="search"]::-webkit-search-cancel-button {
    display: none;
}

main > section > nav > form input[type="search"]:hover,
main > section > nav > form input[type="search"]:focus,
main > section > nav > form input[type="search"]:not(:placeholder-shown) {
    background: var(--input-background-hover);
}

#filter-open {
    anchor-name: --filter-anchor;
}

#filter-panel {
    position-anchor: --filter-anchor;
    top: anchor(bottom);
    right: anchor(right);
    margin-bottom: 0.5rem;
    min-width: 180px;
}

.filter-item label {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    gap: 0.5rem;
}

/*
 ------------------------------------------------
 Footer
 ------------------------------------------------
 */

footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1.2rem;
    opacity: 1;
    transition: opacity 0.5s ease-in;
    padding-bottom: env(safe-area-inset-bottom);
}

footer > nav {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 1.2rem;

    width: 100%;
    max-width: 600px;
    
    margin-bottom: 1.5em;
}

footer > nav a {
    display: inline-flex;
    align-items: center;
    color: inherit;
    opacity: 0.65;
    text-decoration: none
}

footer > nav a:hover {
    opacity: 1;
}

footer > nav a > svg {
    width: 20px;
    max-height: 17px;
}

/*
 ------------------------------------------------
 Sign Out Form
 ------------------------------------------------
 */

form#signout {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

/*
 ------------------------------------------------
 Classes
 ------------------------------------------------
 */

.published-date {
    font-size: 1.3rem;
    font-style: italic;
    opacity: 0.65;
}

p.published-date {
    margin: 1.6em 0;
    display: block;
}

.signin-button {
    width: 240px;
    height: 40px;
    margin: 40px;
}

.signin-button > div > div > svg {
    width: 100%;
    height: 100%;
    color: red;
}

.signin-button:hover {
    cursor: pointer;
}

.signin-button > div {
    outline: none;
}

.invisible {
    opacity: 0;
    pointer-events: none;
}

.system-info {
    font-size: 1.5rem;
    font-weight: 500;
    opacity: 0.75;
    font-family: system-ui, -apple-system, Helvetica, sans-serif;
}

/*
 ------------------------------------------------
 Toolbar
 ------------------------------------------------
 */

#toolbar {
    position: absolute;
    top: 0px;
    width: 100%;
}

#toolbar :is(button, a).icon {
    margin: 16px;
}

:is(button, a).icon {
    border: none;
    background: none;
    color: inherit;
    cursor: pointer;
    text-decoration: none;
}

:is(button, a).icon > svg {
    width: 20px;
    max-height: 17px;
    opacity: 0.65;
}

:is(button, a).icon.small > svg {
    width: 14px;
    max-height: 12px;
}

:is(button, a).icon.active > svg,
:is(button, a).icon > svg:hover {
    opacity: 1;
}

:is(button, a).icon:hover {
    background: none;
    filter: none;
}

.note-badge {
    font-size: 1.2rem;
    opacity: 0.65;
}

/*
 ------------------------------------------------
 Mobile adjustments
 ------------------------------------------------
 */

@media screen and (max-width: 600px) {
    main {
        padding: calc(env(safe-area-inset-top) + 20px) 1.2em 20px 1.2em;
    }
    
    main > section > ul.counted > a > li {
        grid-template-columns: 1.4em 1fr;
        grid-template-rows: auto auto;
    }

    main > section > ul.counted > a > li > span.post-id {
        grid-column: 1;
        grid-row: 1;
    }

    main > section > ul.counted > a > li > span.post-title {
        grid-column: 2;
        grid-row: 1;
    }

    main > section > ul.counted > a > li > span.post-date {
        grid-column: 2;
        grid-row: 2;
        text-align: left;
    }
    
    main article blockquote {
        margin-inline-start: 20px;
        margin-inline-end: 20px;
    }
    
    main article > a > svg.signature {
        transform: translateX(-12px);
    }
    
    main article > header {
        display: flex;
        flex-direction: column-reverse;
        align-items: initial;
        gap: 2em;
    }
    
    main article > header .artwork {
        justify-content: center;
    }
}

@supports (height: 100dvh) {
    html, body {
        min-height: 100dvh;
    }
}
