/* ===================================================================
   canvas.css — Collaborative pixel canvas page
   Builds on feed.css (linked first in canvas.html)
   =================================================================== */

body {
  background-image: none;
  overflow: hidden;
}

/* ===================================================================
   TOOLBAR (desktop: left strip; mobile: bottom strip)
   =================================================================== */

#toolbar {
  position: fixed;
  top: 4rem;
  left: 0;
  bottom: 0;
  width: 2.8rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 0.6rem;
  gap: 0.3rem;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 1px 0 4px rgba(0, 0, 0, 0.12);
  z-index: 10;
}

.tool-btn {
  width: 2.1rem;
  height: 2.1rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.tool-btn:hover  { background: rgba(0, 0, 0, 0.07); }
.tool-btn.active { background: rgba(165, 36, 34, 0.14); color: #A52422; }

.toolbar-sep {
  width: 1.6rem;
  height: 1px;
  background: rgba(0, 0, 0, 0.15);
  margin: 0.15rem 0;
  flex-shrink: 0;
}

/* Tool groups — give relative context for the floating sub-panels */
.tool-group {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Draw / shape sub-panels — float out perpendicular to toolbar */
#draw-sizes,
#shape-sizes {
  position: absolute;
  left: 100%;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  padding: 0.25rem 0.15rem;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.14);
  border-radius: 0 3px 3px 0;
  z-index: 11;
}

#draw-sizes[hidden],
#shape-sizes[hidden] { display: none; }

/* Shape preview overlay */
#shape-preview {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

.size-btn {
  width: 1.7rem;
  height: 1.7rem;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.size-btn:hover  { background: rgba(0, 0, 0, 0.07); }
.size-btn.active { background: rgba(165, 36, 34, 0.14); color: #A52422; }

/* Canvas wrap fills everything below the sticky header */
#canvas-wrap {
  position: fixed;
  top: 4rem;
  left: 2.8rem;
  right: 0;
  bottom: 0;
}

/* ===================================================================
   GOLDEN FRAME
   Positioned by JS to exactly wrap the canvas texture.
   Box-shadow spreads outward from the canvas edge.
   Cross-section per side (29 px total):
   canvas edge · 1 dark · 2 bright · 2 shadow · 2 highlight · 5 gold ·
   2 shadow · 1 deep groove · 2 shadow · 5 gold · 2 highlight · 2 shadow ·
   2 bright · 1 dark · outside
   =================================================================== */

#canvas-frame {
  position: absolute;
  pointer-events: none;
  z-index: 2;
  box-shadow:
    /* touching canvas: dark border */
    0 0 0 1px   #0E0600,
    /* bright gold line */
    0 0 0 3px   #E8C438,
    /* shadow edge */
    0 0 0 5px   #5A3600,
    /* bevel highlight */
    0 0 0 7px   #EDD050,
    /* gold face outer */
    0 0 0 12px  #C08A10,
    /* face shadow */
    0 0 0 14px  #6B4500,
    /* deep center groove */
    0 0 0 15px  #0A0500,
    /* face shadow */
    0 0 0 17px  #6B4500,
    /* gold face inner */
    0 0 0 22px  #C08A10,
    /* bevel highlight */
    0 0 0 24px  #EDD050,
    /* shadow edge */
    0 0 0 26px  #5A3600,
    /* bright gold line */
    0 0 0 28px  #E8C438,
    /* outer dark border */
    0 0 0 29px  #0E0600;
}

#viewport-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* ===================================================================
   UI OVERLAY (bottom-left)
   =================================================================== */

#ui-overlay {
  position: absolute;
  bottom: 1.25rem;
  left: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 10;
}

/* Color row */
#color-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.92);
  padding: 0.4rem 0.6rem;
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}

#color-swatch {
  width: 22px;
  height: 22px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  flex-shrink: 0;
  background: #1A1208;
  cursor: pointer;
}

/* Color picker popup */
#color-picker-popup {
  background: rgba(255, 255, 255, 0.96);
  border-radius: 4px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.22);
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  touch-action: none;
  user-select: none;
}

#color-picker-popup[hidden] { display: none; }

#color-wheel {
  display: block;
  cursor: crosshair;
  border-radius: 50%;
}

#picker-brightness {
  width: 148px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  outline: none;
  border: none;
  /* gradient set dynamically by JS */
  background: linear-gradient(to right, #000, #fff);
}

#picker-brightness::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid rgba(0, 0, 0, 0.35);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

#picker-brightness::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid rgba(0, 0, 0, 0.35);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

#color-field {
  width: 5.5em;
  font-family: 'Courier New', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  border: 1px solid rgba(0, 0, 0, 0.18);
  padding: 0.15rem 0.35rem;
  background: transparent;
  color: #000;
  outline: none;
}

#color-field:focus {
  border-color: #A52422;
}

/* Zoom row */
#zoom-row {
  display: flex;
  gap: 0.25rem;
}

.zoom-btn {
  width: 2rem;
  height: 2rem;
  background: rgba(255, 255, 255, 0.92);
  border: none;
  font-size: 1.1rem;
  font-family: inherit;
  cursor: pointer;
  border-radius: 2px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  transition: background 0.15s;
}

.zoom-btn:hover { background: rgba(255, 255, 255, 1); }

