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

*:not(dialog) {
  margin: 0;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

p {
  text-wrap: pretty;
  hyphens: auto;
  hyphenate-limit-chars: 7
}

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

/* Vars */
:root {
  color-scheme: light dark;
  --white: #faf8f5;
  --black: #1c1b18;
  --colour: #7c3aed;
  --bg: light-dark(var(--white), var(--black));
  --fg: light-dark(var(--black), var(--white));
  --highlight: light-dark(
      var(--colour),
      oklch(from var(--colour) calc(l + 0.20) c h)
  );
  --dots: light-dark(
      oklch(from var(--highlight) calc(l + 0.36) 0.1 h),
      oklch(from var(--highlight) calc(l - 0.60) 0.1 h)
  );
  --links: light-dark(
      oklch(from var(--highlight) calc(l - 0.15) c h),
      oklch(from var(--highlight) calc(l + 0.15) c h)
  );
  --fg-dim: light-dark(
      oklch(from var(--black) calc(l + 0.40) c h),
      oklch(from var(--white) calc(l - 0.40) c h)
  );
  --fg-subtle: light-dark(
      oklch(from var(--black) calc(l + 0.50) c h),
      oklch(from var(--white) calc(l - 0.50) c h)
  );
  --fg-text-dim: light-dark(
      oklch(from var(--black) calc(l + 0.20) c h),
      oklch(from var(--white) calc(l - 0.20) c h)
  );
  --fg-text-very-dim: light-dark(
      oklch(from var(--black) calc(l + 0.10) c h),
      oklch(from var(--white) calc(l - 0.10) c h)
  );
  --highlight-subtle: light-dark(
      oklch(from var(--colour) calc(l + 0.20) 0.1 h / 0.05),
      oklch(from var(--colour) calc(l + 0.40) 0.1 h / 0.05)
  );
  --highlight-transparent: light-dark(
      oklch(from var(--colour) calc(l + 0.20) 0.1 h / 0.1),
      oklch(from var(--colour) calc(l + 0.40) 0.1 h / 0.1)
  );
  --highlight-shadow: light-dark(
      oklch(from var(--colour) calc(l + 0.20) 0.1 h / 0.15),
      oklch(from var(--colour) calc(l + 0.40) 0.1 h / 0.15)
  );
}

/* Styling */
html {
  color: var(--fg);
  background-color: var(--bg);
}

html::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background: var(--dots);
  mask-image: linear-gradient(135deg, white 0%, rgba(255, 255, 255, 0.2) 15%, rgba(255, 255, 255, 0.2) 85%, white 100%),
  url('/static/dots-c978f9f7.svg');
  mask-composite: intersect;
}

html:has(article)::before {
  mask-image: linear-gradient(135deg, white 0%, rgba(255, 255, 255, 0.0) 15%, rgba(255, 255, 255, 0.0) 85%, white 100%),
  url('/static/dots-c978f9f7.svg');
}

body {
  line-height: 1.5;
  display: grid;
  width: 100%;
  height: 100vh;
}

h1 {
  color: var(--highlight);
}

a {
  color: var(--links);
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;

  p {
    padding-bottom: 1rem;

    img {
      max-height: 25vh;
    }
  }

  &:has(article) {
    padding-top: 2rem;

    ul {
      padding-bottom: 1rem;
    }

    nav {
      a {
        align-self: flex-start;
      }

      max-width: 70vw;
    }

    article {
      justify-self: flex-start;
      max-width: 70vw;
      min-width: 80vw;
      padding-bottom: 2rem;
    }
  }

  &:not(:has(article)) {
    justify-content: center;

    ul {
      list-style: none;
      padding: 0;

      li {
        display: inline;

        &:not(:first-child)::before {
          content: " | "
        }
      }
    }
  }
}

nav[aria-label="breadcrumbs"] {
  font-size: 0.85rem;
  padding-bottom: 1rem;

  ol {
    list-style: none;
    padding-left: 0;

    li {
      display: inline-block;

      &:not(:last-child):after {
        content: "›";
        display: inline-block;
        padding: 0 .5ch;
        speak: never;
      }
    }
  }
}

