@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital@0;1&family=DM+Mono:wght@300;400&display=swap');

:root {
  --ink: #1a1209;
  --paper: #f5f0e8;
  --rust: #c0432a;
  --gold: #c8952a;
  --muted: #8a7f6e;
  --panel-w: 230px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'DM Mono', monospace;
  background: var(--ink);
  color: var(--paper);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}

/* ── HEADER ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid #2e2820;
  background: #120f0a;
  flex-shrink: 0;
  gap: 12px;
}
.logo { font-family: 'Playfair Display', serif; font-style: italic; font-size: 1.3rem; color: var(--paper); white-space: nowrap; }
.logo span { color: var(--rust); }
.header-center { display: flex; gap: 6px; align-items: center; flex: 1; justify-content: center; }
.header-actions { display: flex; gap: 6px; align-items: center; }
.btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 6px 14px;
  border: 1px solid #3a3028;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}
.btn:hover { border-color: var(--paper); color: var(--paper); }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn.danger { border-color: #5a2020; color: #a04040; }
.btn.danger:hover { border-color: var(--rust); color: var(--rust); }
.btn.primary { border-color: var(--gold); color: var(--gold); }
.btn.primary:hover { background: var(--gold); color: var(--ink); }
.btn.active-btn { border-color: var(--rust) !important; color: var(--rust) !important; background: #200f0f; }

/* ── WORKSPACE ── */
.workspace { display: flex; flex: 1; overflow: hidden; }

