@import url("_reset.css");

/* Custom fonts */
@font-face {
  font-family: 'Mona Sans';
  src:
    url('../assets/fonts/Mona-Sans.woff2') format('woff2 supports variations'),
    url('../assets/fonts/Mona-Sans.woff2') format('woff2-variations');
  font-weight: 200 900;
  font-stretch: 75% 125%;
}

@font-face {
  font-family: 'Hubot Sans';
  src:
    url('../assets/fonts/Hubot-Sans.woff2') format('woff2 supports variations'),
    url('../assets/fonts/Hubot-Sans.woff2') format('woff2-variations');
  font-weight: 200 900;
  font-stretch: 75% 125%;
  font-variant-alternates: historical-forms;
}

/* CSS Variables for theming */
:root {
  --bg-primary: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #252525;
  --bg-hover: #2a2a2a;
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-muted: rgba(255, 255, 255, 0.5);
  --accent-primary: #894bb8;
  --accent-secondary: #a066cc;
  --accent-success: #22c55e;
  --accent-warning: #f59e0b;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --header-height: 4rem;
  --banner-height: 2.2rem;
}

/* Base styles */
html {
  background: var(--bg-primary);
  color: var(--text-primary);
  scroll-behavior: smooth;
}

body {
  background: var(--bg-secondary);
  background-image: linear-gradient(
    180deg,
    hsl(0deg 0% 11%) 0%,
    hsl(0deg 0% 9%) 50%,
    hsl(0deg 0% 6%) 100%
  );
  background-attachment: fixed;
  font-family: 'Mona Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  max-width: 1400px;
  margin: auto;
  border-left: solid 1px var(--border-subtle);
  border-right: solid 1px var(--border-subtle);
  min-height: 100vh;
}

.wrapper {
  padding: 0 clamp(16px, 3vw, 24px);
}

/* Header */
header {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  height: 4rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-bottom: solid 1px var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;

  & .wrapper {
    flex: 1 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 2rem;

    & nav {
      display: flex;
      align-items: center;
      gap: 0.5rem;

      @media (max-width: 500px) {
        display: none;
      }

      & a {
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 1.2rem;
        transition: var(--transition-fast);
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        border-radius: var(--radius-sm);

        &:hover {
          color: var(--text-primary);
          background: var(--bg-hover);
        }

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

        & .material-symbols-outlined {
          font-size: 1.4rem;
        }
      }
    }
  }

  & h1 {
    color: var(--text-primary);
    font-size: 1.2rem;
    margin: 0;
    line-height: 1;
    font-weight: 300;

    & strong {
      font-weight: 800;
      background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }
  }
}

/* Announcement banner */
.announcement-banner {
  background: linear-gradient(90deg, var(--accent-primary), #c084fc, var(--accent-primary));
  background-size: 200% 100%;
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  overflow: hidden;
  position: relative;

  @media (max-width: 850px) {
    font-size: 0.55rem;
  }

  &.hidden {
    display: none;
  }
}

/* When banner is hidden, reset the banner height variable */
body:has(.announcement-banner.hidden) {
  --banner-height: 0rem;
}

.announcement-banner {
  & .banner-content {
    display: flex;
    animation: marquee 25s linear infinite;
    white-space: nowrap;
  }

  & .banner-text {
    padding: 0.6rem 3rem;
    
    @media (max-width: 850px) {
      padding: 0.3rem 1rem;
    }
    
    & .sep {
      margin: 0 0.5em;
      opacity: 0.4;
      font-weight: 300;
    }
  }

  & .banner-dismiss {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    padding: 0 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);

    &:hover {
      background: rgba(0, 0, 0, 0.4);
    }

    & .material-symbols-outlined {
      font-size: 1.2rem;
    }
  }
}

@keyframes marquee {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

/* Main layout */
main {
  display: flex;
  min-height: calc(100vh - var(--header-height) - var(--banner-height));

  @media (max-width: 850px) {
    flex-direction: column-reverse;
    min-height: auto;
  }

  & section {
    @media (max-width: 850px) {
      height: auto;
    }

    &&#controls {
      width: 380px;
      flex-shrink: 0;
      border-right: solid 1px var(--border-subtle);
      display: flex;
      flex-direction: column;

      @media (max-width: 850px) {
        width: 100%;
        border-right: none;
      }
    }

    &&#preview {
      flex: 1;
      border-left: solid 1px rgba(0, 0, 0, 0.4);

      @media (max-width: 850px) {
        padding: 60px 0;
        border-bottom: solid 1px var(--border-medium);
      }
    }
  }
}

