:root {
  --fg: black;
  --bg: white;
  --fg-pure: black;
  --hash-w: 0.5px;
  --hash-mini-w: 0.25px;
}

[data-theme="dark"] {
  --fg: #DDD;
  --fg-pure: white;
  --bg: black;
}

body {
  font-family: system-ui, sans-serif;
  width: 502px;
  margin: 2rem auto;
  padding: 0 1rem;
  background: var(--bg);
  color: var(--fg-pure);
}

@supports (-moz-appearance: none) {
  body {
    --hash-w: 1px;
    --hash-mini-w: 0.5px;
  }
}

* { box-sizing: content-box; }

.button {
  font-size: 0.9rem;
  text-decoration: none;
  padding: 3px 9px;
  border: 1px solid var(--fg-pure);
  color: var(--fg-pure);
  background: var(--bg);
  cursor: pointer;
  &:hover {
    background-color: var(--fg-pure);
    color: var(--bg);
  }
}

#site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;

  #logo {
    text-decoration: none !important;

    h1 {
      margin: 0;
      color: var(--fg-pure);
      letter-spacing: -3px;
      font-size: 2.5rem;
      -webkit-text-stroke: 1px black;
      paint-order: stroke fill;
      position: relative;

      &::after {
        content: 'qckchs';
        position: absolute;
        left: 2px;
        top: 2px;
        z-index: -1;
        background-color: var(--bg);
        background-clip: text;
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        -webkit-text-stroke: 1px var(--fg-pure);
        paint-order: stroke fill;
      }

      &:hover {
        color: var(--bg);
        -webkit-text-stroke: 2px var(--fg-pure);
        &::after {
          background-color: var(--fg-pure);
          -webkit-text-fill-color: var(--fg-pure);
        }
      }
    }
  }

  &.white-player #logo h1, &.spectator-player #logo h1 {
    color: var(--bg);
    -webkit-text-stroke: 2px var(--fg-pure);
    &::after {
      background-color: var(--fg-pure);
      -webkit-text-fill-color: var(--fg-pure);
    }
    &:hover {
      color: var(--fg-pure);
      &::after {
        background-color: var(--bg);
        -webkit-text-fill-color: transparent;
      }
    }
  }

  .header-link {
    font-size: 0.75rem;
    &.current {
      background: var(--fg-pure);
      color: var(--bg);
    }
  }

  .theme-toggle {
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border-radius: 50%;
    background: var(--bg);
    border: 2px solid var(--fg-pure);
    cursor: pointer;
    padding: 0;
    vertical-align: middle;
  }
}

.profile-page {
  .form-field {
    margin-bottom: 1rem;

    label {
      display: block;
      font-weight: 600;
      margin-bottom: 0.25rem;
    }

    input[type="text"] {
      font-size: 0.9rem;
      padding: 0.35rem 0.58rem;
      border: 1px solid var(--fg-pure);
      color: black;
      background: white;
      &:focus {
        outline: 2px solid var(--fg-pure);
      }
      &[disabled] {
        background: var(--fg-pure);
        color: var(--bg);
      }
    }

    .name-input {
      display: flex;
      gap: 0.5rem;
      align-items: center;

      input { max-width: 50%; }
    }
  }

  .profile-stats {
    width: 500px;
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    margin: 2rem 0;
    > div {
      background: var(--fg-pure);
      color: var(--bg);
      padding: 10px 20px;
      font-size: 1.2rem;
      text-align: center;
      display: flex;
      flex-direction: column;
      align-items: center;
      label { font-size: 0.9rem; }
      strong { font-size: 1.5rem; }
    }
  }

  .notice {
    background: var(--fg-pure);
    color: var(--bg);
    border: 1px solid var(--fg-pure);
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
  }
}

.pk-display {
  font-family: monospace;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;

  input:disabled { color: black; }

  button {
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
  }
}

