@import url("./styles/animations.css");
@import url("./styles/fonts.css");

:root {
  --bg-color: #1a1a24;
  --panel-bg: rgba(30, 30, 40, 0.6);
  --panel-border: rgba(255, 255, 255, 0.1);
  --text-color: #eee;
  --accent-color: #4f46e5;
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
  --glass-blur: blur(12px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', 'Roboto', sans-serif;
  background: radial-gradient(circle at top right, #2b1055, #000000);
  background-attachment: fixed;
  color: var(--text-color);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  transition: background 0.5s ease, color 0.5s ease;
}

body.light-mode {
  --bg-color: #f0f0f5;
  --panel-bg: rgba(255, 255, 255, 0.85);
  --panel-border: rgba(0, 0, 0, 0.1);
  --text-color: #333;
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
  background: radial-gradient(circle at top right, #e0eaf5, #ffffff);
}

body.light-mode button {
  background: rgba(0, 0, 0, 0.05);
  color: #333;
}

body.light-mode button:hover {
  background: rgba(0, 0, 0, 0.1);
}

body.light-mode .message-box {
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

body.light-mode .message-header {
  background: rgba(0, 0, 0, 0.03);
}

body.light-mode #toolbar {
  background: rgba(0, 0, 0, 0.05);
}

body.light-mode .toolbar-divider {
  background: rgba(0, 0, 0, 0.1);
}

body.light-mode #toolbar button img {
  filter: invert(0);
}

body.light-mode .system-message-box {
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.1);
  color: #555;
}

body.light-mode .swatch {
  border: 2px solid rgba(0,0,0,0.2);
}

body.light-mode .swatch.active-swatch {
  border-color: black;
  box-shadow: 0 0 8px rgba(0,0,0,0.5);
}

body.light-mode input[type="color"]::-webkit-color-swatch {
  border: 2px solid rgba(0,0,0,0.2);
}

/* Stream mode for OBS */
body.stream-mode {
  background: transparent !important;
}

body.stream-mode .container {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

body.stream-mode #user-message-form {
  display: none !important;
}

body.stream-mode #chat-log {
  flex: 1;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.stream-mode #chat-log::-webkit-scrollbar {
  display: none; /* Hide scrollbar for clean stream output */
}

.container {
  display: flex;
  flex-direction: column-reverse;
  width: 90vw;
  height: 90vh;
  padding: 10px;
  gap: 15px;
}

@media (min-width: 768px) {
  .container {
    flex-direction: row;
    padding: 20px;
  }
}

/* Glassmorphism panels */
#chat-log, #user-message-form {
  background: var(--panel-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--glass-shadow);
  padding: 15px;
}

#chat-log {
  flex: 1;
  display: flex;
  flex-direction: column-reverse;
  gap: 15px;
  overflow-y: auto;
}

#user-message-form {
  display: flex;
  flex-direction: column;
  gap: 15px;
  transition: all 0.3s ease;
}

@media (min-width: 768px) {
  #user-message-form {
    flex: 2; /* Take up more space */
    max-width: 800px;
  }
}

/* Fullscreen mode for drawing */
body.fullscreen-mode #user-message-form {
  position: fixed;
  top: 5vh;
  left: 5vw;
  width: 90vw;
  height: 90vh;
  max-width: none;
  z-index: 1000;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
body.fullscreen-mode #chat-log {
  opacity: 0.2;
}

.form-main {
  display: flex;
  flex-direction: column;
  gap: 15px;
  flex: 1;
}

#toolbar {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,0.2);
  padding: 10px;
  border-radius: 12px;
  flex-shrink: 0;
  position: relative;
}

.toolbar-divider {
  height: 24px;
  width: 1px;
  background: rgba(255, 255, 255, 0.2);
  margin: 0 5px;
}

button {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text-color);
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  font-family: inherit;
}

button:hover {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

button:active {
  transform: translateY(0);
}

button.active-tool {
  background: var(--accent-color);
  border-color: #6366f1;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

#toolbar button {
  width: 40px;
  height: 40px;
  padding: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#toolbar button img {
  width: 24px;
  height: 24px;
  filter: invert(1);
}

.palette-container {
  position: relative;
  display: flex;
  align-items: center;
}

#palette-toggle {
  display: none;
}

#color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  align-items: center;
}

@media (max-aspect-ratio: 1/1) {
  #palette-toggle {
    display: flex;
  }
  #color-palette {
    display: none;
    position: absolute;
    top: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    backdrop-filter: var(--glass-blur);
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    z-index: 100;
    width: 140px;
  }
  #color-palette.show-palette {
    display: flex;
  }
  body.light-mode #color-palette {
    background: rgba(255, 255, 255, 0.95);
  }
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s;
  padding: 0;
}

.swatch:hover {
  transform: scale(1.1);
}

.swatch.active-swatch {
  border-color: white;
  transform: scale(1.2);
  box-shadow: 0 0 8px rgba(255,255,255,0.8);
}

.swatch-picker-container {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#form-button-row {
  display: flex;
  gap: 10px;
  margin-top: auto;
}

#form-button-row button {
  flex: 1;
  font-size: 16px;
  padding: 12px;
}

/* User Message Box (The canvas container) */
.message-box {
  background: rgba(20, 20, 25, 0.8);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.message-header {
  background: rgba(255, 255, 255, 0.05);
  padding: 8px 12px;
  font-size: 0.9em;
  font-weight: 600;
  border-bottom: 1px solid var(--panel-border);
  color: var(--user-custom-color, var(--accent-color));
}

.canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 856 / 312;
  background: #ffffff;
  cursor: crosshair;
}

.canvas canvas, .canvas img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

.chat-canvas {
  position: relative;
  width: 100%;
  background: #ffffff;
}

.chat-canvas img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

.message-text {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 10px;
  color: #000;
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  pointer-events: none;
  z-index: 10;
  word-wrap: break-word;
}

.system-message-box {
  background: rgba(255, 215, 0, 0.1);
  border: 1px solid rgba(255, 215, 0, 0.3);
  color: #ffd700;
  padding: 10px 15px;
  border-radius: 8px;
  font-size: 0.9em;
  text-align: center;
  align-self: center;
  flex-shrink: 0;
}

input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
  padding: 0;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

#chat-log .message-box {
  animation: message-appear 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes message-appear {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Custom scrollbar for chat log */
#chat-log::-webkit-scrollbar {
  width: 8px;
}
#chat-log::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
}
#chat-log::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 4px;
}
#chat-log::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.3);
}

/* Auth page tweaks */
.login.container {
  flex-direction: column;
  height: initial;
  max-width: 400px;
  padding: 20px;
  background: var(--panel-bg);
  backdrop-filter: var(--glass-blur);
  border-radius: 16px;
}

h1 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 20px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

input[type="text"] {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--panel-border);
  color: var(--text-color);
  border-radius: 8px;
  padding: 10px 15px;
  font-size: 16px;
}

form > button {
  padding: 10px;
  font-size: 16px;
}
