:root{
      /* Global border radius used across cards, buttons, and containers */
      --radius: 12px;

      /* Maximum content width for centered layouts */
      --maxw: 1200px;

      /* Responsive font sizes for headings and base text */
      --fs-h1: clamp(1.5rem, 2.5vw, 2.25rem);
      --fs-h2: clamp(1rem, 1.4vw, 1.15rem);
      --fs-base: clamp(.95rem, 1.1vw, 1rem);

      /* Focus ring dimensions for accessibility */
      --focus-width: 3px;
      --focus-offset: 3px;

      /* Core dark theme colors */
      --bg: #0f1115;
      --bg-light: #171c27;
      --card: #151923;
      --border: #2a2f3a;
      --text: #f0f0f0;
      --muted: #e9e9e9;
      --shadow: 0 2px 8px rgba(0,0,0,.5);
      --shadow-lg: 0 6px 16px rgba(0,0,0,.6);

      /* Focus and button emphasis colors */
      --focus-color: #3b86f6;
      --button-focused: #273548;
      --focus-bg: rgba(59,130,246,0.18);
      --selected: #37d177;

      /* Green accent colors for "selfmade" states */
      --selfmade: #22c55e;
      --selfmade-text: #000000;
      --selfmade-hover: #1a8a43;

      /* Translucent overlay used for headers and overlays */
      --header: rgba(0,0,0,.72);

      /* Danger color palette */
      --danger: #b91717;
      --danger-dark: rgba(239, 68, 68, 0.12);
      --danger-light: #fecaca;

      /* Neutral overlay shades */
      --grey: rgba(0,0,0,.55);
      --dark-grey: rgba(0,0,0,.7);
      --light-grey: rgba(255,255,255,.06);
    }
    
    /* Include padding and border in the element's total width and height */
    * { box-sizing: border-box; }

    /* Remove the default tap highlight on touch devices */
    * {
      -webkit-tap-highlight-color: transparent;
    }

    body {
      /* System font stack for good cross-platform rendering */
      font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;

      /* Base page colors */
      background: var(--bg);
      color: var(--text);

      /* Remove default browser margin */
      margin: 0;

      /* Background */
      background: var(--bg); 
      position: relative;
    }

    /* Decorative svg background layer (Makerlab logo) */
    body::before{
      content:"";
      position:fixed;
      inset:0;
      background:url("/static/gallery/background.svg") top center / 120vw repeat-y;
      opacity:.75;
      pointer-events:none;
      z-index:-1;
    }

    /* Light mode overrides */
    @media (prefers-color-scheme: light) {
      :root{
      /* Base light theme colors */
      --bg: #ffffff; 
      --bg-light: #b4dce4;            
      --card: #f1f1f1;          
      --border: #8d9db1;        

      /* Text colors in light mode */
      --text: #000000;         
      --muted: #202122;        

      /* Softer shadows for light backgrounds */
      --shadow: 0 2px 8px rgba(0,0,0,.08);
      --shadow-lg: 0 6px 16px rgba(0,0,0,.12);

      /* Focus colors adapted for light mode */
      --focus-color: #f3388f;   
      --button-focused: #e2bce0;
      --focus-bg: #ffbce5;
      --selected: #ffb95e;

      /* Danger palette stays consistent */
      --danger: #dc2626;
      --danger-dark: rgba(239, 68, 68, 0.12);
      --danger-light: #fecaca;

      /* Green accent colors adjusted for light mode */
      --selfmade: #006326;
      --selfmade-text: #ffffff;
      --selfmade-hover: #00411098;

      /* Lighter translucent header overlay */
      --header: rgba(255,255,255,.85);

      /* Neutral overlay colors for light mode */
      --grey: rgba(0,0,0,.08);
      --dark-grey: rgba(0,0,0,.18);
      --light-grey: rgba(104, 103, 103, 0.05);
      }

      /* Replace background image in light mode */
      body::before{
        background: url("/static/gallery/background_light.svg") center / cover no-repeat;
      }
    }

    /* Page wrap to keep footer on bottom */
    .page {
      min-height: 100vh;
      display: flex;
      flex-direction: column;
    }

    .page-main {
      flex: 1;
    }

    /* Main page heading */
    h1 {
      text-align: center;
      margin: 28px 0 8px;
      font-size: var(--fs-h1);
      line-height: 1.15;
    }

    /* Secondary heading */
    h2 {
      text-align: center;
      margin: 24px 0 8px;
      font-size: var(--fs-h2);
      line-height: 1.15;
    }

    /* Subtitle or supporting text under headings */
    .sub{
      text-align:center;
      color:var(--text);
      margin: 0 0 18px;
      font-size: var(--fs-base);
    }

    /* --- Grid with cards --- */

    /* Card grid with fixed maximum card width */
    .artifact-grid {
      list-style: none;
      padding: 0;
      margin: 18px 0 40px;
      display: grid;

      /* Never wider than 320px per card, but still responsive */
      grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 320px));
      gap: clamp(12px, 2.2vw, 20px);

      /* Center cards when there are only one or two items */
      justify-content: center;
    }

    /* Single-column layout on very small screens */
    @media (max-width: 480px){
      .artifact-grid { grid-template-columns: 1fr; }
    }

    /* Generic grid item reset */
    .card-item {
      background: transparent;
      padding: 0;
      border-radius: 0;
      box-shadow: none;
    }

    /* Clickable card container */
    .card-link {
      background: var(--card);
      padding: 4px clamp(12px, 2vw, 16px) clamp(12px, 2vw, 16px);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      transition: transform .2s, box-shadow .2s;
      display: flex;
      flex-direction: column;
      text-decoration: none;
      color: inherit;
      cursor: pointer;
    }

    /* Lift card on hover */
    .card-link:hover {
      transform: translateY(-4px);
      box-shadow: var(--shadow-lg);
    }

    /* Card title */
    .card-title {
      margin: 2px 0 8px;
      font-size: var(--fs-h2);
      color: var(--text);
    }

    /* Card body text */
    .card-text {
      margin: 0;
      color: var(--muted);
      font-size: var(--fs-base);
    }

    /* Heading inside linked cards */
    .card-link h2 {
      margin: 2px 0 8px;
      font-size: var(--fs-h2);
      color: var(--text);
    }

    /* Paragraph inside linked cards */
    .card-link p {
      margin: 0;
      color: var(--muted);
      font-size: var(--fs-base);
    }

    @media (max-width:560px) {
      /* Stack title row content vertically on smaller screens */
      .title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
      }
    }

     /* --- Alternative card design --- */

    .card-alternative-wrap{
      max-width: 320px;
      width: 100%;
      justify-self: center;
      display: grid;
      grid-template-rows: auto auto; 
      gap: 10px;
    }

    /* Alternative card layout with fixed image row and flexible content row */
    .card-alternative {
      display: grid;
      grid-template-rows: 160px auto;
      background: var(--card);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      overflow: hidden;
      transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
      border: 2px solid transparent;
      min-width: 0;
      text-decoration: none;
    }

    /* Selected state for alternative cards */
    .card-alternative.selected {
      border-color: var(--selected);
      background: var(--border);
      box-shadow: 
        0 0 0 3px var(--selected),
        0 10px 25px var(--dark-grey);
      transform: scale(1.02);
    }

    /* Custom visible focus style when a focus-visible child exists */
    .card-alternative:focus-within:has(:focus-visible){     
      outline: 3px solid var(--focus-color);
      outline-offset: 3px;
    }

    /* Image area inside alternative cards */
    .card-alternative-thumb {
      background: var(--card);
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
    }

    /* Thumbnail image inside the alternative card */
    .card-alternative-thumb img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    /* Meta section inside the alternative card */
    .card-alternative-meta {
      padding: 12px 12px 14px;
      display: grid;
      gap: 8px;
      text-decoration: none;
    }

    /* Title styling in the alternative card */
    .card-alternative-title {
      margin: 0;
      font-weight: 800;
      font-size: 1rem;
      line-height: 1.25;
      color: var(--text);
      text-decoration: none;
    }

    /* Secondary/meta text styling */
    .card-alternative-meta .muted {
      color: var(--muted);
      font-size: .92rem;
      line-height: 1.35;
      text-decoration: none;
    }

    /* Ensure nested spans stack vertically */
    .card-alternative-meta .muted span {
      display: block;
    }

    /* Utility class to align content at the end of a row */
    .card-alternative--row-end { display: flex; justify-content: flex-end; }

    @media (max-width:560px) {
      /* Stack title row content vertically on smaller screens */
      .title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
      }
    }

    /* --- Card container for forms --- */

    .card {
      background: var(--card);
      border-radius: var(--radius);
      box-shadow: var(--shadow);
      padding: clamp(16px, 4vw, 28px)
    }

    /* --- Toolbar with centered buttons --- */

    .toolbar{
      display: flex;
      justify-content: center;
      margin: 8px 0 40px;
      gap: 12px;
      flex-wrap: wrap; 
    }

    /* --- Top bar --- */
    /* Buttons aligned to the left */
    .topbar {
      display: flex;
      justify-content: flex-start;
    }

    /* Buttons aligned to the right */
    .topbar-right{
    margin-left: auto;   
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    }

    /* Main topbar layout */
    .topbar{
      display:flex;
      justify-content: space-between;
      gap:12px;
      flex-wrap:wrap;
      align-items:center;
    }

    /* Right-side button group */
    .topbar .right{
      display:flex;
      gap:10px;
      flex-wrap:wrap;
    }

    /* Center topbar content on very small screens */
    @media (max-width:480px){
      .topbar{
        justify-content:center;
        text-align:center;
      }
      .topbar .left{
        width:100%;
        display:flex;
        justify-content:center;
      }
      .topbar-right{
        margin-left: 0; 
        justify-content:center;
      }

        .std_btn {
        text-align: center;
      }
    }

    /* --- Standard button style --- */

    .std_btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      background: var(--bg);
      font-size: 0.9rem;
      color: var(--text);
      text-decoration: none;
      min-height: 36px;
      padding: 6px 12px;
      border: 1px solid var(--muted);
      border-radius: 8px;
      white-space: nowrap;     
    }

    /* Destructive button variant */
    .std_btn.danger{
      background: var(--danger);
      color: var(--text);
      border-color: var(--danger);
    }

    /* Darken destructive button on hover */
    .std_btn.danger:hover {
      filter: brightness(0.6);
    }

    /* Hover state for standard buttons */
    .std_btn:hover {
      background: var(--bg-light);
      color: var(--text);
      border-color: var(--border);
    }
    

    /* Disabled button state */
    .std_btn[disabled] {
      opacity: .5;
      cursor: not-allowed;
    }

    /* --- Base green button --- */

    .green-btn{
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: .5rem;
      padding: 12px 18px;
      font-size: var(--fs-base);
      font-weight: 700;
      border: 0;
      border-radius: 999px;
      background: var(--selfmade);
      color: var(--selfmade-text);
      cursor: pointer;
      box-shadow: var(--shadow);
      text-decoration: none; 
    }

    /* Hover effect for green buttons */
    .green-btn:hover{
      background: var(--selfmade-hover);
      transform: translateY(-1px);
    }

    /* Active press state */
    .green-btn:active{
      transform: translateY(0);
    }

    /* Square icon-only green button */
    .green-btn--icon{
      width: 44px;
      height: 44px;
      padding: 12px 14px;
    }

    /* Icon sizing inside the icon-only green button */
    .green-btn--icon svg{
      width:20px;
      height:20px;
      flex: 0 0 20px;
    }

    /* Full-width green button variant */
    .green-btn--wide{
      width: 100%;
      padding: 12px 18px;
      font-size: var(--fs-base);
      font-weight: 700;
      box-shadow: var(--shadow);
    }

    /* Selfmade badges */
    .badge{
      display:inline-flex; align-items:center; gap:.4rem;
      background:var(--selfmade); color:var(--selfmade-text); font-weight:700; font-size:.8rem;
      padding:4px 10px; border-radius:999px; box-shadow: var(--shadow);
    }

    /* --- Back link --- */

    .back{ 
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      background: var(--bg);
      font-size: 0.9rem;
      color: var(--muted);
      text-decoration: none;
      min-height: 36px;
      padding: 6px 12px;
      border: 1px solid var(--muted);
      border-radius: 8px;
      white-space: nowrap; 
    }

    /* Hover state for back links */
    .back:hover{ 
      background: var(--bg);
      color: var(--text);
      border-color: var(--border);
    }

    /* --- Thumbnails --- */

    .thumbs {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
      gap: 10px;
      margin-top: 8px
    }

    /* Generic thumbnail box */
    .thumb {
      position: relative;
      border-radius: 10px;
      overflow: hidden;
      background: var(--bg);
      border: 1px solid var(--field-br);
      aspect-ratio: 1/1
    }

    /* Thumbnail image fills the box */
    .thumb img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block
    }

    /* Small close button on thumbnails */
    .thumb .x {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 999px;
    background: var(--grey);
    color: var(--text);
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
  }

  /* Cross symbol rendered via text content */
  .thumb .x::before{
    font-size: 18px;
    line-height: 1;
  }

    /* Document thumbnail layout */
    #docList .thumb {
      display: grid;
      grid-auto-flow: column;
      align-items: center;
      gap: 8px;
      font-size: .9em;
      padding: 8px 10px;
    }

   /* Long file names are clamped to two lines */
    #docList .file-label {
      display: -webkit-box;
      line-clamp: 2;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      overflow: hidden;
      text-overflow: ellipsis;
      line-height: 1.2;
      max-height: 2.4em;
      word-break: break-word;
    }

    /* File icon container */
    #docList .file-emoji{
      display: inline-flex;
      width: 20px;
      height: 20px;
      flex: 0 0 20px;
      color: var(--muted);
    }

    /* File icon SVG fills the emoji container */
    #docList .file-emoji svg{
      width: 100%;
      height: 100%;
      display: block;
    }

    /* Generic cross icon lines */
    .x::before,
    .x::after {
      content: "";
      position: absolute;
      width: 2px;
      height: 12px;
      background: var(--text)
    }

    /* First diagonal line of the cross */
    .x::before {
      transform: rotate(45deg)
    }

    /* Second diagonal line of the cross */
    .x::after {
      transform: rotate(-45deg)
    }

    /* --- Footer --- */

    .footer-hero {
      width: 100%;
      background: var(--bg);
      color: var(--text);
      position: relative;
      overflow: hidden;
      padding: 28px 20px;   
      margin: 60px 0 0 0;  
      padding-bottom: calc(28px + env(safe-area-inset-bottom));
      background: var(--header); /* same as header */
    }

    /* Footer inner wrapper above the overlay */
    .footer-inner {
      position: relative;
      z-index: 1;
      max-width: 1200px;
      margin: 0 auto;
      text-align: center;
    }

    /* Footer buttons spacing */
    .footer-hero .std_btn {
      margin-top: 14px;
      display: inline-block;
    }

    /* Footer title styling */
    .footer-title {
      text-align: center;
      margin: 24px 0 8px;
      font-size: var(--fs-h2);
      line-height: 1.15;
    }

    /* --- Accessibility --- */

    /* Remove default browser focus outline */
    *:focus {
        outline: none; 
    }

    /* Visible keyboard focus state */
    *:focus-visible {
        outline: 3px solid var(--focus-color) !important;
        outline-offset: 3px !important;
        border-radius: 10px !important;          
        background: var(--focus-bg) !important;
    }

    /* Skip link for keyboard users */
    .skip-link{
      position: fixed;
      top: 12px;             
      left: 50%;
      transform: translate(-50%, -200%);
      padding: 10px 16px;
      background: var(--bg);
      color:var(--text);
      border-radius: 12px;
      font-weight: 600;
      z-index: 10000;
      transition: transform .15s ease;
      box-shadow: 0 4px 12px var(--shadow);
    }

    /* Show skip link when focused */
    .skip-link:focus,
    .skip-link:focus-visible{
      transform: translate(-50%, 0);
      outline: 3px solid var(--focus-color);
      outline-offset: 3px;
    }

    /* Utility class for screen-reader-only content */
    .visually-hidden {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0 0 0 0);
      white-space: nowrap;
      border: 0;
    }

    /* Alternative screen-reader-only helper class */
    .sr-only{
      position:absolute;
      width:1px;
      height:1px;
      margin:-1px;
      padding:0;
      overflow:hidden;
      clip:rect(0,0,0,0);
      white-space:nowrap;
      border:0;
    }