/* Controls section */
#controls {
  font-family: 'Hubot Sans', 'Mona Sans', sans-serif;
  overflow-y: auto;
  max-height: calc(100vh - var(--header-height) - var(--banner-height));

  @media (max-width: 850px) {
    max-height: none;
  }

  & .controls-tabs {
    flex: 1;
  }

  /* Accordion details - redesigned for clarity */
  & details {
    border-bottom: none;
    margin-bottom: 0;

    & summary {
      padding: 0.9rem 1.25rem;
      font-weight: 600;
      font-size: 0.9rem;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 0.75rem;
      transition: var(--transition-fast);
      user-select: none;
      color: var(--text-secondary);
      background: var(--bg-primary);
      border-bottom: 1px solid var(--border-subtle);
      text-transform: uppercase;
      letter-spacing: 0.03em;

      &:hover {
        background: var(--bg-secondary);
        color: var(--text-primary);
      }

      & .material-symbols-outlined {
        font-size: 1.2rem;
        color: var(--accent-primary);
      }

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

      &::after {
        content: '';
        margin-left: auto;
        width: 8px;
        height: 8px;
        border-right: 2px solid currentColor;
        border-bottom: 2px solid currentColor;
        transform: rotate(-45deg);
        transition: var(--transition-fast);
        opacity: 0.5;
      }
    }

    &[open] summary {
      color: var(--text-primary);
      background: var(--bg-tertiary);
      border-bottom: none;

      &::after {
        transform: rotate(45deg);
      }
    }
  }

  /* Control groups */
  & .control-group {
    padding: 1rem 1.25rem 1.25rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
  }

  & .control-row {
    margin-bottom: 1rem;

    &:last-child {
      margin-bottom: 0;
    }
  }

  & .control-row-inline {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;

    &:last-child {
      margin-bottom: 0;
    }

    & .control-col {
      flex: 1;
    }
  }

  /* Labels */
  & label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);

    & .material-symbols-outlined {
      font-size: 1.1rem;
      opacity: 0.6;
    }
  }

  /* Inputs */
  & input[type="text"],
  & input[type="url"],
  & input[type="search"] {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition-fast);

    &::placeholder {
      color: var(--text-muted);
    }

    &:focus {
      outline: none;
      border-color: var(--accent-primary);
      box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
    }
  }

  & input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    cursor: pointer;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;

    &::-webkit-color-swatch-wrapper {
      padding: 2px;
    }

    &::-webkit-color-swatch {
      border-radius: 4px;
      border: none;
    }

    &::-moz-color-swatch {
      border-radius: 4px;
      border: none;
    }
  }

  & input[type="range"] {
    width: 100%;
    height: 6px;
    background: var(--border-medium);
    border-radius: 3px;
    -webkit-appearance: none;
    appearance: none;
    margin: 0.5rem 0;

    &::-webkit-slider-thumb {
      -webkit-appearance: none;
      width: 18px;
      height: 18px;
      background: var(--accent-primary);
      border-radius: 50%;
      cursor: pointer;
      transition: var(--transition-fast);
      box-shadow: var(--shadow-sm);
    }

    &::-webkit-slider-thumb:hover {
      transform: scale(1.1);
      background: var(--accent-secondary);
    }

    &::-moz-range-thumb {
      width: 18px;
      height: 18px;
      background: var(--accent-primary);
      border-radius: 50%;
      cursor: pointer;
      border: none;
    }
  }

  & .range-value {
    display: inline-block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: 0.5rem;
    min-width: 40px;
  }

  & input[type="file"] {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border: 1px dashed var(--border-medium);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition-fast);

    &:hover {
      border-color: var(--accent-primary);
      background: rgba(124, 58, 237, 0.1);
    }

    &::file-selector-button {
      padding: 0.4rem 0.8rem;
      margin-right: 0.75rem;
      background: var(--accent-primary);
      border: none;
      border-radius: 4px;
      color: white;
      font-size: 0.8rem;
      font-weight: 500;
      cursor: pointer;
      transition: var(--transition-fast);
    }

    &::file-selector-button:hover {
      background: var(--accent-secondary);
    }
  }

  & .input-hint {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.4rem;

    & .material-symbols-outlined {
      font-size: 0.9rem;
    }

    &.privacy-hint {
      display: flex;
      align-items: center;
      gap: 0.35rem;
      color: var(--accent-success);
      opacity: 0.8;
      margin-top: 0.5rem;

      & .material-symbols-outlined {
        font-size: 0.9rem;
      }
    }
  }

  & .helper-link {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--accent-secondary);
    margin-top: 0.75rem;
    text-decoration: none;
    transition: var(--transition-fast);

    & .material-symbols-outlined {
      font-size: 1rem;
    }

    &:hover {
      color: var(--text-primary);
    }
  }

  /* Choices.js overrides */
  & .choices__inner {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-medium) !important;
    border-radius: var(--radius-sm) !important;
    min-height: 40px !important;
    padding: 4px 8px !important;
    font-size: 0.9rem !important;
  }

  & .choices__list--single {
    padding: 4px 0 !important;
  }

  & .choices__list--dropdown,
  & .choices__list[aria-expanded] {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-medium) !important;
    border-radius: var(--radius-sm) !important;
    margin-top: 4px !important;

    /* More visible scrollbar for dropdowns (targeting the inner list) */
    & .choices__list {
      &::-webkit-scrollbar {
        width: 12px;
        background: var(--bg-primary);
      }

      &::-webkit-scrollbar-track {
        background: var(--bg-primary) !important;
        border-left: 1px solid var(--border-subtle);
      }

      &::-webkit-scrollbar-thumb {
        background: var(--text-muted) !important;
        border: 3px solid var(--bg-primary);
        border-radius: 10px;

        &:hover {
          background: var(--text-secondary) !important;
        }
      }
    }
  }

  & .choices__item {
    color: var(--text-primary) !important;
  }

  & .choices__item--selectable.is-highlighted {
    background: var(--accent-primary) !important;
  }

  & .choices__input {
    background: transparent !important;
    color: var(--text-primary) !important;
  }

  & .choices__placeholder {
    color: var(--text-muted) !important;
  }

  & .choices__list--dropdown .choices__item--selectable {
    padding: 8px 12px !important;
  }

  & .choices__group .choices__heading {
    font-weight: 600 !important;
    font-size: 0.75rem !important;
    color: var(--text-muted) !important;
    border-bottom: 1px solid var(--border-subtle) !important;
    padding: 8px 12px !important;
  }

  /* Sub-details (Advanced options) */
  & .sub-details {
    margin-top: 1rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-medium);

    & summary {
      padding: 0.65rem 1rem;
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--text-muted);
      text-transform: uppercase;
      letter-spacing: 0.04em;
      background: rgba(0, 0, 0, 0.15);
      border-bottom: 1px solid transparent;
      border-radius: var(--radius-md);
      box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.02);

      & .material-symbols-outlined {
        font-size: 1rem;
        color: var(--accent-primary);
        opacity: 0.8;
      }

      &:hover {
        background: rgba(0, 0, 0, 0.25);
        color: var(--text-secondary);

        & .material-symbols-outlined {
          opacity: 1;
        }
      }

      &::after {
        width: 6px;
        height: 6px;
        opacity: 0.6;
      }
    }

    &[open] summary {
      border-bottom: 1px solid var(--border-subtle);
      color: var(--text-secondary);
      background: rgba(0, 0, 0, 0.25);
      border-radius: var(--radius-md) var(--radius-md) 0 0;

      & .material-symbols-outlined {
        opacity: 1;
      }
    }

    & .sub-control-group {
      padding: 1rem;
      background: rgba(0, 0, 0, 0.14);
      border-top: 1px solid var(--border-subtle);

      &:last-child {
        border-radius: 0 0 var(--radius-md) var(--radius-md);
      }
    }
  }

  /* Icon picker */
  & .icon-picker {
    background: rgba(0, 0, 0, 0.3);
    padding: 1rem;
    border-top: 1px solid var(--border-subtle);
  }

  & .icon-search-container {
    position: relative;
    margin-bottom: 0.75rem;

    & .search-icon {
      position: absolute;
      left: 10px;
      top: 50%;
      transform: translateY(-50%);
      font-size: 1.2rem;
      color: var(--text-muted);
      pointer-events: none;
    }

    & input[type="search"] {
      padding-left: 2.5rem;
    }
  }

  & .icon-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-subtle);

    & .category-btn {
      padding: 0.35rem 0.65rem;
      background: var(--bg-secondary);
      border: 1px solid var(--border-subtle);
      border-radius: 20px;
      color: var(--text-muted);
      font-size: 0.7rem;
      font-weight: 500;
      cursor: pointer;
      transition: var(--transition-fast);

      &:hover {
        border-color: var(--accent-primary);
        color: var(--text-secondary);
      }

      &.active {
        background: var(--accent-primary);
        border-color: var(--accent-primary);
        color: white;
      }
    }
  }

  & .icon-grid-wrapper {
    max-height: 280px;
    overflow-y: auto;
    overflow-x: hidden;

    &::-webkit-scrollbar {
      width: 6px;
    }

    &::-webkit-scrollbar-track {
      background: var(--bg-secondary);
      border-radius: 3px;
    }

    &::-webkit-scrollbar-thumb {
      background: var(--border-medium);
      border-radius: 3px;
    }
  }

  & .icon-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
    padding: 4px;

    & .icon {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      aspect-ratio: 1 / 1;
      min-height: 0;
      background: var(--bg-secondary);
      border: 1px solid var(--border-subtle);
      border-radius: var(--radius-sm);
      color: var(--text-secondary);
      font-size: 1.5rem;
      cursor: pointer;
      transition: var(--transition-fast);
      overflow: hidden;

      & .material-symbols-outlined {
        font-size: 1.5rem;
        line-height: 1;
      }

      &:hover {
        background: var(--bg-hover);
        border-color: var(--accent-primary);
        color: var(--text-primary);
        transform: scale(1.05);
      }

      &.selected {
        background: var(--accent-primary);
        border-color: var(--accent-primary);
        color: white;
      }
    }

    & .icon-loading {
      grid-column: 1 / -1;
      text-align: center;
      padding: 2rem;
      color: var(--text-muted);
    }
  }

  & .icon-attribution {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-subtle);

    & a {
      color: var(--accent-secondary);
      text-decoration: none;

      &:hover {
        text-decoration: underline;
      }
    }
  }

  /* Hide icon option groups based on type */
  & .charIconOptions,
  & .uploadIconOptions,
  & .mdIconOptions {
    display: none;
  }

  /* Add margin only to specific icon control rows, not the picker */
  & .icon-colour-row {
    margin-top: 1rem;
  }

  /* Icon picker should not have top margin */
  & .icon-picker {
    margin-top: 0;
  }
}