.logout-page {
  .notice {
    background: var(--fg-pure);
    color: var(--bg);
    border: 1px solid var(--fg-pure);
    padding: 0.5rem 0.75rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
  }

  .pk-field {
    margin-bottom: 1.5rem;

    label {
      display: block;
      font-weight: 600;
      margin-bottom: 0.25rem;
    }
  }

  .logout-btn {
    font-size: 1rem;
  }
}

.new-game-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  align-items: center;
  justify-content: start;
  background-color: var(--bg);
  background-image: repeating-linear-gradient(
    -45deg,
    var(--fg) 0px, var(--fg) var(--hash-w),
    transparent var(--hash-w), transparent 50%
  );
  background-size: 8px 8px;
  border: 1px solid var(--fg);
  text-align: center;
  font-size: 0.8rem;
  padding: 1.25rem 2rem;
  label { font-size: 0.75rem; background: var(--bg); padding: 0 0.25rem; }
  .buttons {
    display: flex;
    gap: 0.5rem;
    align-items: center;
  }
}

.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.25rem;
  font-size: 0.9rem;

  .player-name {
    font-weight: 600;
    color: var(--fg-pure);
    text-decoration: none;
    letter-spacing: -1px;
  }

  .player-time {
    font-variant-numeric: tabular-nums;
    font-family: monospace;
  }
}

.game-area {
  position: relative;
  min-height: 200px;
}

.game-status {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  text-align: center;
  font-size: 0.8rem;
  padding: 2rem 3rem;
  background: var(--bg);
  opacity: 0.95;
  border: 1px solid var(--fg);
  color: var(--fg-pure);

  .variant {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  &.waiting-for-players {
    p {
      -webkit-background-clip: text;
      -webkit-text-fill-color: var(--fg-pure);
      -webkit-text-stroke: 5px var(--bg);
      paint-order: stroke fill;
    }
    background-color: var(--bg);
    background-image: repeating-linear-gradient(
      -45deg,
      var(--fg) 0px, var(--fg) var(--hash-w),
      transparent var(--hash-w), transparent 50%
    );
    background-size: 8px 8px;
  }

  .dismiss-btn {
    position: absolute;
    top: 0.25rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #666;
    line-height: 1;
    padding: 0;
  }

  p {
    margin-top: 0;
    margin-bottom: 0.2rem;
  }
}

#board {
  width: 500px;
  height: 600px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(6, 1fr);
  border: 1px solid var(--fg);
  box-sizing: content-box;
  overflow: hidden;

  > div.sq {
    position: relative;
    display: grid;
    justify-items: center;
    align-items: center;
    background: var(--bg);
    border: 1px solid var(--fg);
    width: 100px;
    height: 100px;
    box-sizing: border-box;
    overflow: visible;
    &:nth-child(odd)::before {
      content: '';
      position: absolute;
      inset: 0;
      background-color: var(--bg);
      background-image: repeating-linear-gradient(
        -45deg,
        var(--fg) 0px, var(--fg) var(--hash-w),
        transparent var(--hash-w), transparent 50%
      );
      background-size: 8px 8px;
      pointer-events: none;
    }
    &.dragging { opacity: 0.6; }
    > img {
      width: 80%;
      height: 80%;
      position: relative;
      z-index: 1;
      filter:
        drop-shadow( 1px  0   0 white)
        drop-shadow(-1px  0   0 white)
        drop-shadow( 0    1px 0 white)
        drop-shadow( 0   -1px 0 white);
    }
    &.valid-target::after {
      content: '';
      position: absolute;
      inset: 0;
      pointer-events: none;
      z-index: 2;
      background:
        linear-gradient(135deg, var(--fg-pure) 8px, transparent 8px),
        linear-gradient(225deg, var(--fg-pure) 8px, transparent 8px),
        linear-gradient(315deg, var(--fg-pure) 8px, transparent 8px),
        linear-gradient(45deg, var(--fg-pure) 8px, transparent 8px);
      background-position: top left, top right, bottom right, bottom left;
      background-size: 50% 50%;
      background-repeat: no-repeat;
    }
    &.hover-target::after {
      background:
        linear-gradient(135deg, var(--fg-pure) 10px, transparent 10px),
        linear-gradient(225deg, var(--fg-pure) 10px, transparent 10px),
        linear-gradient(315deg, var(--fg-pure) 10px, transparent 10px),
        linear-gradient(45deg, var(--fg-pure) 10px, transparent 10px);
      background-position: top left, top right, bottom right, bottom left;
      background-size: 50% 50%;
      background-repeat: no-repeat;
    }
    &.hl-from::after,
    &.hl-to::after {
      content: '';
      position: absolute;
      inset: 2px;
      pointer-events: none;
      z-index: 0;
      --l: 14px;
      --t: 2px;
      background:
        /* top-left */
        linear-gradient(var(--fg-pure), var(--fg-pure)) top left / var(--l) var(--t) no-repeat,
        linear-gradient(var(--fg-pure), var(--fg-pure)) top left / var(--t) var(--l) no-repeat,
        /* top-right */
        linear-gradient(var(--fg-pure), var(--fg-pure)) top right / var(--l) var(--t) no-repeat,
        linear-gradient(var(--fg-pure), var(--fg-pure)) top right / var(--t) var(--l) no-repeat,
        /* bottom-right */
        linear-gradient(var(--fg-pure), var(--fg-pure)) bottom right / var(--l) var(--t) no-repeat,
        linear-gradient(var(--fg-pure), var(--fg-pure)) bottom right / var(--t) var(--l) no-repeat,
        /* bottom-left */
        linear-gradient(var(--fg-pure), var(--fg-pure)) bottom left / var(--l) var(--t) no-repeat,
        linear-gradient(var(--fg-pure), var(--fg-pure)) bottom left / var(--t) var(--l) no-repeat;
    }
  }
}

