/* ==========================================================================
   Topsters 3-inspired styles
   Tokens and geometry extracted from topsters.org (2026-11-06)
   ========================================================================== */

:root {
  --ui-bg: #000;
  --blue-bg: #0f9b8e;
  --text-color: #fff;
  --main-bg: #2a2a2a;
  --accent: coral;
  --input-bg: #ccc;
  --panel-bg: #141414cc;
  --button-bg: #393939;
  --muted: #b5b5b5;
  --border: #3c3c3ce6;
  --placeholder: #5a5a5a99;
  --sidebar-width: 400px;
  --tile-size: 260px;
  --grid-gap: 20px;
  --tile-radius: 0px;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background-color: var(--main-bg);
  color: var(--text-color);
  font-family:
    "Nunito",
    system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  font-size: 16px;
  line-height: 1.4;
  scrollbar-color: var(--accent) #000;
  scrollbar-width: thin;
  accent-color: var(--accent);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

h1,
h2,
h3 {
  color: var(--accent);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   App shell
   -------------------------------------------------------------------------- */

.main {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Sidebar
   -------------------------------------------------------------------------- */

.sidebar-container {
  display: flex;
  align-items: flex-start;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 10px;
  background: transparent;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  width: 100%;
  min-height: 0;
  max-height: 100%;
}

.sidebar-header {
  padding: 16px 10px;
  text-align: center;
  margin-bottom: 10px;
  background: var(--panel-bg);
  border-radius: 6px;
}

.sidebar-header h1 {
  margin: 0;
  font-size: 1.8rem;
  line-height: 1.1;
  letter-spacing: 0.01em;
}

/* Tabs -------------------------------------------------------------------- */

.sidebar-action-list {
  display: flex;
  gap: 4px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sidebar-action-item {
  flex: 1 1 0;
  min-width: 0;
}

.sidebar-action-btn {
  width: 100%;
  padding: 8px 10px;
  color: #000;
  background: var(--muted);
  border: none;
  border-radius: 6px 6px 0 0;
  font-size: 1rem;
  line-height: 1.2;
  transition:
    background-color 0.15s ease-out,
    color 0.15s ease-out;
}

.sidebar-action-btn:hover {
  background: #c9c9c9;
}

.sidebar-action-btn-active,
.sidebar-action-btn-active:hover {
  color: var(--text-color);
  background: var(--panel-bg);
}

/* Tab panel --------------------------------------------------------------- */

.sidebar-action {
  flex: 0 1 auto;
  min-height: 0;
  max-height: calc(100dvh - 150px);
  padding: 16px;
  overflow-y: auto;
  background: var(--panel-bg);
  border-radius: 0 0 6px 6px;
  scrollbar-color: var(--accent) #000;
  scrollbar-width: thin;
}

/* Tab panels -------------------------------------------------------------- */

.sidebar-panel[hidden] {
  display: none;
}

/* Search row -------------------------------------------------------------- */

.sidebar-addlvl-form {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.sidebar-addlvl-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 36px;
  padding: 8px 10px;
  color: #000;
  background: var(--input-bg);
  border: none;
  border-radius: 4px;
  font-size: 1rem;
}

.sidebar-addlvl-input::placeholder {
  color: #00000080;
}

.sidebar-addlvl-btn {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 14px;
  color: #000;
  background: var(--input-bg);
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  transition:
    background-color 0.15s ease-out,
    color 0.15s ease-out;
}

.sidebar-addlvl-btn:hover {
  color: #000;
  background: var(--accent);
}

/* Search results ---------------------------------------------------------- */

.sidebar-addlvl-result {
  display: grid;
  grid-template-columns: repeat(auto-fill, 90px);
  gap: 4px;
  justify-content: space-evenly;
  align-content: start;
  max-height: 45vh;
  margin: 12px 0;
  overflow-y: auto;
  padding: 2px;
  scrollbar-color: var(--accent) #000;
  scrollbar-width: thin;
}

.sidebar-addlvl-result:not(:has(> *))::after {
  content: "Search results will appear here";
  grid-column: 1 / -1;
  padding: 18px 6px;
  color: #ffffff80;
  font-size: 0.8rem;
  text-align: center;
}

.sidebar-addlvl-result > * {
  width: 90px;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background: var(--placeholder);
  border-radius: 4px;
  cursor: pointer;
}

.sidebar-addlvl-result > button {
  position: relative;
  padding: 0;
  color: inherit;
  font: inherit;
  border: 0;
  cursor: grab;
  user-select: none;
  appearance: none;
}

.sidebar-addlvl-result-caption {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 3px 4px;
  overflow: hidden;
  color: #fff;
  font-family: monospace;
  font-size: 0.7rem;
  font-weight: 400;
  line-height: 1.05;
  text-align: left;
  text-shadow:
    -1px -1px 0 #000,
    0 -1px 0 #000,
    1px -1px 0 #000,
    -1px 0 0 #000,
    1px 0 0 #000,
    -1px 1px 0 #000,
    0 1px 0 #000,
    1px 1px 0 #000,
    0 2px 4px #000;
  pointer-events: none;
}

.sidebar-addlvl-result-name,
.sidebar-addlvl-result-author {
  display: block;
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar-addlvl-result > button:active {
  cursor: grabbing;
}

.sidebar-addlvl-result > button.is-dragging {
  opacity: 0.5;
}

.sidebar-addlvl-result > button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-addlvl-result-item.is-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  color: #fff;
  font-size: 0.65rem;
  line-height: 1.2;
  text-align: center;
  word-break: break-word;
}

.sidebar-addlvl-result-missing {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  width: 100%;
}

.sidebar-addlvl-result-missing-name {
  font-size: 0.65rem;
  line-height: 1.1;
}

.sidebar-addlvl-result-missing-author {
  font-size: 0.58rem;
  line-height: 1.1;
  opacity: 0.75;
}

.sidebar-addlvl-result > .sidebar-addlvl-status {
  width: auto;
  aspect-ratio: auto;
  grid-column: 1 / -1;
  padding: 18px 6px;
  overflow: visible;
  color: #ffffff80;
  font-size: 0.8rem;
  text-align: center;
  background: transparent;
  border-radius: 0;
  cursor: default;
}

.sidebar-addlvl-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.sidebar-addlvl-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 0 0 12px;
}

.sidebar-addlvl-pagination[hidden] {
  display: none;
}

.sidebar-addlvl-page-btn {
  display: grid;
  place-items: center;
  width: 36px;
  height: 30px;
  padding: 0;
  color: var(--accent);
  font-size: 1.35rem;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--accent);
  border-radius: 4px;
  cursor: pointer;
  transition:
    background-color 0.15s ease-out,
    color 0.15s ease-out,
    opacity 0.15s ease-out;
}

.sidebar-addlvl-page-btn:hover:not(:disabled) {
  color: #fff;
  background: var(--accent);
}

.sidebar-addlvl-page-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.sidebar-addlvl-page-number {
  min-width: 36px;
  padding: 4px 8px;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  text-align: center;
  background: var(--accent);
  border-radius: 4px;
}

.sidebar-addlvl-result img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.sidebar-addlvl-result > *:hover {
  filter: brightness(1.1);
}

/* Options ----------------------------------------------------------------- */

a {
  color: var(--accent);
  text-decoration: none;
  position: relative;
  font-weight: 700;
  transition: color 0.2s ease;
}

a::after {
  content: "";
  display: inline-block;
  width: 0.85em;
  height: 0.85em;
  margin-left: 0.1em;
  margin-right: 0.15em;
  vertical-align: -0.05em;
  background-color: var(--accent);

  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3Cpolyline points='15 3 21 3 21 9'/%3E%3Cline x1='10' y1='14' x2='21' y2='3'/%3E%3C/svg%3E")
    center / contain no-repeat;

  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3Cpolyline points='15 3 21 3 21 9'/%3E%3Cline x1='10' y1='14' x2='21' y2='3'/%3E%3C/svg%3E")
    center / contain no-repeat;

  transition: transform 0.2s ease;
}

a:hover {
  color: color-mix(in srgb, var(--accent) 70%, black);
  text-decoration: underline;
}

a:hover::after {
  transform: translate(2px, -2px);
}

a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.sidebar-title-option {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 0 14px;
}

.sidebar-title-option > p {
  margin: 0;
  font-size: 0.9rem;
}

.sidebar-options-title-input {
  width: 100%;
  height: 36px;
  padding: 8px 10px;
  color: #000;
  background: var(--input-bg);
  border: none;
  border-radius: 4px;
  font-size: 1rem;
}

.sidebar-options-title-input::placeholder {
  color: #00000080;
}

.sidebar-option {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.sidebar-option:first-of-type {
  padding-top: 2px;
  border-top: 0;
}

.sidebar-option > p {
  margin: 0;
  font-size: 0.9rem;
}

.sidebar-option > p.sidebar-option-note {
  flex: 1 0 100%;
  color: #888;
  font-size: 0.8rem;
  font-style: italic;
  line-height: 1.35;
}

.sidebar-option > p.sidebar-option-note[hidden] {
  display: none;
}

.text-accent-bold {
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-option > div {
  flex: 1 0 100%;
  display: flex;
  gap: 10px;
  align-items: center;
}

.sidebar-option > div p {
  margin: 0;
  font-size: 0.9rem;
}

.sidebar-option > div p:first-child {
  flex: 0 0 56px;
}

.sidebar-options-height-value,
.sidebar-options-width-value {
  flex: 0 0 24px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.sidebar-data-actions {
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sidebar-data-btn {
  flex: 1 1 120px;
  padding: 8px 10px;
  color: #fff;
  background: var(--button-bg);
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition:
    background-color 0.15s ease-out,
    color 0.15s ease-out;
}

.sidebar-data-btn:hover {
  color: var(--accent);
  text-decoration: underline;
}

.sidebar-data-btn:disabled {
  opacity: 0.6;
  cursor: progress;
}

.sidebar-reset-btn {
  flex: 1 1 100%;
  background: #a12a2a;
}

.sidebar-reset-btn:hover {
  color: #fff;
  background: #c53030;
  text-decoration: none;
}

.sidebar-import-file {
  display: none;
}

/* Range inputs ------------------------------------------------------------ */

input[type="range"] {
  flex: 1 1 auto;
  height: 4px;
  background: var(--input-bg);
  border: none;
  border-radius: 5px;
  appearance: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  box-shadow: 1px 1px 1px #000;
  appearance: none;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  box-shadow: 1px 1px 1px #000;
  cursor: pointer;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: var(--input-bg);
  border-radius: 5px;
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  background: var(--accent);
  border-radius: 5px;
}

/* Checkbox switches ------------------------------------------------------- */

.sidebar-option input[type="checkbox"] {
  flex: 0 0 auto;
  width: 48px;
  height: 24px;
  margin: 0;
  background-color: var(--input-bg);
  background-image: radial-gradient(
    circle at center,
    #fff 0 9px,
    transparent 9.5px
  );
  background-repeat: no-repeat;
  background-position: left 2px center;
  background-size: 20px 20px;
  border: none;
  border-radius: 16px;
  appearance: none;
  cursor: pointer;
  transition:
    background-color 0.2s ease-out,
    background-position 0.2s ease-out;
}

.sidebar-option input[type="checkbox"]:checked {
  background-color: var(--accent);
  background-position: right 2px center;
}

/* --------------------------------------------------------------------------
   Chart area
   -------------------------------------------------------------------------- */

.main-container {
  height: 100%;
  min-width: 0;
  padding: 50px 20px;
  overflow: auto;
  scrollbar-color: var(--accent) #000;
  scrollbar-width: thin;
}

.chart-scale {
  position: relative;
  margin: 0 auto;
  overflow: hidden;
}

.main-grid {
  --cols: 5;
  --rows: 5;
  --label-width: 0px;
  --action-size: clamp(20px, calc(var(--tile) * 0.28), 200px);
  --tile: 260px;
  position: absolute;
  top: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile)) var(--label-width);
  grid-auto-rows: auto;
  gap: var(--grid-gap);
  width: max-content;
  margin: 0;
  padding: var(--grid-gap);
  background: #000;
  box-shadow: 0 0 0 1px #141414;
  transform: scale(var(--chart-scale, 1));
  transform-origin: top left;
  visibility: hidden;
}

.main-grid.is-scaled {
  visibility: visible;
}

.chart-title-row {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
  padding: 0;
  color: var(--text-color);
  font-family: monospace;
  font-size: 50px;
  line-height: 1.1;
  text-align: center;
  text-shadow: 2px 2px 4px rgb(0 0 0 / 60%);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* The whitespace/comment in the empty grid prevents :empty, so test for the
   absence of element children instead; the hint disappears as soon as JS adds
   the first tile. */
.main-grid:not(:has(> *))::after {
  content: "Search for levels to start your topster";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #666;
  font-size: 1rem;
  pointer-events: none;
}

.main-grid > * {
  width: 100%;
  min-width: 0;
}

.grid-cell-media img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.grid-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
  background: transparent;
  border: 0;
}

.grid-cell-media {
  position: relative;
  flex: 0 0 var(--tile);
  width: 100%;
  height: var(--tile);
  padding: 0;
  overflow: hidden;
  background: var(--placeholder);
  border: 0;
  border-radius: var(--tile-radius);
  box-shadow: 2px 2px 4px rgb(0 0 0 / 60%);
}

.grid-cell-media[draggable="true"] {
  cursor: grab;
}

.grid-cell-media[draggable="true"]:active {
  cursor: grabbing;
}

.grid-cell--dragging .grid-cell-media {
  opacity: 0.45;
}

.grid-cell--empty .grid-cell-media {
  cursor: pointer;
  appearance: none;
  transition: background-color 0.15s ease-out;
}

.grid-cell--empty .grid-cell-media:hover {
  background: #6a6a6a;
}

.grid-cell--empty .grid-cell-media:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.grid-cell-media--missing {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
  box-shadow:
    inset 0 0 0 1px #333,
    2px 2px 4px rgb(0 0 0 / 60%);
}

.grid-cell-fallback {
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 10px;
  overflow: hidden;
  color: #fff;
  font-size: 11px;
  line-height: 1.25;
  text-align: center;
  word-break: break-word;
}

.grid-cell-fallback-name {
  font-size: 11px;
  font-weight: 700;
}

.grid-cell-fallback-author {
  font-size: 9px;
  opacity: 0.75;
}

.grid-row-labels {
  display: flex;
  width: max-content;
  min-width: 0;
  padding: 0 2px;
  overflow: visible;
}

.grid-row-label-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: max-content;
  margin: 0;
  padding: 0;
  overflow: visible;
  font-family: monospace;
  text-shadow: rgba(0, 0, 0, 0.6) 2px 2px 4px;
  color: rgb(255, 255, 255);
  white-space: nowrap;
  text-align: left;
  font-size: 20px;
  list-style: none;
  line-height: 1.2;
  box-sizing: border-box;
}

.grid-cell-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  left: 6px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease-out;
}

.grid-cell:hover .grid-cell-actions,
.grid-cell:focus-within .grid-cell-actions {
  opacity: 1;
}

.grid-cell-action {
  display: grid;
  place-items: center;
  width: var(--action-size);
  height: var(--action-size);
  padding: 0;
  color: #fff;
  background: rgb(0 0 0 / 65%);
  border: 0;
  border-radius: 5px;
  pointer-events: auto;
  cursor: pointer;
  transition:
    background-color 0.15s ease-out,
    color 0.15s ease-out;
}

.grid-cell-action:hover {
  color: #000;
  background: var(--accent);
}

.grid-cell-action svg {
  pointer-events: none;
}

.grid-cell--drop-target .grid-cell-media {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.grid-cell-file {
  display: none;
}

.sidebar-addlvl-result > *,
.sidebar-addlvl-result img,
.grid-cell-media,
.grid-cell-media img {
  touch-action: none;
  -webkit-touch-callout: none;
}

.pointer-drag-ghost {
  position: fixed;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  color: #fff;
  font-family: monospace;
  font-size: 10px;
  text-align: center;
  background-color: #333;
  background-position: center;
  background-size: cover;
  border-radius: 4px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 55%);
  pointer-events: none;
  opacity: 0.9;
}

body.is-pointer-dragging,
body.is-pointer-dragging * {
  cursor: grabbing !important;
  user-select: none;
}

@media (hover: none) {
  .grid-cell-actions {
    opacity: 1;
  }
}

/* Rounded corners checkbox drives the chart tiles (no JS) */
body:has(.sidebar-options-rounded-corners-checkbox:checked) .main-grid {
  --tile-radius: 10px;
}

/* --------------------------------------------------------------------------
   Responsive
   -------------------------------------------------------------------------- */

@media (max-width: 1000px) {
  body {
    overflow-x: hidden;
    overflow-y: auto;
  }

  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    width: 100%;
    height: auto;
    max-height: none;
    min-height: 100dvh;
    overflow: visible;
  }

  .sidebar-container {
    order: 2;
    height: auto;
    padding: 10px;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    max-height: none;
  }

  .sidebar-header {
    display: none;
  }

  .sidebar-action {
    max-height: none;
    overflow-y: visible;
  }

  .main-container {
    order: 1;
    height: auto;
    padding: 20px 0;
    overflow: visible;
  }
}

@media (max-width: 600px) {
  .sidebar-addlvl-result {
    max-height: 35vh;
  }
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */

.gd-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  z-index: 100;
  max-width: min(90vw, 420px);
  padding: 10px 16px;
  color: #fff;
  font-size: 0.85rem;
  text-align: center;
  background: #141414;
  border: 1px solid #3c3c3c;
  border-radius: 6px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 45%);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition:
    opacity 0.18s ease-out,
    transform 0.18s ease-out;
}

.gd-toast--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   Reduced motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