/* Download section */
.download-section {
  padding: 1rem 1.25rem 1.25rem;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-medium);

  & .export-size-row {
    margin-bottom: 1rem;
  }

  & .btn-primary {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.9rem 1.5rem;
    background: linear-gradient(135deg, var(--accent-success), #16a34a);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition-normal);
    box-shadow: var(--shadow-md);

    & .material-symbols-outlined {
      font-size: 1.3rem;
    }

    &:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-lg);
      background: linear-gradient(135deg, #22d05e, #22c55e);
    }

    &:active {
      transform: translateY(0);
    }
  }

  & .gif-note {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.3);
    border-radius: var(--radius-sm);
    color: var(--accent-warning);
    font-size: 0.8rem;

    & .material-symbols-outlined {
      font-size: 1.2rem;
    }
  }

  & .export-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;

    & .material-symbols-outlined {
      font-size: 1rem;
      opacity: 0.7;
    }
  }

  & .tip-jar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.9rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--accent-primary);
    color: #fff;
    font-size: 0.9rem;
    font-weight: 650;
    text-decoration: none;
    border-radius: var(--radius-md);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
    transition: var(--transition-fast);

    & .material-symbols-outlined {
      font-size: 1.1rem;
    }

    &:hover {
      background: var(--accent-secondary);
      color: #fff;
    }
  }
}