.drag-clone {
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 1000;
  display: grid;
  justify-items: center;
  align-items: center;
  will-change: transform;
  filter:
    drop-shadow( 1px  0   0 white)
    drop-shadow(-1px  0   0 white)
    drop-shadow( 0    1px 0 white)
    drop-shadow( 0   -1px 0 white);
}

#joinable {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 1rem;
}

.join-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-pure);
  z-index: 2;
}

#lobby, .profile-games {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 1rem;
}

.mini-game {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
  &.joinable-game {
    .mini-board .sq { opacity: 0.7; }
  }
}

.mini-bar {
  display: flex;
  justify-content: space-between;
  font-size: 0.6rem;
  padding: 0.1rem 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  max-width: 115px;
  line-height: 1.2;
  min-height: 0.9em;

  span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.mini-board {
  position: relative;
  width: 115px;
  height: 138px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(6, 1fr);
  border: 0.5px solid var(--fg);
  box-sizing: content-box;

  > div.sq {
    position: relative;
    display: grid;
    justify-items: center;
    align-items: center;
    background: var(--bg);
    border: 0.5px solid var(--fg);
    width: 23px;
    height: 23px;
    box-sizing: border-box;
    overflow: hidden;
    &:nth-child(odd)::before {
      content: '';
      position: absolute;
      inset: -50%;
      width: 200%;
      height: 200%;
      background-color: var(--bg);
      background-image: repeating-linear-gradient(
        -45deg,
        var(--fg) 0px, var(--fg) var(--hash-mini-w),
        transparent var(--hash-mini-w), transparent 50%
      );
      background-size: 3px 3px;
      pointer-events: none;
    }
    > img {
      width: 80%;
      height: 80%;
      position: relative;
      z-index: 1;
      filter:
        drop-shadow( 0.5px  0   0 white)
        drop-shadow(-0.5px  0   0 white)
        drop-shadow( 0    0.5px 0 white)
        drop-shadow( 0   -0.5px 0 white);
    }
  }
}
