:root {
  /* fallback until drawing.js measures the real available height */
  --max-canvas-height: 100%;
}

/* GAME PAGE */

main {
  background: transparent;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
}

#container {
  display: flex;
  flex-direction: column;
  overflow-x: auto;
}

/* CONTROLS BAR */

#controlls {
  background-color: var(--accent);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  flex-shrink: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#colors {
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}

.colors-row {
  display: flex;
  flex-direction: row;
}

.clr {
  height: 1em;
  aspect-ratio: 1;
}

#buttons {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-around;
  padding: 0.1em 0;
}

#buttons > div {
  height: 1.8em;
  display: flex;
}

.size {
  height: 100%;
  aspect-ratio: 1;
  border-radius: 0.5em;
  display: grid;
  justify-content: center;
  align-content: center;
}

.size-ball {
  background-color: black;
  border-radius: 50%;
  aspect-ratio: 1;
}

#controlls,
#buttons,
#buttons > div {
  gap: 0.2em;
}

#controlls .button {
  padding: 0 0.5em;
}

/* CANVAS */

#canvas-container {
  position: relative;
  overflow: hidden;
  border-radius: 0 0 0.5rem 0.5rem;
  max-width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Internal resolution stays 800x600; the displayed size is set explicitly by
   calculate_viewport_size_dependant_things() in drawing.js (largest 4:3 rect
   that fits), because coordinate calibration and PNG export depend on the
   untouched ratio. max-* here is only a safety net. */
#canvas {
  max-height: var(--max-canvas-height);
  max-width: 100%;
  background-color: var(--secondary);
  border-radius: 0 0 0.5rem 0.5rem;
  cursor: cell;
}

/* PAUSE OVERLAY (div is created by game.js on load) */

#paused-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10;
  display: none;
  border-radius: 0.5em;
}

.paused-state {
  opacity: 0.4;
  pointer-events: none;
}

/* LOBBY OVERLAY */

#lobby {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--shade);
  /* room-creation form (duration + word list + custom words) can exceed the
     canvas box on small screens: scroll within the overlay instead */
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#lobby > * {
  margin: 0.2em;
}

#room-creation {
  display: flex;
  flex-direction: column;
  gap: 0.5em;
  padding: 1em;
  align-items: center;
}

#room-creation .form-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3em;
  width: 100%;
}

#room-creation label {
  color: var(--secondary);
  font-size: 0.9em;
}

#room-creation select,
#room-creation input,
#room-creation textarea {
  padding: 0.4em;
  background: var(--background);
  color: var(--secondary);
  border: 0.15em solid var(--tertiary);
  border-radius: 0.3em;
  width: 100%;
  max-width: 250px;
}

#custom-words-input {
  height: 3em;
  resize: vertical;
}

#room-creation hr {
  width: 100%;
  border-color: var(--tertiary);
  margin: 0.5em 0;
}

#lobby-waiting {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5em;
  padding: 1em;
}

#lobby-waiting .room-id-display {
  font-size: 1.2em;
  font-weight: bold;
  color: var(--primary);
}

#start-game-btn {
  display: none;
}

/* CHAT / STATUS COLUMN */

#chat {
  display: flex;
  flex-direction: column;
  background-color: var(--accent);
  margin: 0.5em;
  padding: 0.2em;
  border: 0.2em solid var(--secondary);
  border-radius: 0.5em;
  min-height: 12em;
  /* word choices + fixed-size rows can exceed the column on small screens:
     scroll instead of pushing the chat inputs out of their border box */
  overflow-y: auto;
}

#chat > h2 {
  text-shadow: 2px 2px 2px var(--background);
}

#word-display {
  display: none;
  padding: 0.5em;
  margin: 0.3em;
  border: 0.2em solid var(--gold);
  border-radius: 0.3em;
  background: var(--background);
  font-size: 1.3em;
  font-weight: bold;
  text-align: center;
  color: var(--gold);
}

#scoreboard {
  margin: 0.3em;
  padding: 0.3em;
  border: 0.15em solid var(--secondary);
  border-radius: 0.3em;
  background: var(--accent);
  font-size: 0.85em;
}