/* Preview section */
#preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
  background-image: url('../assets/tile-background.png');
  background-position: center center;
  background-size: 1080px 1080px;
  position: relative;
  min-height: 400px;

  @media (max-width: 900px) {
    background-size: 720px 720px;
  }

  & .preview-dots {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.01;
  }

  /* Reset button (legacy - keeping for backwards compat) */
  & .reset-btn {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.4);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    pointer-events: auto;
    z-index: 10;

    & .material-symbols-outlined {
      font-size: 20px;
    }

    &:hover {
      background: rgba(255, 255, 255, 0.15);
      color: rgba(255, 255, 255, 0.8);
      border-color: rgba(255, 255, 255, 0.2);
    }
  }

  /* Preview action buttons (link + reset) */
  & .preview-actions {
    position: absolute;
    bottom: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    pointer-events: auto;
    z-index: 10;
  }

  & .preview-action-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.4);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    position: relative;

    & .material-symbols-outlined {
      font-size: 20px;
    }

    &:hover {
      background: rgba(255, 255, 255, 0.15);
      color: rgba(255, 255, 255, 0.8);
      border-color: rgba(255, 255, 255, 0.2);
    }

    &:hover .tooltip {
      opacity: 1;
      visibility: visible;
      transform: translateX(-50%) translateY(0);
    }

    &.copied {
      background: var(--accent-success);
      border-color: var(--accent-success);
      color: #fff;
    }

    & .tooltip {
      position: absolute;
      bottom: calc(100% + 8px);
      left: 50%;
      transform: translateX(-50%) translateY(4px);
      background: var(--bg-primary);
      color: var(--text-primary);
      padding: 6px 10px;
      border-radius: 6px;
      font-size: 12px;
      font-weight: 500;
      white-space: nowrap;
      opacity: 0;
      visibility: hidden;
      transition: all 0.15s ease;
      pointer-events: none;
      border: 1px solid var(--border-medium);
      box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
      z-index: 100;

      &::after {
        content: '';
        position: absolute;
        top: 100%;
        left: 50%;
        transform: translateX(-50%);
        border: 6px solid transparent;
        border-top-color: var(--border-medium);
      }
    }
  }

  & #preview-button-container {
    transform: scale(1.4);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
    border-radius: 15%;

    @media (max-width: 900px) {
      transform: scale(1);
    }
  }

  & #preview-button {
    background: transparent;
    width: 244px;
    height: 244px;
    font-size: 50px;
    text-align: center;
    line-height: 1;
    font-weight: bold;
    letter-spacing: -1px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;

    & #buttonBackground {
      position: absolute;
      background: #94008F;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: 15%;
      border-color: transparent;
      border-width: 0px;
      border-style: solid;
      background-size: cover;
      background-position: center center;
    }

    & #backgroundDarkOverlay {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      border-radius: 15%;
      background: #000;
      opacity: 0;
      pointer-events: none;
      z-index: 1;
    }

    & #textPreview {
      align-self: flex-end;
      text-align: center;
      width: 100%;
      word-break: break-word;
      line-height: 0.9;
      padding: 3% 6%;
      position: relative;
      z-index: 10;
      white-space: pre-line;

      &:empty {
        display: none;
      }
    }

    & #buttonOverlay {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      object-fit: cover;
      object-position: center center;
      mix-blend-mode: overlay;
      z-index: 100;
      display: block;
      border-radius: 15%;
    }

    /* Status badge indicator */
    & .status-badge {
      position: absolute;
      width: 20px;
      height: 20px;
      border-radius: 50%;
      z-index: 200;
      pointer-events: none;
      border: 2px solid rgba(255, 255, 255, 0.9);
    }

    & #buttonIcon {
      top: 0;
      position: relative;
      left: 0;
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      line-height: 0.9;
      font-family: 'Hubot Sans', sans-serif;
      z-index: 5;

      & img {
        height: 100%;
        width: auto;
        max-width: 100%;
      }

      & object {
        height: 100%;
        width: auto;
        max-width: 100%;
        margin-bottom: -10px;
      }

      & #buttonIconInner {
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }
    }

    & .char-text {
      margin-top: 0.1em;
      margin-bottom: -0.1em;
    }
  }
}

