:root {
  /* Dark Mode Palette */
  --bg-chassis: #0b0d11;
  --panel-header-bg: #222630;
  --panel-system-bg: #101217;
  --panel-card-bg: #1e222a;
  --panel-canvas-bg: #12141a;
  --panel-palette-bg: #161920;
  --border-dark: #2a303c;
  --picto-blue: #6366f1;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --system-yellow: #facc15;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  background-color: var(--bg-chassis);
  font-family: "Courier New", monospace, monospace;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 24px;
  color: var(--text-main);
}

/* Screen Housing Frame: Maximized horizontal space */
.ds-housing {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-width: 1600px;
}

@media (min-width: 860px) {
  .ds-housing {
    flex-direction: row;
    align-items: stretch;
  }
  .screen-column {
    flex: 1;
    min-width: 0;
  }
}

.screen-column {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

/* ====================================================
   SCROLLING CHAT STREAM & BANNERS
==================================================== */
.chat-stream {
  flex: 1;
  min-height: 420px;
  max-height: 680px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 6px;
}

.stream-item {
  width: 100%;
  flex-shrink: 0;
}

/* Header Bar 3D Panel */
panel-3d.header-bar-panel::part(surface) {
  padding: 8px 14px;
}

.header-bar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #f8fafc;
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 0.95rem;
}

/* System Banner 3D Panel */
panel-3d.system-banner-panel::part(surface) {
  padding: 8px 12px;
}

.system-banner-content {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: #e2e8f0;
}

.room-badge {
  background: var(--system-yellow);
  color: #000000;
  font-weight: bold;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.78rem;
}

/* Message Card 3D Panel */
panel-3d.message-card-panel::part(surface) {
  padding: 6px;
}

/* ====================================================
   CANVAS FRAMES & INLINE NAMEPLATE OVERLAY
==================================================== */
.message-canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 228 / 80;
  background: #ffffff;
  border-radius: 4px;
  overflow: hidden;
  user-select: none;
}

.message-canvas-wrap canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* Drawing Canvas Container */
panel-3d.canvas-panel::part(surface) {
  padding: 6px;
}

.canvas-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 228 / 80;
  background: #ffffff;
  border-radius: 4px;
  overflow: hidden;
  cursor: crosshair;
  touch-action: none;
}

#drawing-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  display: block;
}

/* Top Canvas Overlay: Name Tag on the left, Text on the right */
.canvas-text-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 3;
}

/* 3D Name Tag Panel with Exaggerated Bottom-Right Bevel */
panel-3d.name-tag-panel {
  flex-shrink: 0;
  height: 28px;
  pointer-events: auto;
  align-self: flex-start;
}

panel-3d.name-tag-panel::part(surface) {
  min-height: 0;
  height: 100%;
  padding: 0 14px 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-bottom-right-radius: 18px !important;
}

.name-tag-label {
  font-size: 0.85rem;
  font-weight: bold;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}

.name-tag-label .instance-tag {
  font-size: 0.72rem;
  opacity: 0.75;
}

/* Live Inline Canvas Text Input */
.canvas-text-input {
  flex: 1;
  height: 26px;
  background: transparent;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: #000000;
  padding: 0 8px 0 0;
  margin: 0;
  pointer-events: auto;
  caret-color: #2563eb;
  user-select: text;
}

/* Static Rendered Message Text in Stream */
.message-overlay-text {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  color: #000000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 6px;
}

/* ====================================================
   HORIZONTAL ROWS (PANEL ON LEFT + BUTTON ON RIGHT)
==================================================== */
.tray-row-container {
  display: flex;
  align-items: stretch;
  gap: 12px;
  width: 100%;
}

.tray-row-container panel-3d.tools-panel,
.tray-row-container panel-3d.palette-panel {
  flex: 1;
  min-width: 0;
  height: 60px;
}

panel-3d.tools-panel::part(surface),
panel-3d.palette-panel::part(surface) {
  height: 100%;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

button-3d.row-action-btn {
  flex: 0 0 80px;
  width: 80px;
  height: 60px;
}

button-3d.row-action-btn::part(surface) {
  min-height: 0;
  height: 100%;
  width: 100%;
  padding: 0;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Tools Scroller Inside Tools Panel */
.tools-scroller {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: 100%;
  height: 100%;
}

button-3d.tool-btn {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  border-radius: 8px;
  transition: transform 0.2s cubic-bezier(0.34, 1.4, 0.64, 1);
}

button-3d.tool-btn::part(surface) {
  min-height: 0;
  height: 100%;
  width: 100%;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

button-3d.tool-btn .tool-svg {
  width: 18px;
  height: 18px;
  color: #f1f5f9;
  pointer-events: none;
}

button-3d.tool-btn.active {
  transform: scale(1.15);
  z-index: 4;
}

/* Palette Scroller Inside Palette Panel */
.palette-scroller {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  overflow: visible;
}

@media (max-width: 720px) {
  .palette-scroller {
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .palette-scroller::-webkit-scrollbar {
    display: none;
  }

  .tools-scroller {
    justify-content: flex-start;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tools-scroller::-webkit-scrollbar {
    display: none;
  }
}

/* 3D Palette Swatches */
button-3d.palette-swatch-btn {
  flex: 0 0 26px;
  width: 26px;
  height: 26px;
  aspect-ratio: 1 / 1;
  cursor: pointer;
  border-radius: 6px;
  transform-origin: center center;
  transition: transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
}

button-3d.palette-swatch-btn::part(surface) {
  min-height: 0;
  height: 100%;
  width: 100%;
  padding: 0;
}

button-3d.palette-swatch-btn.shift-left {
  transform: translateX(-10px) scale(1);
}

button-3d.palette-swatch-btn.shift-right {
  transform: translateX(10px) scale(1);
}

button-3d.palette-swatch-btn.active {
  transform: translateX(0) scale(1.5);
  z-index: 5;
}