main:has(nav[aria-label="subpages"]) nav[aria-label="breadcrumbs"] {
  padding-bottom: 0;
}

nav[aria-label="subpages"] {
  font-size: 0.85rem;
  padding-bottom: 1rem;

  ul {
    list-style: none;
    padding-left: 0;

    &::before {
      content: "→";
      padding-right: .5ch;
      speak: never;
    }

    li {
      display: inline-block;
      padding-right: 0;

      &:not(:first-child):before {
        content: "·";
        display: inline-block;
        padding: 0 .5ch;
        speak: never;
      }
    }
  }
}

a:not(
	[href^="#"],
	[href^="/"]
)::after {
  content: "↗";
  vertical-align: super;
  font-size: 0.5em;
  display: inline-block;
  bottom: 0.5em;
  padding-left: 1ch;
  position: relative;
}

pre {
  font: inherit;
  white-space: pre-line;
  text-wrap: pretty;
  overflow-wrap: break-word;
}

table {
  width: 100%;
  margin-bottom: 1rem;
  border-collapse: collapse;
  tr {
    border-bottom: 1px solid oklch(from var(--fg) calc(l - 0.50) c h);
    transition: border-color 0.5s ease, background-color 0.5s ease;

    &:hover {
      border-bottom-color: var(--highlight);
    }
  }
  th {
    text-align: left;
    width: 130px;
    padding: 0.5rem 0;
    color: var(--highlight);
    font-weight: normal;
  }
  td {
    padding: 0.5rem 0;
    font-size: 0.95rem;
  }
}

.uses {
  section {
    h2 {
      margin-bottom: 1rem;
      color: var(--highlight);
    }
  }
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 0.5rem;

  .card {
    border: 1px solid oklch(from var(--fg) calc(l - 0.40) c h);
    border-radius: 0.5rem;
    padding: 0.25rem 1rem;
    transition: border-color 0.5s ease, box-shadow 0.5s ease;
    display: grid;
    grid-template-columns: minmax(110px, 130px) 1fr;
    gap: 1rem;
    align-items: flex-start;

    &:hover {
      border-color: var(--highlight);
      box-shadow: 0 4px 12px oklch(from var(--highlight) calc(l - 0.30) 0.1 h / 0.2);
    }

    .card-left {
      padding-top: 0.25rem;

      h3 {
        font-size: 1rem;
        margin: 0;
        color: var(--highlight);
        line-height: 1.3;
      }
    }

    .card-right {
      p {
        margin: 0;
        font-size: 0.95rem;
      }

      .note {
        display: block;
        margin-top: 0.5rem;
        font-size: 0.85em;
        opacity: 0.7;
        font-style: italic;
      }
    }
  }

  &.compact {
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1rem;

    .card {
      grid-template-columns: 120px 1fr;
    }
  }
}

.ramblings-list {
  width: 100%;
  min-width: 80vw;
}

.post-meta {
  color: var(--fg-text-dim);
}

.ramblings-header {
  .header-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;

    h1 {
      margin: 0;
      font-size: 2.5rem;
    }

    .feed-link {
      display: inline-flex;
      align-items: center;
      gap: 0.25rem;
      padding: 0.5rem 1rem;
      border: 1px solid var(--fg-dim);
      border-radius: 2rem;
      color: var(--links);
      text-decoration: none;
      font-size: 0.9rem;
      font-weight: 500;
      transition: all 0.3s ease;

      &:hover {
        border-color: var(--highlight);
        background-color: var(--highlight-transparent);
      }

      svg {
        width: 18px;
        height: 18px;
      }
    }
  }

  .header-subtitle {
    margin: 0.5rem 0 0 0;
    font-size: 1.1rem;
    color: var(--fg-text-dim);
  }
}

.ramblings-intro {
  margin-bottom: 2rem;
  padding: 1rem 1.5rem;
  background-color: var(--highlight-subtle);
  border-left: 3px solid var(--highlight);
  border-radius: 0 0.5rem 0.5rem 0;

  p {
    margin: 0;
  }
}

