:root {
  --deep-blue: #3c2c9c;
  --grassland-green: #4a824a;
  --dark-grassland-green: #448644;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  display: grid;
  overflow: hidden;
  padding: 2rem;

  background-image: url(images/waves.png);
  background-color: #46a4b5;
}

game-app {
  display: grid;
  align-items: center;
  grid-template:
    "left center right"
    / minmax(0, 1fr) auto minmax(0, 1fr);

  height: 100%;
}

game-ui {
  grid-area: left;
  display: grid;
  align-content: start;
  gap: 1rem;
}

#inventory {
  display: grid;
  gap: 0.5rem;
}

#inventory-items {
  display: grid;
  gap: 0.45rem;
}

.inventory-item {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  column-gap: 0.55rem;
  row-gap: 0.15rem;
  max-width: 20rem;
  padding: 0.35rem 0.6rem;
  border-radius: 0.8rem;
  background: rgb(255 255 255 / 0.84);
  color: #17313b;
}

.inventory-item-emoji {
  font-size: 1.15rem;
  line-height: 1;
}

.inventory-item-name {
  font-weight: 700;
}

.inventory-item-category {
  grid-column: 2;
  font-size: 0.78rem;
  line-height: 1.2;
  text-transform: capitalize;
  color: color-mix(in srgb, #17313b 60%, white);
}

game-board {
  grid-area: center;
  --tile-size: 3rem;
  font-size: clamp(1rem,
      /* min */
      calc(var(--tile-size) * 0.5),
      /* preferred */
      calc(var(--tile-size) * 0.7)
      /* max */
    );
  /* line-height: 1; */

  display: grid;
  grid-template-columns: repeat(var(--column-count), 1fr);
  grid-template-rows: repeat(var(--row-count), 1fr);
  aspect-ratio: var(--column-count) / var(--row-count);

  width: min(calc(100dvw - 4rem),
      calc((100dvh - 4rem) * (var(--column-count) / var(--row-count))));
  height: auto;
  max-width: 100%;
  max-height: 100%;
  place-self: center;
  background: var(--grassland-green);
  position: relative;
}

terrain-layer,
avatar-layer,
effect-layer {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 1 / -1;
  width: 100%;
  height: 100%;
}

terrain-layer,
avatar-layer {
  grid-template-columns: subgrid;
  grid-template-rows: subgrid;
}

effect-layer {
  position: relative;
  pointer-events: none;
  overflow: hidden;
}

game-cell {
  --terrain-base-lightness-1: 62%;
  --terrain-base-lightness-2: 54%;
  --terrain-base-chroma-1: 0.13;
  --terrain-base-chroma-2: 0.11;
  --terrain-base-hue-1: 132deg;
  --terrain-base-hue-2: 128deg;
  --terrain-lightness-delta: 0%;
  --terrain-chroma-delta: 0;
  --terrain-hue-delta: 0deg;
  background-color:
    oklch(
      calc(var(--terrain-base-lightness-1) + var(--terrain-lightness-delta))
      calc(var(--terrain-base-chroma-1) + var(--terrain-chroma-delta))
      calc(var(--terrain-base-hue-1) + var(--terrain-hue-delta))
    );
  aspect-ratio: 1;
  display: grid;
  place-content: center;
  outline: 1px solid white;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-height: 0;
}

.avatar {
  position: relative;
  display: grid;
  place-content: center;
  height: 100%;
  width: 100%;
  overflow: visible;
  z-index: 2;
}

.avatar-emoji {
  position: static;
  font-size: calc(var(--tile-size) * 0.78);
  line-height: 1;
  max-inline-size: 100%;
  max-block-size: 100%;
}


player-avatar {
  display: grid;
  font-size: 1rem;
  grid-template: repeat(5, 1fr) / repeat(5, 1fr);
  aspect-ratio: 1;
  z-index: 2;
}

player-avatar .avatar-emoji {
  grid-area: 2 / 2 / 5 / 5;
  display: grid;
  place-content: center;
}

player-avatar .emotion-badge {
  grid-area: 1 / 1 / 4 / 4;
  font-size: calc(var(--tile-size) * 0.45);
  rotate: -12deg;
  position: relative;
  left: -.4em;
  display: grid;
  place-content: center;
  transform-origin: center;
}


.avatar[hidden] {
  display: none;
}

.emote-effect {
  position: absolute;
  transform: translate(-50%, -50%);
  z-index: 4;
  will-change: transform, opacity;
}

speech-bubble.avatar-speech-bubble {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: calc(100% + 0.5rem);
  transform: translateX(-50%);
  display: inline-block;
  inline-size: max-content;
  max-inline-size: min(18rem, 60vw);
  padding: 0.7rem 0.9rem;
  border: 2px solid color-mix(in srgb, black 75%, #734b2b 25%);
  border-radius: 1rem;
  background: white;
  color: #1e1e1e;
  font: 600 clamp(0.85rem, 0.55rem + 0.7vw, 1rem) / 1.35 ui-rounded, "SF Pro Rounded", "Hiragino Maru Gothic ProN", sans-serif;
  box-shadow: 0 0.7rem 1.8rem rgb(0 0 0 / 0.18);
  z-index: 5;
}

speech-bubble.avatar-speech-bubble[hidden] {
  display: none !important;
}

speech-bubble.avatar-speech-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  width: 0.85rem;
  height: 0.85rem;
  background: white;
  border-right: 2px solid color-mix(in srgb, black 75%, #734b2b 25%);
  border-bottom: 2px solid color-mix(in srgb, black 75%, #734b2b 25%);
  transform: translateX(-50%) rotate(45deg);
}

speech-bubble.avatar-speech-bubble::after {
  top: -0.5rem;
  transform: translateX(-50%) rotate(225deg);
}

speech-bubble.avatar-speech-bubble .word {
  display: inline;
  white-space: normal;
}

speech-bubble.avatar-speech-bubble .letter {
  display: inline-block;
}

.admin-launch {
  justify-self: start;
  border: 1px solid rgb(0 0 0 / 0.2);
  border-radius: 999px;
  background: rgb(255 255 255 / 0.92);
  color: #123;
  padding: 0.55rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

.admin-dialog {
  width: min(72rem, calc(100vw - 3rem));
  max-height: min(85dvh, 52rem);
  border: none;
  border-radius: 1rem;
  margin: auto;
  padding: 0;
  background: #f8fbfd;
  color: #123;
  box-shadow: 0 1.4rem 4rem rgb(0 0 0 / 0.28);
}

.admin-dialog::backdrop {
  background: rgb(0 0 0 / 0.3);
}

.admin-shell {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.admin-close {
  border: 1px solid rgb(0 0 0 / 0.16);
  border-radius: 999px;
  background: white;
  padding: 0.45rem 0.75rem;
  font: inherit;
}

.admin-field {
  display: grid;
  gap: 0.35rem;
}

.admin-field span {
  font-weight: 600;
}

.admin-field select {
  width: fit-content;
  min-width: 16rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid #c7ced6;
  border-radius: 0.5rem;
  background: white;
  font: inherit;
}

.admin-catalogs {
  display: grid;
  gap: 0.75rem;
}

.admin-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.admin-tab {
  border: 1px solid #c7ced6;
  border-radius: 999px;
  background: #fff;
  color: #234;
  padding: 0.45rem 0.8rem;
  font: inherit;
  cursor: pointer;
}

.admin-tab[aria-selected="true"] {
  background: #234;
  color: #fff;
  border-color: #234;
}

.admin-panel,
.admin-data {
  border: 1px solid #d6dde6;
  border-radius: 0.75rem;
  background: #fbfcfe;
  padding: 1rem;
}

.admin-summary {
  color: #5a6573;
  margin-bottom: 0.75rem;
}

.tree {
  font-family: monospace;
  font-size: 0.95rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-family: monospace;
  font-size: 0.92rem;
  background: white;
}

th,
td {
  padding: 0.45rem 0.6rem;
  border: 1px solid #d6dde6;
  text-align: left;
  vertical-align: top;
}

th {
  background: #eef3f8;
  position: sticky;
  top: 0;
}

details {
  margin-left: 1rem;
}

summary {
  cursor: pointer;
}

.leaf {
  margin-left: 2rem;
  padding: 0.1rem 0;
}

.key {
  font-weight: bold;
}

.type {
  color: #666;
}

.string {
  color: #0a5;
}

.number {
  color: #06c;
}

.boolean {
  color: #a50;
}

.null {
  color: #999;
  font-style: italic;
}
