/* The layer statement precedes the imports so they can be imported INTO a layer.
   base.css carries the `* { margin: 0; padding: 0 }` reset; imported unlayered it
   outranked every layered rule regardless of specificity, so all the margins and
   padding declared in `components` were dead. */
@layer base, components, overlay;
@import 'base.css' layer(base);
@import 'tokens.css' layer(base);

@layer base {
  html {
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font);
    font-size: 14px;
  }

  body {
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background: var(--bg);
    touch-action: manipulation;
  }

  #wrap {
    width: min(var(--measure-app), calc(100% - 32px));
    display: flex;
    flex-direction: column;
    height: 100vh;
  }
}

@layer components {
  #top {
    display: flex;
    align-items: center;
    padding: 24px 0 12px;
    flex-shrink: 0;
    position: relative;
  }

  #timer {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 15px;
    color: var(--accent);
    font-family: var(--font);
  }

  #song-name {
    margin-left: auto;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
  }

  #line-wrap {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    overflow: hidden;
    overflow-anchor: none;
    overscroll-behavior: none;
    cursor: text;
    -webkit-mask-image: linear-gradient(
      to right,
      transparent 0,
      #000 3%,
      #000 60%,
      transparent 100%
    );
    mask-image: linear-gradient(to right, transparent 0, #000 3%, #000 60%, transparent 100%);
  }

  #line-wrap.idle {
    overflow-x: auto;
  }
  #line-wrap.idle::-webkit-scrollbar {
    display: none;
  }

  #line {
    white-space: nowrap;
    font-size: 28px;
    line-height: 1.4;
    min-width: 100%;
    transition: transform 80ms ease-out;
  }

  #line .char.correct {
    color: var(--muted);
  }
  #line .char.incorrect {
    color: var(--danger);
    opacity: 0.6;
  }
  #line .char.future {
    color: var(--fg);
  }

  .char.cursor {
    position: relative;
    color: var(--fg);
  }
  .char.cursor::before {
    content: '';
    position: absolute;
    left: -1px;
    top: 1px;
    width: 4px;
    height: 1.3em;
    background: var(--caret);
    border-radius: var(--radius-xs);
  }

  #input {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: text;
    touch-action: manipulation;
    font-family: var(--font);
    font-size: 28px;
    border: none;
    outline: none;
    padding: 0;
    margin: 0;
    caret-color: transparent;
  }

  #time-bar {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
  }
  .time-opt {
    color: var(--muted);
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font);
    touch-action: manipulation;
  }
  .time-opt.active {
    color: var(--fg);
  }
  .time-opt:hover {
    color: var(--accent);
  }

  #legend {
    display: flex;
    gap: 16px;
    padding: 24px 0;
    color: var(--muted);
    font-size: 12px;
    flex-shrink: 0;
    justify-content: center;
    touch-action: manipulation;
  }
  .legend-item {
    cursor: pointer;
    touch-action: manipulation;
  }
  .legend-item:hover {
    color: var(--accent);
  }

  .kbd {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid var(--line);
    color: var(--muted);
    font-family: var(--font);
    line-height: 1.7;
  }

  #footer {
    padding: 12px 0 24px;
    color: var(--muted);
    font-size: 9px;
    white-space: normal;
    text-align: center;
    flex-shrink: 0;
    line-height: 1.5;
  }

  #finish-overlay {
    position: absolute;
    inset: 0;
    background: var(--scrim-blur);
    -webkit-backdrop-filter: blur(var(--blur-sm));
    backdrop-filter: blur(var(--blur-sm));
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
  }
  #burst-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
  }
  .muted {
    color: var(--muted);
  }
  .fg {
    color: var(--fg);
  }
  .accent {
    color: var(--accent);
  }

  #finish-overlay.hidden {
    display: none;
  }
  .overlay-close {
    display: block;
    margin-bottom: 8px;
    color: var(--danger);
    font-size: 16px;
    cursor: pointer;
    font-family: var(--font);
    line-height: 1;
    text-align: center;
  }
  .overlay-close:hover {
    color: var(--fg);
  }
  .overlay-inner {
    text-align: center;
  }
  .overlay-stat {
    font-size: 22px;
    color: var(--fg);
    font-family: var(--font);
    line-height: 1.8;
  }
  .overlay-stat span {
    color: var(--accent);
    font-weight: 700;
  }
  .retry-link {
    color: var(--accent);
    text-decoration: none;
  }
  .retry-link:hover {
    text-decoration: underline;
  }

  .noscript-fallback {
    position: fixed;
    inset: 0;
    background: var(--bg);
    display: grid;
    place-items: center;
    color: var(--muted);
    font-family: var(--font);
    font-size: 14px;
    z-index: 9999;
  }
}