/* Article/Footer content */
article {
  @media (min-width: 800px) {
    column-count: 2;
    column-gap: 2rem;
  }

  padding: clamp(20px, 3vw, 40px);
  border-top: solid 1px var(--border-medium);
  background: var(--bg-tertiary);

  & img {
    width: 100%;
    border-radius: var(--radius-md);
    max-width: 500px;
    margin: 1em 0;
  }

  & h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text-primary);
  }

  & h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
  }

  & p {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.6;
  }

  & ul {
    color: var(--text-secondary);
    margin-left: 0;
    padding-left: 1.1rem;
    margin-bottom: 1.25rem;

    & li {
      margin-bottom: 0.55rem;
    }
  }

  & a {
    color: var(--accent-secondary);
    text-decoration: none;
    transition: var(--transition-fast);

    &:hover {
      color: var(--text-primary);
      text-decoration: underline;
    }
  }
}

/* Utility: Scrollbar styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 4px;

  &:hover {
    background: var(--text-muted);
  }
}

/* Background options visibility */
#backgroundGradientOptions,
#backgroundImageOptions {
  display: none;
}

/* Ko-fi widget - remove black background */
.floatingchat-container,
.floatingchat-container-wrap,
.floatingchat-container-wrap-mo498,
[id^="kofi-widget"],
[class*="floatingchat"],
[class*="floating-chat"] {
  background: transparent !important;
  background-color: transparent !important;
  
  &,
  & > *,
  & iframe {
    background: transparent !important;
    background-color: transparent !important;
  }
}