/* ===================================================================
   STATUS DISPLAYS
   =================================================================== */

/* Loading message — centered in canvas area */
#loading-msg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  font-family: spaceGrotesk, Helvetica, sans-serif;
  font-size: 0.55rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  pointer-events: none;
}

/* Cooldown countdown — bottom-right */
#cooldown-display {
  position: absolute;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 6;
  background: rgba(165, 36, 34, 0.88);
  color: #fff;
  font-family: spaceGrotesk, Helvetica, sans-serif;
  font-size: 0.55rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 0.3rem 0.7rem;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

#cooldown-display.active {
  opacity: 1;
}

#cooldown-display.flash {
  background: rgba(200, 60, 40, 0.95);
}

/* Pixel coordinates — top center */
#coords-display {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  background: rgba(0, 0, 0, 0.5);
  color: rgba(255, 255, 255, 0.85);
  font-family: 'Courier New', monospace;
  font-size: 0.65rem;
  padding: 0.15rem 0.55rem;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  white-space: nowrap;
}

/* Help hint — bottom center */
#canvas-hint {
  position: absolute;
  bottom: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  font-family: spaceGrotesk, Helvetica, sans-serif;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.25);
  pointer-events: none;
  white-space: nowrap;
}

/* ===================================================================
   DARK MODE OVERRIDES
   =================================================================== */

body.dark #toolbar {
  background: rgba(28, 35, 32, 0.95);
  box-shadow: 1px 0 4px rgba(0, 0, 0, 0.4);
}

body.dark .tool-btn {
  color: #ccc;
}

body.dark .tool-btn:hover  { background: rgba(255, 255, 255, 0.07); }
body.dark .tool-btn.active { background: rgba(165, 36, 34, 0.28); color: #e07070; }

body.dark #color-row {
  background: rgba(28, 35, 32, 0.95);
}

body.dark #color-picker-popup {
  background: rgba(28, 35, 32, 0.97);
}

body.dark #color-field {
  color: #e0e0e0;
  border-color: rgba(255, 255, 255, 0.18);
}

body.dark #color-field:focus {
  border-color: #A52422;
}

body.dark .zoom-btn {
  background: rgba(28, 35, 32, 0.95);
  color: #e0e0e0;
}

body.dark .zoom-btn:hover {
  background: rgba(40, 50, 45, 0.98);
}

body.dark .toolbar-sep {
  background: rgba(255, 255, 255, 0.12);
}

body.dark #draw-sizes,
body.dark #shape-sizes {
  background: rgba(28, 35, 32, 0.95);
  box-shadow: 2px 0 6px rgba(0, 0, 0, 0.4);
}

body.dark .size-btn { color: #ccc; }
body.dark .size-btn:hover  { background: rgba(255, 255, 255, 0.07); }
body.dark .size-btn.active { background: rgba(165, 36, 34, 0.28); color: #e07070; }

/* ===================================================================
   RESPONSIVE
   =================================================================== */

@media screen and (max-width: 480px) {
  #canvas-hint { display: none; }

  #toolbar {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: auto;
    min-height: 3.25rem;
    flex-direction: row;
    padding: 0.25rem 0.4rem;
    justify-content: center;
    gap: 0.6rem;
    box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.12);
  }

  #canvas-wrap {
    left: 0;
    bottom: 3.25rem; /* fallback; JS syncs to actual toolbar height */
  }

  #ui-overlay {
    bottom: 0.75rem; /* just above toolbar; canvas-wrap already clears it */
    left: 0.75rem;
  }

  .toolbar-sep {
    width: 1px;
    height: 1.6rem;
    margin: 0 0.1rem;
  }

  #draw-sizes,
  #shape-sizes {
    left: 50%;
    transform: translateX(-50%);
    top: auto;
    bottom: 100%;
    flex-direction: row;
    padding: 0.15rem 0.25rem;
    border-radius: 3px 3px 0 0;
    box-shadow: 0 -2px 6px rgba(0, 0, 0, 0.14);
  }
}

/* Two-row toolbar only for very narrow screens (≤320px) */
@media screen and (max-width: 320px) {
  #toolbar {
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.3rem 0.4rem;
    align-content: center;
  }

  /* Separator becomes a full-width horizontal rule, breaking items into two rows */
  .toolbar-sep {
    flex-basis: 100%;
    width: 100%;
    height: 1px;
    margin: 0.1rem 0;
  }
}

/* Landscape on small phones: wrapping column; JS adds .two-col only when items overflow */
@media screen and (orientation: landscape) and (max-height: 500px) {
  #toolbar {
    flex-wrap: wrap;
    align-content: space-around;
    gap: 0.2rem;
    padding: 0.3rem 0;
    overflow: visible;
  }

  /* JS sets this when items actually spill into a second column */
  #toolbar.two-col {
    width: 5.6rem;
  }

  /* Sub-panels: revert to desktop style (pop right), not mobile upward style */
  #draw-sizes,
  #shape-sizes {
    left: 100%;
    top: 0;
    bottom: auto;
    transform: none;
    flex-direction: column;
    border-radius: 0 3px 3px 0;
    box-shadow: 2px 0 6px rgba(0, 0, 0, 0.14);
    padding: 0.25rem 0.15rem;
  }
}
