:root {
  color-scheme: dark;
  --canvas-color: #05070a;
}

body {
  background:
    radial-gradient(circle at 15% 10%, rgba(255, 49, 88, .13), transparent 25rem),
    radial-gradient(circle at 85% 90%, rgba(45, 125, 255, .15), transparent 28rem),
    #10141d;
}

.free-draw-shell {
  width: min(100%, 90rem);
  padding: max(.65rem, env(safe-area-inset-top)) .75rem max(.65rem, env(safe-area-inset-bottom));
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: .55rem;
}

.game-header {
  min-height: 3.25rem;
  border-color: rgba(255, 255, 255, .16);
}

.game-header h1 { color: #fff; }

.back-link,
.icon-button,
.action-button {
  border-color: rgba(255, 255, 255, .82);
  background: #1b2130;
  color: #fff;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .35);
}

.back-link {
  width: 2.75rem;
  height: 2.75rem;
}

.canvas-toggle {
  min-height: 2.75rem;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .35rem .65rem;
  font-size: .76rem;
}

.toggle-swatch {
  width: 1rem;
  height: 1rem;
  border: 1px solid rgba(255, 255, 255, .65);
  border-radius: 50%;
  background: #fff;
}

.canvas-toggle[aria-pressed="true"] .toggle-swatch {
  border-color: #fff;
  background: #05070a;
}

.draw-toolbar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .65rem;
  padding: .4rem .6rem;
  border: 1px solid rgba(255, 255, 255, .14);
  border-radius: .8rem;
  background: rgba(27, 33, 48, .82);
}

.draw-toolbar p {
  margin: 0;
  color: rgba(255, 255, 255, .7);
  font-size: .66rem;
  font-weight: 900;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.color-options {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(.32rem, 1.2vw, .55rem);
}

.color-button {
  width: clamp(2.1rem, 6vw, 2.75rem);
  height: clamp(2.1rem, 6vw, 2.75rem);
  flex: none;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--pen-color);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .3);
}

.color-button.rainbow {
  display: grid;
  place-items: center;
  background: conic-gradient(#ff3158, #ffdb1f, #24e17a, #2d7dff, #a44fff, #ff4fe1, #ff3158);
  color: #fff;
  font-size: 1.1rem;
  text-shadow: 0 1px 3px #000;
}

.color-button.selected {
  outline: 3px solid #fff;
  outline-offset: 3px;
  transform: scale(.86);
}

.color-button:focus-visible,
.canvas-toggle:focus-visible,
.draw-actions .action-button:focus-visible {
  outline: 3px solid #ffdb1f;
  outline-offset: 3px;
}

.draw-stage {
  width: 100%;
  min-height: 0;
  place-items: stretch;
}

.canvas-frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, .75);
  border-radius: .85rem;
  background: var(--canvas-color);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
}

#drawing-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

.canvas-hint {
  position: absolute;
  inset: 50% auto auto 50%;
  margin: 0;
  color: rgba(255, 255, 255, .22);
  font: 800 clamp(1rem, 4vw, 2rem)/1 Georgia, "Times New Roman", serif;
  letter-spacing: .04em;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity .2s ease;
  white-space: nowrap;
}

.canvas-frame.white .canvas-hint { color: rgba(23, 50, 77, .22); }
.canvas-frame.has-drawing .canvas-hint { opacity: 0; }

.draw-actions { gap: .55rem; }
.draw-actions .action-button { min-height: 2.8rem; flex: 0 1 10rem; }
.draw-actions .primary { border-color: #fff; background: linear-gradient(135deg, #ffdb1f, #ff8a1f); color: #10141d; }

@media (max-width: 440px) {
  .free-draw-shell { padding-inline: .5rem; }
  .draw-toolbar { gap: .35rem; padding-inline: .35rem; }
  .color-options { gap: .3rem; }
  .color-button { width: min(10vw, 2.35rem); height: min(10vw, 2.35rem); border-width: 2px; }
  .color-button.selected { outline-width: 2px; outline-offset: 2px; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .free-draw-shell {
    width: 100%;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: auto minmax(0, 1fr);
    gap: .5rem;
  }

  .game-header {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .draw-toolbar {
    grid-column: 1;
    grid-row: 2;
    flex-direction: column;
    align-self: stretch;
  }

  .color-options { flex-direction: column; }

  .draw-stage {
    grid-column: 2;
    grid-row: 2;
  }

  .draw-actions {
    grid-column: 3;
    grid-row: 2;
    flex-direction: column;
  }

  .draw-actions .action-button {
    min-width: 5.4rem;
    min-height: 0;
    flex: 1 1 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .canvas-hint { transition: none; }
}
