/* DOOM look: always dark; the background and the title font come from the
   visitor's own IWAD (doomlook.js), these are the fallbacks until then.
   Modern CSS: layers, nesting, clamp(), color-mix(), :has(), container queries. */
@layer base, layout, parts, states;

@layer base {
  :root {
    color-scheme: dark;
    --bg: #120806;
    --fg: #e8dccf;
    --muted: #a8988a;
    --red: #d42a1a;
    --gold: #ffd27a;
    --line: color-mix(in srgb, var(--red) 35%, #1a0a06);
    --panel: color-mix(in srgb, #0a0605 82%, transparent);
    --box: color-mix(in srgb, #000 55%, transparent);
    --gap: clamp(8px, 2vw, 16px);
    accent-color: var(--red);
  }
  *, *::before, *::after { box-sizing: border-box; }
  [hidden] { display: none !important; }
  body {
    margin: 0;
    min-block-size: 100dvh;
    background: var(--bg) radial-gradient(ellipse at top, #3a0f08, var(--bg) 70%) fixed;
    color: var(--fg);
    font: 16px/1.5 system-ui, sans-serif;
    &.doombg {
      background-size: cover;
      background-position: center top;
      background-attachment: fixed;
      image-rendering: pixelated;
    }
  }
  h1 { font-size: clamp(1.3rem, 4vw, 1.8rem); margin-block: 4px 8px; text-wrap: balance; }
  a { color: var(--gold); }
  :focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
}

@layer layout {
  header {
    padding: 12px var(--gap);
    border-block-end: 2px solid var(--red);
    background: var(--panel);
    backdrop-filter: blur(3px);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px 24px;
  }
  main {
    container: page / inline-size;
    max-inline-size: 1000px;
    margin: var(--gap) auto;
    padding: var(--gap);
    background: var(--panel);
    border: 1px solid var(--line);
    backdrop-filter: blur(3px);
    box-shadow: 0 0 40px color-mix(in srgb, var(--red) 25%, transparent);
  }
  .maps {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 12px;
    margin-block: 16px;
  }
  .go { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
  @container page (inline-size < 640px) {
    .maps { grid-template-columns: 1fr; }
    .maps .list { max-block-size: 200px; }
    #view { block-size: 320px; }
  }
}

@layer parts {
  header, h1, .pick label > span, .maps .head > span {
    color: var(--red);
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
  }
  .doomtext { display: inline-block; image-rendering: pixelated; vertical-align: middle; max-inline-size: 100%; block-size: auto; }
  .pick label {
    display: block;
    margin-block: 14px;
    color: var(--muted);
    & > span { display: block; }
    & input { display: block; margin-block-start: 4px; max-inline-size: 100%; color: var(--fg); }
  }
  .maps .list {
    max-block-size: 480px;
    overflow-y: auto;
    background: var(--box);
    border: 1px solid var(--line);
    padding: 6px;
    scrollbar-color: var(--red) transparent;
    & .head { margin-block-end: 6px; }
    & .head button { font-size: 12px; padding: 0 6px; }
  }
  .map {
    display: block;
    cursor: pointer;
    white-space: nowrap;
    &:hover { background: color-mix(in srgb, var(--red) 20%, transparent); }
    &:has(input:checked) { color: var(--gold); }
  }
  .secret { color: #e0b020; font-size: 12px; }
  #view {
    inline-size: 100%;
    min-inline-size: 0;
    block-size: 480px;
    background: #101014;
    touch-action: none;
    cursor: grab;
    border: 1px solid var(--line);
    &:active { cursor: grabbing; }
  }
  button {
    padding: 6px 16px;
    font: inherit;
    cursor: pointer;
    background: #2a0d08;
    color: var(--fg);
    border: 2px solid var(--red);
    transition: background-color .15s, transform .1s;
    &:hover { background: #4a140c; }
    &:active { transform: translateY(1px); }
  }
  #convert { padding: 10px 22px; }
  footer { max-inline-size: 1000px; margin: 0 auto var(--gap); padding-inline: var(--gap); font-size: 13px;
    & p { margin-block: 4px; } }
  .eta { color: var(--gold); font-variant-numeric: tabular-nums; }

  /* DOS text mode, 80 columns: light grey on black, the bar red on light grey */
  .dos {
    background: #000;
    color: #aaa;
    font: 20px/1 "VT323", "Courier New", monospace;
    padding-block-end: 8px;
    margin-block-start: 20px;
    block-size: 25em;
    overflow: auto;
    border: 2px solid #333;
    white-space: pre;
    & div { padding-inline: 8px; min-block-size: 1em; }
    & > .head, & > .body { padding: 0; }
    & > .head { position: sticky; inset-block-start: 0; background: #000; }
    & .title { background: #aaa; color: #a00; text-align: center; }
    & .ok { color: #fff; }
    & .bad { color: #f55; }
    & .cursor { animation: blink 1s steps(1) infinite; }
    & .active::after { content: ''; animation: dots 1.2s steps(1) infinite; }
  }
  .bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-block-start: 12px;
    & .track { flex: 1; block-size: 14px; background: #000; border: 1px solid var(--line); overflow: hidden; }
    & .fill {
      block-size: 100%;
      inline-size: 0;
      background: linear-gradient(90deg, #7a0d05, var(--red), #ff6a2a);
      transition: inline-size .4s;
    }
  }
  #pct { font-variant-numeric: tabular-nums; min-inline-size: 3.5em; text-align: end; }
  #errors { font-size: 14px; }
  #downloads a { font-weight: 700; }

  /* the last conversions: one row each, the WAD in gold, maps, then when */
  .recent {
    margin-block-start: 24px;
    border-block-start: 1px solid var(--line);
    padding-block-start: 8px;
    & h2 { font-size: 1rem; color: var(--red); letter-spacing: .06em; text-transform: uppercase; margin-block: 4px 8px; }
    & ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
    & li {
      display: grid;
      grid-template-columns: minmax(8em, 14em) 1fr auto;
      align-items: baseline;
      gap: 12px;
      padding: 4px 8px;
      background: var(--box);
      font-size: 14px;
      &:nth-child(odd) { background: color-mix(in srgb, var(--red) 8%, var(--box)); }
    }
    & b { color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    & .rmaps { color: var(--fg); font-family: "VT323", monospace; font-size: 17px; line-height: 1.2; }
    & .when { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
    & li.fail {
      border-inline-start: 3px solid var(--red);
      & b { color: #ff8a70; }
      & .when { color: #ff6a55; }
    }
    & .why { grid-column: 1 / -1; color: #ff8a70; font-size: 13px; overflow-wrap: anywhere; }
    @container page (inline-size < 640px) {
      & li { grid-template-columns: 1fr auto; }
      & .rmaps { grid-column: 1 / -1; grid-row: 2; }
    }
  }
}

@layer states {
  button:disabled { opacity: .5; cursor: wait; }
  .err { color: #ff6a55; }
  .busy, .note { color: var(--muted); }
  .note.warn { color: #e8c040; border-left: 3px solid #e8c040; padding-left: .6em; }
  @keyframes blink { 50% { opacity: 0; } }
  @keyframes dots {                      /* the running step: . .. ... */
    0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; }
  }
  @media (prefers-reduced-motion: reduce) {
    .dos .cursor { animation: none; }
    .bar .fill { transition: none; }
  }
}