@layer overlay {
  .hidden {
    display: none !important;
  }

  #palette {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    display: flex;
    justify-content: center;
    padding-top: 15vh;
    z-index: 100;
  }

  .palette-inner {
    width: min(var(--measure-palette), calc(100% - 32px));
    background: var(--card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-overlay);
    align-self: flex-start;
  }

  .palette-input-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
  }

  .palette-prompt {
    color: var(--accent);
    font-family: var(--font);
    font-size: 14px;
  }

  #palette-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--fg);
    font-family: var(--font);
    font-size: 14px;
  }

  #palette-results {
    max-height: 320px;
    overflow-y: auto;
  }

  .palette-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    color: var(--fg);
  }

  .palette-item .song-slug {
    color: var(--muted);
    font-size: 11px;
  }

  .palette-item:hover,
  .palette-item.focused {
    background: var(--hover);
  }

  #highscores {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    display: flex;
    justify-content: center;
    padding-top: 15vh;
    z-index: 100;
  }
  .hs-inner {
    width: min(var(--measure-palette), calc(100% - 32px));
    background: var(--card);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-overlay);
    align-self: flex-start;
  }
  .hs-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
  }
  .hs-prompt {
    color: var(--accent);
    font-family: var(--font);
    font-size: 14px;
  }
  #hs-time {
    color: var(--muted);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
  }
  #hs-time:hover {
    color: var(--accent);
  }
  #hs-body-wrap {
    max-height: 320px;
    overflow-y: auto;
  }
  #hs-body-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font);
    font-size: 13px;
  }
  #hs-body-wrap th {
    color: var(--muted);
    text-align: left;
    padding: 8px 16px;
    font-weight: 400;
    border-bottom: 1px solid var(--line);
  }
  #hs-body-wrap td {
    color: var(--fg);
    padding: 6px 16px;
    border-bottom: 1px solid var(--line);
  }
  #hs-body-wrap td:first-child {
    color: var(--muted);
  }
  #hs-body-wrap td:nth-child(2),
  #hs-body-wrap td:nth-child(3) {
    color: var(--accent);
  }
  #hs-export {
    display: block;
    padding: 10px 16px;
    color: var(--muted);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    text-align: center;
    border-top: 1px solid var(--line);
  }
  #hs-export:hover {
    color: var(--accent);
  }
  .hs-empty {
    text-align: center;
    padding: 24px;
    color: var(--muted);
  }
}

@media (max-width: 600px) {
  #line {
    font-size: 22px;
  }
  #top {
    padding: 16px 0 8px;
  }
  #legend {
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px 0;
  }
  .kbd {
    font-size: 9px;
    padding: 1px 4px;
  }
  .palette-inner,
  .hs-inner {
    width: calc(100% - 16px);
  }
  #footer {
    font-size: 8px;
    white-space: normal;
  }
  #line-wrap {
    -webkit-mask-image: linear-gradient(
      to right,
      transparent 0,
      #000 6%,
      #000 50%,
      transparent 100%
    );
    mask-image: linear-gradient(to right, transparent 0, #000 6%, #000 50%, transparent 100%);
  }
}

@media (max-width: 400px) {
  #line {
    font-size: 18px;
  }
  #timer {
    font-size: 13px;
  }
  #song-name {
    font-size: 11px;
  }
}