#scoreboard .scores {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3em 0.8em;
}

#scoreboard .scores span {
  white-space: nowrap;
}

#timer-display {
  font-size: 1.2em;
  font-weight: bold;
  text-align: center;
  padding: 0.2em;
  background: var(--accent);
}

#timer-display:empty,
#word-hint:empty {
  display: none;
}

#word-hint {
  text-align: center;
  font-size: 1.4em;
  font-weight: bold;
  letter-spacing: 0.05em;
  padding: 0.3em;
  color: var(--primary);
}

#word-choices-area {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.3em;
  padding: 0.5em;
}

.word-choice-btn {
  display: block;
  width: 100%;
  padding: 0.8em;
  font-size: 1.2em;
  color: var(--secondary);
  background: var(--tertiary);
  border: 0;
  border-radius: 0.5em;
  font-weight: bold;
  text-transform: uppercase;
  cursor: pointer;
}

.word-choice-btn:hover {
  background: var(--secondary);
  color: var(--background);
}

#pause-resume-area {
  display: none;
  flex-direction: row;
  gap: 0.3em;
  justify-content: center;
  padding: 0.3em;
}

#pause-btn,
#resume-btn {
  display: none;
}

#game-over-area {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5em;
  padding: 1em;
}

#cycle-paused-area {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.5em;
  padding: 1em;
}

#chat-area {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#chat-text {
  display: flex;
  flex-direction: column;
  overflow: auto;
}

#chat-text > span {
  font-weight: bold;
}

#chat-inputs {
  border: 0.2em dashed var(--secondary);
  border-radius: 0.4em;
  min-height: 1.8rem;
  padding: 0.2em;
  display: flex;
  flex-direction: row;
  flex-shrink: 0; /* never let siblings squeeze it into overflow */
}

#chat-input {
  height: 100%;
  min-width: 0; /* allow the input to shrink instead of overflowing */
  border: 0;
  background-color: transparent;
  color: var(--secondary);
}

#chat-input:focus {
  outline: 0;
}

#chat-inputs > button {
  padding: 0 0.4em;
  flex-shrink: 0; /* SEND keeps its size — the input shrinks instead */
}

/* MEDIA QUERIES */

/* small phones */
@media screen and (max-width: 400px) {
  .clr {
    height: 0.6em;
  }
}

/* landscape phones through tablet landscape:
   compact vertical control panel beside the canvas, chat on the right */
@media screen and (orientation: landscape) and (max-width: 75em) {
  main {
    flex-direction: row;
  }

  #container {
    flex-direction: row;
    flex: 1 1 auto;
    min-width: 0;
    justify-content: flex-start;
  }

  #chat {
    flex: 0 0 11em;
    min-height: 0;
  }

  #controlls {
    flex: 0 0 auto;
    flex-direction: row;
    align-items: flex-start;
    align-content: flex-start;
    overflow-y: auto;
    border-radius: 0.5em 0 0 0.5em;
  }

  /* compact panel: single letters instead of full labels
     (overrides base.css, which flips these the other way at >=56.25em) */
  .button > .big {
    display: none;
  }

  .button > .small {
    display: block;
  }

  #colors {
    display: flex;
    flex-direction: row;
    overflow: visible;
  }

  .colors-row {
    flex-direction: column;
    width: 1em;
  }

  #buttons {
    flex: 0 0 auto;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-content: flex-start;
    width: 3.8em;
    padding: 0;
  }

  #buttons > div {
    flex-direction: column;
    width: 1.8em;
    height: auto;
  }

  .size {
    width: 100%;
  }

  #canvas-container {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    border-radius: 0 0.5em 0.5em 0;
  }

  #canvas {
    max-height: 100%;
    border-radius: 0 0.5em 0.5em 0;
  }
}

/* short landscape (phones): smaller root font to fit the tiny height;
   drawing.js recalibrates on orientationchange/resize */
@media screen and (orientation: landscape) and (max-height: 32em) {
  html {
    font-size: 1.1em;
  }
}

/* PC */
@media screen and (min-width: 75em) {
  main {
    flex-direction: row;
  }

  #controlls {
    border-radius: 0.5em 0.5em 0 0;
  }
}