/* PWA Install Prompt */
.pwa-install-prompt {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 420px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  animation: slideUp 0.3s ease;

  @media (max-width: 500px) {
    flex-direction: column;
    align-items: stretch;
    left: 10px;
    right: 10px;
    transform: none;
    bottom: 10px;
  }

  &.hidden {
    display: none;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.pwa-install-content {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex: 1;
}

.pwa-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.pwa-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;

  & strong {
    font-size: 0.9rem;
    color: var(--text-primary);
    line-height: 1.2;
  }

  & span {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.3;
  }
}

.pwa-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;

  @media (max-width: 500px) {
    justify-content: flex-end;
  }
}

.pwa-install-btn {
  padding: 0.5rem 1rem;
  background: var(--accent-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;

  &:hover {
    background: var(--accent-secondary);
  }
}

.pwa-dismiss-btn {
  width: 36px;
  height: 36px;
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
  flex-shrink: 0;

  & .material-symbols-outlined {
    font-size: 1.1rem;
  }

  &:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border-color: var(--border-medium);
  }
}

/* PWA Footer Banner */
.pwa-footer-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1rem 1.5rem;
  background: linear-gradient(135deg, rgba(137, 75, 184, 0.15), rgba(160, 102, 204, 0.1));
  border-top: 1px solid var(--border-medium);

  &.hidden {
    display: none;
  }

  @media (max-width: 600px) {
    flex-direction: column;
    gap: 0.75rem;
    text-align: center;
  }
}

.pwa-footer-content {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-secondary);
  font-size: 0.9rem;

  & .material-symbols-outlined {
    font-size: 1.4rem;
    color: var(--accent-primary);
  }

  & strong {
    color: var(--text-primary);
  }

  @media (max-width: 600px) {
    flex-direction: column;
    gap: 0.4rem;
  }
}

.pwa-footer-install-btn {
  padding: 0.5rem 1.2rem;
  background: var(--accent-primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;

  &:hover {
    background: var(--accent-secondary);
  }
}

/* Templates Feature */
.templates-section {
  margin: -1rem;
  margin-top: 0;
  position: relative;
  
  &::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(to top, rgba(0,0,0,0.3), transparent);
    pointer-events: none;
  }
  
  &:first-child {
    margin-top: -1rem;
  }
}

.templates-section-inner {
  max-height: 280px;
  overflow: auto;
  padding: 1rem;
}

.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.75rem;
}

.template-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: var(--transition-fast);
  cursor: pointer;
  position: relative;

  &:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
  }
}

.template-card-preview {
  height: 80px;
  padding: 0.5rem;
  background: repeating-conic-gradient(#1a1a1a 0% 25%, #252525 0% 50%) 50% / 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  overflow: hidden;
}

.template-card-info {
  padding: 0.5rem;
  border-top: 1px solid var(--border-subtle);
}

.template-card-name {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-card-meta {
  font-size: 0.6rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.2rem;
}

.template-card-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.35rem;
  opacity: 1;
  transition: var(--transition-fast);
  z-index: 50;
}

.template-action-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);

  & .material-symbols-outlined {
    font-size: 1rem;
  }

  &:hover {
    background: var(--accent-primary);
  }

  &.copied {
    background: var(--accent-success);
  }

  &.delete:hover {
    background: #ef4444;
  }
}

