* {
  box-sizing: border-box;
}

html, body {
  height: 100vh;
  margin: 0;
}

#container {
  display: flex;
  flex-flow: column;
  height: 100%;
}

#menu {
  background-color: black;
  flex: 0 1 auto;
  position: sticky;
  top: 0;
  display: flex;
  padding-right: 10px;
  z-index: 100;
}

#menu button {
  flex: 1 1;
  height: 4em;
  margin: 10px 0px 10px 10px;
}

#menu button.selected {
  background-color: yellow;
  border-color: gold;
}

#content {
  flex: 1 1 auto;
  min-height: 0;
  container: content / size;
}

.page:not(.selected) {
  display: none;
}

.page {
  --page-margin: 2vmin;
  padding: var(--page-margin);
}

.page.flex.selected {
  display: flex;
  flex-flow: column;
  height: 100%;
}

#chat .chat-input {
  flex: 0 1 auto;
  margin: var(--page-margin) 0 0;
}

#chat-messages {
  flex: 1 1 auto;
  overflow: auto;
  word-wrap: break-word;
  scroll-behavior: smooth;
  padding: 0 var(--page-margin);
  border: 1px solid black;
}

#game.selected  {
  display: grid;
  height: 100%;
  gap: var(--page-margin);
}

#board {
  aspect-ratio: 1/1;
  height: 100%;
  grid-area: b;
}

canvas.board {
  height: 100%;
  width: 100%;
  position: absolute;
}

#left {
  background-color: red;
  grid-area: l;
}

#right {
  background-color: blue;
  grid-area: r;
}

@media (orientation: landscape) {
  #container {
    flex-flow: row;
  }

  #menu {
    flex-flow: column;
    width: min-content;
    padding: 0 0 10px 0;
  }

  #menu button {
    margin: 10px 10px 0 10px;
  }

  #rules {
    height: 100%;
    overflow: auto;
  }
}

@container content (aspect-ratio > 2) {
  #game.selected {
    grid-auto-columns: 1fr max-content 1fr;
    grid-template-areas: 
      'l b r';
    grid-auto-rows: 100%;
  }
}

@container content (5/4 < aspect-ratio <= 2) {
  #game.selected {
    grid-template-columns: max-content auto;
    grid-auto-rows: 1fr;
    height: 100%;
    grid-template-areas: 
      'b l'
      'b r';
  }
}

@container content (1 < aspect-ratio <= 5/4) {
  #game.selected {
    grid-auto-columns: 3fr 4fr;
    grid-template-areas: 
      'l b'
      'r r';
    grid-auto-rows: 1fr;
    height: 100%;
  }
}

@container content (3/4 < aspect-ratio <= 1) {
  #game.selected {
    grid-auto-columns: 3fr 4fr;
    grid-template-areas: 
      'l b'
      'l r';
    grid-auto-rows: 1fr;
    height: 100%;
  }
}

@container content (1/2 < aspect-ratio <= 3/4) {
  #game.selected {
    grid-template-rows: max-content 1fr;
    grid-auto-columns: 1fr;
    width: 100%;
    grid-template-areas: 
      'b b'
      'l r';
  }

  #board {
    width: 100%;
    height: unset;
  }
}

@container content (aspect-ratio <= 1/2) {
  #game.selected {
    grid-template-rows: max-content 1fr 1fr;
    grid-template-areas: 
      'b'
      'l'
      'r';
    grid-auto-columns: 100%;
  }

  #board {
    width: 100%;
    height: unset;
  }
}