.ramblings-nav {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;

  h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    color: var(--highlight);
  }

  .year-list, .month-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .year-link, .month-list a {
    padding: 0.35rem 0.75rem;
    border: 1px solid var(--fg-dim);
    border-radius: 0.25rem;
    text-decoration: none;
    color: var(--links);
    font-size: 0.9rem;
    transition: all 0.3s ease;

    &:hover {
      border-color: var(--highlight);
      background-color: var(--highlight-transparent);
    }
  }
}

.posts {
  .posts-count {
    margin: 0 0 1.5rem 0;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--highlight);
  }

  .post-list {
    display: flex;
    flex-direction: column;
  }

  .post-card {
    .post-title {
      margin: 0 0 0.5rem 0;
      font-size: 1.3rem;
      color: var(--highlight);
      transition: color 0.3s ease;
    }
  }

  .post-date {
    display: block;
    margin-bottom: 0.75rem;
    font-size: 0.85rem;
    color: var(--fg-text-dim);
  }

  .post-excerpt {
    margin: 0;
    line-height: 1.6;
    color: var(--fg-text-very-dim);
  }
}

.empty-state {
  padding: 3rem;
  text-align: center;
  background-color: var(--highlight-subtle);
  border-radius: 0.5rem;

  p {
    margin: 0;
    font-size: 1.1rem;
    color: var(--fg-text-dim);
  }
}

img {
  cursor: zoom-in;
}

#lightbox {
  position: fixed;
  inset: 0;
  background: oklch(from var(--bg) calc(l - 0.15) c h / 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;

  &[aria-hidden="false"] {
    opacity: 1;
    pointer-events: auto;

    img {
      transform: scale(1);
    }
  }

  img {
    max-width: 95vw;
    max-height: 95vh;
    cursor: zoom-out;
    object-fit: contain;
    transform: scale(0.95);
    transition: transform 0.3s ease;
  }
}

@media (max-width: 768px) {
  body {
    font-size: 1.1rem;
  }
  main:has(article) {
    padding-top: 3rem;

    nav, article {
      width: 90vw;
      max-width: 70ch;
    }
  }

  .card-grid {
    grid-template-columns: 1fr;

    .card {
      display: flex;
      flex-direction: column;
      gap: 0.25rem;

      .card-left {
        padding-top: 0.5rem;
        padding-bottom: 0.25rem;

        h3 {
          margin-bottom: 0;
        }
      }

      .card-right {
        flex: 1;
      }
    }

    &.compact {
      .card {
        display: flex;
        flex-direction: column;
      }
    }
  }
  .ramblings-list {
    max-width: 100%;
  }

  .ramblings-header .header-title {
    h1 {
      font-size: 2rem;
    }

    .feed-link {
      font-size: 0.85rem;
      padding: 0.4rem 0.8rem;
    }
  }

  .ramblings-nav {
    grid-template-columns: 1fr;
    padding: 1rem;
  }

  .post-card {
    padding: 1rem;
  }
}

