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

:root {
  color-scheme: light dark;
  --c-blue: #232cf4;
  --c-white: #fcfdf7;

  --c-bg: light-dark(var(--c-white), var(--c-blue));
  --c-onBg: light-dark(var(--c-blue), var(--c-white));

  --c-interactive: light-dark(var(--c-blue), var(--c-white));
  --c-onInteractive: light-dark(var(--c-white), var(--c-blue));

  --grid-size: calc(100vmin / 15);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 100;
}

p {
  line-height: 1.6;
  max-width: 40ch;
}

p + p {
  margin-top: var(--grid-size);
}

a {
  color: var(--c-interactive);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  text-decoration-skip-ink: none;
  position: relative;
}

a:hover, a:focus {
  text-underline-offset: 1px;
}

::selection {
  background: var(--c-interactive);
  color: var(--c-onInteractive);
}

body {
  background: var(--c-bg);
  color: var(--c-onBg);
  font-family: 'Iosevka Web', 'Iosevka', 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

.layout {
  display: flex;
  flex-wrap: wrap;
}

.app {
  max-width: 100vmin;
  flex: 0 0 100vmin;
}

/* Top bar */
.top-bar {
  display: flex;
  gap: 1px;
  margin-bottom: 1px;
  height: var(--grid-size);
  position: relative;
  z-index: 2;
  margin-bottom: calc(var(--grid-size) * -1);
  border-bottom: 1px solid var(--c-interactive);
  border-right: 1px solid var(--c-interactive);
  background: var(--c-interactive);
}

.top-bar__button {
  display: block;
  background: var(--c-onInteractive);
  border: none;
  color: var(--c-interactive);
  font-family: inherit;
  width: calc(var(--grid-size) - 3px);
  flex: 0 0 calc(var(--grid-size) - 3px);
  cursor: pointer;
  font-size: 0;
}

.top-bar__button::after {
  display: block;
  content: '⌵';
  font-size: 1.2rem;
  transform: translateY(-0.1em);
}

/* Search */
.search {
  display: block;
  background: var(--c-onInteractive);
  border: none;
  color: var(--c-interactive);
  font-family: inherit;
  padding: 0 1rem;
  flex: 1 1 auto;
  outline: none;
}

.search::placeholder {
  color: var(--c-interactive);
}

.search:focus {
  background: var(--c-onInteractive);
  color: var(--c-interactive);
}

/* Voxel grid background */
.voxel-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.voxel-grid svg {
  width: 100%;
  height: 100%;
}

/* Grid stack */
.grid-stack {
  position: relative;
  width: 100%;
  container-type: inline-size;
  border-bottom: 1px solid var(--c-interactive);
  border-right: 1px solid var(--c-interactive);
}

.grid-stack:has(.grid:not(.grid--free)) {
  aspect-ratio: 1;
}

/* Grid */
.grid {
  position: relative;
  z-index: 1;
  font-family: 'Noto Sans', 'Noto Sans CJK', 'Noto Sans Arabic', 'Noto Sans Devanagari', system-ui, sans-serif;
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 1px;
  height: 70%;
  aspect-ratio: 1;
  container-type: inline-size;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--c-interactive);
  box-shadow: 0 0 0 1px var(--c-interactive);
}

.grid--free {
  height: auto;
}

.grid--free .cell {
  aspect-ratio: 1;
}

/* Cell */
.cell {
  --rank: 0.5;
  position: relative;
  cursor: pointer;
  user-select: none;
  overflow: hidden;
  background: var(--c-bg);
  color: var(--c-onBg);
}

.cell--close {
  background: var(--c-interactive);
  color: var(--c-onInteractive);
  outline: 1px solid var(--c-onInteractive);
}

.cell--close:hover {
  transform: scale(1.5);
  outline: 1px solid var(--c-onInteractive);
  outline-offset: -1px;
  z-index: 1;
}

.cell:hover {
  opacity: 1;
}

.cell:hover .cell__char {
  transform: scale(1);
}

.cell--far {
  background: var(--c-bg);
}

.cell--empty {
  pointer-events: none;
}

.cell__char {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4cqi;
  text-align: center;
  line-height: 1;
  transform: scale(calc((1 - var(--rank))));
}

/* Drawboard */
.drawboard {
  width: calc(var(--grid-size) - 3px);
  height: calc(var(--grid-size) - 1px);
  position: relative;
}
.drawboard__canvas {
  width: 100%;
  height: 100%;
  background: var(--c-onInteractive);
  cursor: crosshair;
  display: block;
}