/* ── LEFT PANEL ── */
.panel {
  width: var(--panel-w);
  background: #120f0a;
  border-right: 1px solid #2e2820;
  display: flex;
  flex-direction: column;
  padding: 14px 13px;
  gap: 18px;
  overflow-y: auto;
  flex-shrink: 0;
  scrollbar-width: thin;
  scrollbar-color: #2e2820 transparent;
}
.panel-section h3 {
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
  border-bottom: 1px solid #2a2520;
  padding-bottom: 5px;
}
.palette { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.color-swatch {
  width: 100%; aspect-ratio: 1; border-radius: 50%;
  cursor: pointer; border: 2px solid transparent;
  transition: transform 0.12s, border-color 0.12s;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.25);
}
.color-swatch:hover { transform: scale(1.18); }
.color-swatch.active { border-color: var(--paper); transform: scale(1.18); }
.custom-color-row { display: flex; align-items: center; gap: 7px; margin-top: 7px; }
.custom-color-row label { font-size: 0.63rem; color: var(--muted); }
input[type="color"] { width: 30px; height: 22px; border: 1px solid #3a3028; background: none; cursor: pointer; padding: 0; }
.current-color-preview { flex: 1; height: 22px; border: 1px solid #3a3028; border-radius: 2px; transition: background 0.2s; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.tool-btn {
  font-family: 'DM Mono', monospace;
  font-size: 0.6rem;
  letter-spacing: 0.03em;
  padding: 6px 2px;
  border: 1px solid #3a3028;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: all 0.13s;
}
.tool-btn:hover { border-color: var(--paper); color: var(--paper); }
.tool-btn.active { border-color: var(--rust); color: var(--rust); background: #200f0f; }

.slider-row { display: flex; flex-direction: column; gap: 5px; }
.slider-label { display: flex; justify-content: space-between; font-size: 0.63rem; color: var(--muted); }
input[type="range"] {
  width: 100%; -webkit-appearance: none; height: 3px;
  background: #3a3028; outline: none; border-radius: 2px; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 11px; height: 11px;
  border-radius: 50%; background: var(--paper); cursor: pointer;
}

.bg-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.bg-btn {
  font-size: 0.58rem; padding: 5px 2px;
  border: 1px solid #3a3028; background: transparent;
  color: var(--muted); cursor: pointer; text-align: center;
  font-family: 'DM Mono', monospace; transition: all 0.13s;
}
.bg-btn:hover, .bg-btn.active { border-color: var(--gold); color: var(--gold); }

.users-list { display: flex; flex-direction: column; gap: 6px; }
.user-entry { display: flex; align-items: center; gap: 7px; font-size: 0.67rem; color: var(--muted); }
.user-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.user-dot.online { animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.35} }

select {
  background: #120f0a; border: 1px solid #3a3028;
  color: var(--muted); font-family: 'DM Mono', monospace;
  font-size: 0.66rem; padding: 5px 7px; outline: none; cursor: pointer; width: 100%;
}
select option { background: #1a1510; }

.kbd { display: inline-block; background: #2a2520; border: 1px solid #3a3028; border-radius: 2px; padding: 0 4px; font-size: 0.55rem; color: var(--muted); margin-left: 3px; }

/* ── CANVAS ── */
.canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #1a1510; }
canvas { display: block; touch-action: none; }
#main-canvas { position: absolute; top: 0; left: 0; }
#cursor-canvas { position: absolute; top: 0; left: 0; pointer-events: none; }

/* ── CHAT ── */
.chat-panel {
  width: 240px; background: #120f0a;
  border-left: 1px solid #2e2820;
  display: flex; flex-direction: column; flex-shrink: 0;
  transition: width 0.25s ease;
}
.chat-panel.collapsed { width: 0; overflow: hidden; border: none; }
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 13px; border-bottom: 1px solid #2a2520;
  font-size: 0.58rem; letter-spacing: 0.15em; text-transform: uppercase; color: var(--muted); flex-shrink: 0;
}
.chat-header button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1rem; line-height: 1; }
.chat-messages {
  flex: 1; overflow-y: auto; padding: 9px 11px;
  display: flex; flex-direction: column; gap: 7px;
  scrollbar-width: thin; scrollbar-color: #2e2820 transparent;
}
.chat-msg { font-size: 0.67rem; line-height: 1.5; animation: fadeUp 0.2s; }
@keyframes fadeUp { from { opacity:0; transform: translateY(4px); } }
.chat-msg .msg-author { margin-bottom: 1px; font-size: 0.63rem; }
.chat-msg .msg-text { color: var(--muted); word-break: break-word; }
.chat-msg.system .msg-text { color: #4a4035; font-style: italic; font-size: 0.62rem; }
.chat-input-row { display: flex; border-top: 1px solid #2a2520; flex-shrink: 0; }
.chat-input-row input {
  flex: 1; background: none; border: none; color: var(--paper);
  font-family: 'DM Mono', monospace; font-size: 0.7rem; padding: 9px 11px; outline: none;
}
.chat-input-row button {
  background: none; border: none; border-left: 1px solid #2a2520;
  color: var(--muted); cursor: pointer; padding: 0 11px; font-size: 0.8rem; transition: color 0.15s;
}
.chat-input-row button:hover { color: var(--gold); }

/* ── STATUSBAR ── */
.statusbar {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(18,15,10,0.88); border: 1px solid #2e2820;
  padding: 5px 14px; font-size: 0.6rem; color: var(--muted);
  letter-spacing: 0.07em; backdrop-filter: blur(8px); pointer-events: none; white-space: nowrap;
}

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 50px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: #2a2010; border: 1px solid var(--gold); color: var(--gold);
  font-size: 0.7rem; padding: 7px 18px; letter-spacing: 0.06em;
  opacity: 0; transition: all 0.3s; pointer-events: none; z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(10,8,5,0.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px);
}
.modal {
  background: #1a1510; border: 1px solid #3a3028;
  padding: 38px; max-width: 380px; width: 90%; text-align: center;
}
.modal h2 { font-family: 'Playfair Display', serif; font-style: italic; font-size: 1.7rem; margin-bottom: 6px; }
.modal p { font-size: 0.7rem; color: var(--muted); margin-bottom: 22px; line-height: 1.7; }
.modal input[type="text"] {
  width: 100%; background: #120f0a; border: 1px solid #3a3028;
  color: var(--paper); font-family: 'DM Mono', monospace; font-size: 0.88rem;
  padding: 11px 16px; outline: none; margin-bottom: 13px; text-align: center; letter-spacing: 0.08em;
}
.modal input[type="text"]:focus { border-color: var(--gold); }
.modal .btn { width: 100%; font-size: 0.78rem; padding: 11px; }
.share-info {
  background: #0f0c08; border: 1px solid #2a2520; padding: 9px 13px;
  font-size: 0.63rem; color: var(--muted); margin-top: 10px; line-height: 1.65; text-align: left;
}
.share-info strong { color: var(--gold); }

/* ── TEXT INPUT ON CANVAS ── */
#text-input-overlay { position: absolute; display: none; z-index: 50; }
#text-field {
  background: transparent; border: 1px dashed rgba(192,67,42,0.6);
  color: inherit; font-family: inherit; outline: none; padding: 2px 6px; min-width: 80px;
  caret-color: var(--rust);
}

/* ── ZOOM CONTROLS ── */
.zoom-controls { position: absolute; bottom: 14px; right: 14px; display: flex; gap: 4px; }
.zoom-btn {
  width: 28px; height: 28px; background: rgba(18,15,10,0.88); border: 1px solid #2e2820;
  color: var(--muted); cursor: pointer; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s; backdrop-filter: blur(4px);
}
.zoom-btn:hover { border-color: var(--paper); color: var(--paper); }
#zoom-label { width: 46px; font-size: 0.6rem; }

/* ── SYMMETRY INDICATOR ── */
.sym-indicator {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(192,67,42,0.12); border: 1px solid rgba(192,67,42,0.35);
  padding: 3px 12px; font-size: 0.58rem; color: var(--rust);
  letter-spacing: 0.1em; text-transform: uppercase; pointer-events: none; display: none;
}

/* ── CHAT BADGE ── */
.chat-badge {
  display: none; background: var(--rust); color: white;
  border-radius: 50%; width: 16px; height: 16px;
  font-size: 0.58rem; text-align: center; line-height: 16px; margin-left: 4px;
}

/* ══════════════════════════════════════════
   RESPONSIVE — MOBILE & TABLET
   ══════════════════════════════════════════ */

/* ── Mobile panel toggle button ── */
.panel-toggle {
  display: none;
  position: fixed;
  bottom: 70px;
  left: 12px;
  z-index: 60;
  width: 38px; height: 38px;
  background: rgba(18,15,10,0.92);
  border: 1px solid #3a3028;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  transition: all 0.18s;
}
.panel-toggle:hover { border-color: var(--paper); color: var(--paper); }

/* ── Tablet (≤ 900px) ── */
@media (max-width: 900px) {
  :root { --panel-w: 195px; }
  .btn { font-size: 0.62rem; padding: 5px 10px; }
  .chat-panel { width: 210px; }
}

/* ── Mobile (≤ 650px) ── */
@media (max-width: 650px) {
  :root { --panel-w: 100%; }

  body { height: 100dvh; overflow: hidden; }

  /* ── HEADER: two rows ── */
  header {
    flex-wrap: wrap;
    padding: 7px 10px;
    gap: 5px;
    height: auto;
  }
  .logo { font-size: 1.05rem; flex-shrink: 0; }
  .header-center {
    order: 3;
    width: 100%;
    gap: 4px;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  .header-actions { gap: 4px; }
  .btn { font-size: 0.6rem; padding: 5px 8px; }
  /* Hide coord display — too small on mobile */
  #coord-display { display: none; }

  /* ── WORKSPACE: stack canvas + tools ── */
  .workspace { flex-direction: column-reverse; position: relative; }

  /* ── LEFT PANEL: slides up from bottom as a drawer ── */
  .panel {
    width: 100%;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 55;
    max-height: 0;
    overflow: hidden;
    border-right: none;
    border-top: 1px solid #3a3028;
    padding: 0 12px;
    gap: 14px;
    transition: max-height 0.3s ease, padding 0.3s ease;
    scrollbar-width: thin;
  }
  .panel.open {
    max-height: 60dvh;
    overflow-y: auto;
    padding: 14px 12px 20px;
  }

  /* Panel toggle button — visible on mobile */
  .panel-toggle { display: flex; }

  /* ── CANVAS: takes full available height ── */
  .canvas-wrap {
    flex: 1;
    width: 100%;
    height: 100%;
  }

  /* ── CHAT: full-width overlay on mobile ── */
  .chat-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 55dvh;
    border-left: none;
    border-top: 1px solid #3a3028;
    z-index: 60;
    transform: translateY(100%);
    transition: transform 0.28s ease, width 0.25s ease;
  }
  .chat-panel.collapsed { width: 100%; overflow: hidden; transform: translateY(100%); border: none; }
  .chat-panel.open { transform: translateY(0); }

  /* ── TOOLS: 3-column grid on mobile ── */
  .tools { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .tool-btn { font-size: 0.55rem; padding: 7px 2px; }
  .tool-btn .kbd { display: none; } /* hide keyboard hints on mobile */

  /* ── PALETTE: 5 col stays fine, swatches bigger touch targets ── */
  .palette { gap: 7px; }
  .color-swatch { min-width: 30px; min-height: 30px; }

  /* Sliders: bigger touch targets */
  input[type="range"] { height: 5px; }
  input[type="range"]::-webkit-slider-thumb { width: 16px; height: 16px; }

  /* ── BG options: 3 col ── */
  .bg-options { grid-template-columns: repeat(3, 1fr); }
  .bg-btn { padding: 7px 2px; font-size: 0.6rem; }

  /* ── STATUS BAR: au-dessus des zoom controls pour éviter le chevauchement ── */
  .statusbar { bottom: 96px; font-size: 0.58rem; padding: 4px 12px; }

  /* ── ZOOM CONTROLS: reposition above panel toggle ── */
  .zoom-controls { bottom: 56px; right: 10px; }
  .zoom-btn { width: 32px; height: 32px; }

  /* ── MODAL: full width ── */
  .modal { padding: 26px 20px; width: 95%; }
  .modal h2 { font-size: 1.35rem; }

  /* ── PANEL section shortcuts: hide on mobile ── */
  .panel-section:last-of-type { display: none; }

  /* ── SYMMETRY indicator: adjust for mobile header height ── */
  .sym-indicator { top: auto; bottom: 56px; left: 50%; transform: translateX(-50%); }

  /* Text field on canvas */
  #text-field { font-size: 1rem; min-width: 120px; }
}

/* ── Very small (≤ 380px) ── */
@media (max-width: 380px) {
  .logo { font-size: 0.9rem; }
  .btn { font-size: 0.56rem; padding: 4px 6px; }
  .tools { grid-template-columns: repeat(3, 1fr); }
  .tool-btn { font-size: 0.5rem; }
  header { gap: 4px; }
}

/* ── Landscape mobile: side panel as narrow strip ── */
@media (max-width: 750px) and (orientation: landscape) {
  .workspace { flex-direction: row; }
  .panel {
    position: static;
    width: 180px;
    max-height: none;
    overflow-y: auto;
    padding: 10px 10px;
    border-right: 1px solid #2e2820;
    border-top: none;
  }
  .panel.open { max-height: none; }
  .panel-toggle { display: none; }
  .chat-panel {
    position: static;
    width: 0;
    height: auto;
    border-top: none;
    border-left: 1px solid #2e2820;
    transform: none;
    transition: width 0.25s ease;
  }
  .chat-panel.open { width: 200px; transform: none; }
  .chat-panel.collapsed { width: 0; }
  .statusbar { bottom: 50px; }
  .zoom-controls { bottom: 10px; }
  .sym-indicator { top: 8px; bottom: auto; }
}