/* Global tooltip - appended to body, never clipped */
.global-tooltip {
  position: fixed;
  transform: translate(-50%, -100%);
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  border: 1px solid var(--border-medium);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  z-index: 10000;
  transition: opacity 0.15s ease;

  &.visible {
    opacity: 1;
  }
}

.preview-placeholder {
  width: 60px;
  height: 60px;
  border-radius: 15%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  flex-shrink: 0;
}

.template-count {
  background: var(--accent-primary);
  color: #fff;
  font-size: 0.6rem;
  font-weight: 600;
  min-width: 1.1rem;
  height: 1.1rem;
  line-height: 1.1rem;
  text-align: center;
  padding: 0 0.35rem;
  border-radius: 10px;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.no-templates {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.storage-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.4;

  & .material-symbols-outlined {
    font-size: 1rem;
    color: var(--accent-warning);
    flex-shrink: 0;
  }
}

/* Template save section (top buttons) */
.template-save-section {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.btn-save-template {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1rem;
  height: 42px;
  background: var(--accent-primary);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);

  & .material-symbols-outlined {
    font-size: 1.2rem;
  }

  &:hover {
    background: var(--accent-secondary);
    border-color: var(--accent-secondary);
  }
}

.btn-permalink {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  flex-shrink: 0;

  & .material-symbols-outlined {
    font-size: 1.2rem;
  }

  &:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--text-primary);
  }

  &.copied {
    background: var(--accent-success);
    border-color: var(--accent-success);
    color: #fff;
  }
}

.template-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.template-btn {
  flex: 1;
  min-width: 120px;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: var(--transition-fast);

  & .material-symbols-outlined {
    font-size: 1.1rem;
  }

  &:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
  }

  &.primary {
    background: var(--accent-primary);
    border-color: var(--accent-primary);

    &:hover {
      background: var(--accent-secondary);
    }
  }

  &.copied {
    background: var(--accent-success);
    border-color: var(--accent-success);
  }
}

/* Save Template Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  visibility: visible;
  transition: var(--transition-normal);

  &.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
  }
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 90%;
  max-width: 400px;
  transform: scale(1);
  transition: var(--transition-normal);
}

.modal-overlay.hidden .modal-content {
  transform: scale(0.95);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;

  & h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;

    & .material-symbols-outlined {
      color: var(--accent-primary);
    }
  }
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  transition: var(--transition-fast);

  &:hover {
    color: var(--text-primary);
  }
}

.modal-body {
  & label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
  }

  & input[type="text"] {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: var(--transition-fast);

    &:focus {
      outline: none;
      border-color: var(--accent-primary);
    }
  }
}

.modal-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  margin-top: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  line-height: 1.4;

  & .material-symbols-outlined {
    font-size: 1rem;
    color: var(--accent-warning);
    flex-shrink: 0;
  }

  &.hidden {
    display: none;
  }
}

.modal-footer {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}

.modal-btn {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);

  &.secondary {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    color: var(--text-primary);

    &:hover {
      background: var(--bg-hover);
    }
  }

  &.primary {
    background: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    color: #fff;

    &:hover {
      background: var(--accent-secondary);
    }
  }
}

/* Modal button variants (alternative class names) */
.btn-secondary {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);

  &:hover {
    background: var(--bg-hover);
  }
}

.btn-primary-modal {
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition-fast);
  background: var(--accent-primary);
  border: 1px solid var(--accent-primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.4rem;

  & .material-symbols-outlined {
    font-size: 1.1rem;
  }

  &:hover {
    background: var(--accent-secondary);
  }
}

/* Custom image warning in modal */
.custom-image-warning {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  margin-top: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.4;

  & .material-symbols-outlined {
    font-size: 1.5rem;
    color: var(--accent-warning);
    flex-shrink: 0;
  }

  & strong {
    display: block;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
  }

  & p {
    margin: 0;
  }

  &.hidden {
    display: none;
  }
}

.template-notification {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-secondary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  padding: 0.8rem 1.2rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  opacity: 0;
  transition: var(--transition-normal);
  max-width: 90%;

  &.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }

  &.warning {
    border-color: rgba(245, 158, 11, 0.5);
    background: rgba(30, 25, 15, 0.95);
  }

  & .material-symbols-outlined {
    font-size: 1.2rem;
    color: var(--accent-success);
  }

  &.warning .material-symbols-outlined {
    color: var(--accent-warning);
  }
}