/* FFXIV page */
.ffxiv {
  min-width: 90vw;
  max-width: 90vw;

  .ffxiv-header {
    display: flex;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;

    .ffxiv-avatar {
      width: 64px;
      height: 64px;
      border-radius: 0.5rem;
      object-fit: cover;
      cursor: default;
    }

    .ffxiv-portrait {
      max-height: 400px;
      border-radius: 0.5rem;
      cursor: default;
    }

    .ffxiv-portrait-wrap {
      display: flex;
      gap: 0.5rem;
      align-items: flex-start;
      flex-shrink: 0;
    }

    .ffxiv-header-jobs {
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
      flex-shrink: 0;
      align-self: stretch;

      .ffxiv-job-group {
        display: grid;
        grid-template-columns: repeat(8, 1fr);
        gap: 0.3rem;
      }

      .ffxiv-job-group-label {
        grid-column: 1 / -1;
        font-size: 0.6rem;
        text-transform: uppercase;
        color: var(--fg-dim);
        letter-spacing: 0.05em;
        padding-bottom: 0.1rem;
      }

      .ffxiv-header-job {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.1rem;
        padding: 0.2rem;
        border-radius: 0.25rem;
        opacity: 0.5;

        &.ffxiv-job-max {
          opacity: 1;
        }
      }

      .ffxiv-header-job-icon {
        width: 28px;
        height: 28px;
        cursor: default;
      }

      .ffxiv-header-job-level {
        font-size: 0.65rem;
        font-variant-numeric: tabular-nums;
      }
    }

    .ffxiv-header-info {
      flex: 1;
      min-width: 0;

      h1 {
        margin: 0;
        font-size: 2rem;
      }

      .ffxiv-title {
        color: var(--fg-text-dim);
        font-style: italic;
        margin: 0;
      }

      .ffxiv-server {
        color: var(--fg-dim);
        font-size: 0.95rem;
        margin: 0.25rem 0 0 0;
      }
    }

    .ffxiv-header-details {
      display: flex;
      flex-direction: column;
      gap: 0.1rem;
      margin-top: 0.5rem;
      font-size: 0.85rem;
      color: var(--fg-dim);

      strong {
        color: var(--fg);
        margin-right: 0.25rem;
      }
    }

    .ffxiv-header-stats {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
      gap: 0.4rem;
      margin-top: 0.75rem;

      .ffxiv-stat {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0.35rem 0.5rem;
        border: 1px solid oklch(from var(--fg) calc(l - 0.40) c h);
        border-radius: 0.25rem;

        .ffxiv-stat-value {
          font-size: 1rem;
          font-weight: bold;
        }

        .ffxiv-stat-label {
          font-size: 0.7rem;
          color: var(--fg-dim);
        }
      }
    }
  }

  .ffxiv-bio {
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--highlight-subtle);
    border-radius: 0.5rem;
  }

  .ffxiv-section {
    margin-bottom: 2rem;

    h2 {
      color: var(--highlight);
      font-size: 1.3rem;
      margin-bottom: 1rem;
      padding-bottom: 0.5rem;
      border-bottom: 1px solid oklch(from var(--fg) calc(l - 0.40) c h);
    }
  }

  .ffxiv-jobs {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;

    .ffxiv-job {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.4rem 0.6rem;
      border: 1px solid oklch(from var(--fg) calc(l - 0.40) c h);
      border-radius: 0.25rem;

      &.ffxiv-job-max {
        border-color: var(--highlight);
        background: var(--highlight-subtle);
      }

      .ffxiv-job-icon {
        width: 24px;
        height: 24px;
        cursor: default;
      }

      .ffxiv-job-info {
        display: flex;
        justify-content: space-between;
        flex: 1;
        min-width: 0;
      }

      .ffxiv-job-name {
        font-size: 0.9rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .ffxiv-job-level {
        font-weight: 600;
        font-size: 0.9rem;
        margin-left: 0.5rem;
        flex-shrink: 0;
      }
    }
  }

  .ffxiv-collectibles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 0.4rem;

    .ffxiv-collectible {
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 0.25rem;
      border: 1px solid oklch(from var(--fg) calc(l - 0.40) c h);
      border-radius: 0.25rem;
      cursor: default;

      img {
        width: 40px;
        height: 40px;
        cursor: default;
      }

      .ffxiv-collectible-name {
        font-size: 0.65rem;
        text-align: center;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
        color: var(--fg-dim);
      }

      &.ffxiv-collectible-missing {
        .ffxiv-img-unobtained {
          opacity: 0.25;
          filter: grayscale(100%);
        }

        .ffxiv-collectible-name-missing {
          font-style: italic;
          color: var(--fg-dim);
        }
      }
    }
  }

  .ffxiv-collectible-count {
    color: var(--fg-dim);
    font-size: 0.9rem;
    margin: 0 0 0.75rem 0;
  }

  .ffxiv-summary-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
  }

  .ffxiv-summary-card {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid oklch(from var(--fg) calc(l - 0.30) c h / 0.3);
    border-radius: 6px;
    min-width: 140px;
  }

  .ffxiv-summary-label {
    font-size: 0.85rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ffxiv-summary-bar-wrap {
    width: 100%;
    height: 6px;
    background: oklch(from var(--fg) calc(l - 0.30) c h / 0.3);
    border-radius: 3px;
    overflow: hidden;
  }

  .ffxiv-summary-bar {
    height: 100%;
    background: var(--highlight);
    border-radius: 3px;
    min-width: 0;
    transition: width 0.3s ease;
  }

  .ffxiv-summary-count {
    font-size: 0.75rem;
    color: var(--fg-dim);
    font-variant-numeric: tabular-nums;
  }

  .ffxiv-subpage-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-bottom: 1px solid oklch(from var(--fg) calc(l - 0.30) c h / 0.3);
    margin-bottom: 1.5rem;
  }

  .ffxiv-subpage-link {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--fg-dim);
    font-size: 0.9rem;
    border-bottom: 2px solid transparent;
    transition: color 0.2s ease, border-color 0.2s ease;

    &:hover {
      color: var(--fg);
      border-bottom-color: var(--fg-dim);
    }
  }

  .ffxiv-subpage-active {
    color: var(--highlight);
    border-bottom-color: var(--highlight);
  }

  .ffxiv-subsection {
    margin-bottom: 1.5rem;

    summary {
      color: var(--fg);
      font-size: 1rem;
      margin: 0 0 0.5rem 0;
      cursor: pointer;
      list-style: none;
      display: flex;
      align-items: center;
      gap: 0.3rem;

      &::-webkit-details-marker {
        display: none;
      }

      &::before {
        content: '▸';
        display: inline-block;
        width: 1ch;
        font-size: 0.85rem;
        transition: transform 0.15s ease;
      }
    }

    &[open] summary::before {
      transform: rotate(90deg);
    }

    .ffxiv-exp-tag {
      font-size: 0.8rem;
      color: var(--fg-dim);
      font-weight: normal;
    }

    .ffxiv-progress-count {
      font-size: 0.8rem;
      color: var(--fg-dim);
      font-weight: normal;
      margin-left: 0.5rem;
    }
  }

  .ffxiv-checklist {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 0.25rem;

    .ffxiv-checklist-item {
      display: flex;
      align-items: center;
      gap: 0.4rem;
      padding: 0.2rem 0.4rem;
      border-radius: 0.2rem;
      font-size: 0.9rem;
      transition: background 0.2s;

      &:hover {
        background: var(--highlight-subtle);
      }

      .ffxiv-check-icon {
        flex-shrink: 0;
        width: 1em;
        text-align: center;
      }

      .ffxiv-check-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      &.ffxiv-done {
        .ffxiv-check-icon {
          color: oklch(0.7 0.15 140);
        }
        .ffxiv-check-name {
          color: var(--fg-text-very-dim);
          text-decoration: line-through;
        }
      }

      .ffxiv-not-done {
        color: var(--fg-text-dim);
      }

      .ffxiv-locked {
        opacity: 0.4;
      }
    }
  }

  .ffxiv-updated {
    font-size: 0.8rem;
    color: var(--fg-dim);
    margin: 1rem 0;
  }

  .ffxiv-refresh-form {
    margin: 1rem 0;
  }

  .ffxiv-refresh-btn {
    padding: 0.4rem 1rem;
    font-size: 0.8rem;
    cursor: pointer;
    background: none;
    border: 1px solid var(--fg-dim);
    color: var(--fg-dim);
    border-radius: 4px;
    transition: all 0.2s ease;
  }

  .ffxiv-refresh-btn:hover {
    color: var(--fg);
    border-color: var(--fg);
  }

  .ffxiv-loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    gap: 1rem;

    h1 {
      font-size: 1.5rem;
    }

    p {
      color: var(--fg-dim);
    }
  }

  .ffxiv-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid oklch(from var(--fg) calc(l - 0.40) c h);
    border-top-color: var(--highlight);
    border-radius: 50%;
    animation: ffxiv-spin 0.8s linear infinite;
  }
}

@keyframes ffxiv-spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 768px) {
  .ffxiv {
    .ffxiv-header {
      flex-direction: column;
      text-align: center;

      .ffxiv-portrait-wrap {
        justify-content: center;
      }

      .ffxiv-header-details {
        justify-content: center;
      }

      .ffxiv-header-stats {
        max-width: 100%;
      }
    }

    .ffxiv-jobs {
      grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    .ffxiv-collectibles {
      grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
    }
  }
}