.drawboard__label {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--c-interactive);
  pointer-events: none;  
  font-size: 2rem;
}

.drawboard:hover .drawboard__label,
.drawboard:has(.drawboard__canvas--drawn) .drawboard__label {
  display: none;
}

.about {
  max-width: 100%;
  padding: 0 var(--grid-size) var(--grid-size);
  h1 {
    margin-bottom: var(--grid-size);
    letter-spacing: -0.08em;
    line-height: 1;
  }
}

.about__footer {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.about__settings {
  display: inline-flex;
  align-items: center;
  gap: 1px;
  flex-wrap: wrap;
  margin-top: var(--grid-size);
  margin-bottom: calc(var(--grid-size) * 0.75);
  font-style: normal;
  border: 1px solid var(--c-interactive);
  background: var(--c-interactive);
}

.model-picker {
  display: flex;
  align-items: center;
  gap: 1px;
  font-size: 11px;

}

.model-picker__select {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0 1rem;
  
  height: var(--grid-size);
  width: calc(var(--grid-size) * 2);
  background-color: var(--c-onInteractive);
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position:
    calc(100% - 0.9rem) calc(50% - 0.12rem),
    calc(100% - 0.6rem) calc(50% - 0.12rem);
  background-size: 0.3rem 0.3rem, 0.3rem 0.3rem;
  background-repeat: no-repeat;
}

.model-picker__select:hover,
.model-picker__select:focus-visible {
  background-color: var(--c-interactive);
  color: var(--c-onInteractive);
  outline: none;
}

.sound-toggle {
  appearance: none;
  border: none;
  background: var(--c-onInteractive);
  color: var(--c-interactive);
  font: inherit;
  line-height: 1;
  cursor: pointer;
  width: var(--grid-size);
  height: var(--grid-size);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.sound-toggle:hover,
.sound-toggle:focus-visible {
  background: var(--c-interactive);
  color: var(--c-onInteractive);
}


/* Info */
.info {
  display: flex;
  align-items: center;
  font-size: 11px;
  line-height: 1.6;
  padding: var(--grid-size);
}

.info__char {
  flex: 0 0 var(--grid-size);
  width: var(--grid-size);
  height: var(--grid-size);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--c-interactive);
  font-size: calc(var(--grid-size) * 0.7);
  line-height: 1;
  margin-right: 1.5rem;
  font-family: 'Noto Sans', 'Arial Unicode MS', 'Helvetica', sans-serif;
  box-sizing: border-box;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.1s;
}

.info__char:active {
  background: var(--c-interactive);
  color: var(--c-bg);
}

.info__data {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.info__codepoint {
  color: light-dark(#555, #777);
}


/* Tags panel */
.tags {
  display: none;
  max-height: 50vh;
  overflow-y: auto;
  margin-top: var(--grid-size);
  border-bottom: 1px solid var(--c-onInteractive);
}

:root.tags-open .tags {
  display: block;
}

.top-bar__button--active {
  background: var(--c-onInteractive);
  color: var(--c-interactive);
}

/* Categories */

.categories__list {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  font-size: 11px;
}

.categories__item {
  height: var(--grid-size);
  display: flex;
  align-items: center;
  gap: 2ch;
  padding: 0 1em;
  cursor: pointer;
  white-space: nowrap;
  background: var(--c-interactive);
  color: var(--c-onInteractive);
  border: none;
  flex: 1 1 auto;
  justify-content: space-between;
}

.categories__item:hover {
  background: var(--c-onInteractive);
  color: var(--c-interactive);
}

.categories__name {
  color: inherit;
}

.categories__count {
  opacity: 0.5;
  font-size: 0.9em;
}

/* Breadcrumbs */
.breadcrumb {
  display: flex;
  font-family: inherit;
  font-size: 1rem;
  color: var(--c-interactive);
  white-space: nowrap;
  align-items: center;
  margin-left: -1px;
  width: calc(100% + 2px);
  margin-top: calc(var(--grid-size) * -1);
  position: relative;
  z-index: 2;
}

.breadcrumb__crumb {  
  display: block;
  appearance: none;
  background: none;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  padding: 0.1rem 0.3rem;
  box-sizing: border-box;
  user-select: none;
  width: calc(100% / 15);
  flex: 0 0 calc(100% / 15);
  aspect-ratio: 1;
  color: var(--c-interactive);
}

.breadcrumb__crumb--filled {
  color: var(--c-onInteractive);
}
