/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --pasta: #f0c96a;
  --pasta-dark: #9f6f32;
  --paper: #f7f1df;
  --paper-fleck: rgba(128, 93, 45, 0.11);
  --bg: #d8b86f;
  --sidebar-bg: #6f4e22;
  --surface: #8f6730;
  --surface-soft: #b8843e;
  --text: #fff8e8;
  --text-dark: #3b260a;
  --accent: #b94d2f;
  --accent-strong: #8f3420;
  --sage: #62714a;
  --radius: 8px;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(135deg, #c99c4a 0%, var(--bg) 52%, #b67535 100%);
  color: var(--text);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* === Sidebar === */
#sidebar {
  width: 240px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 2px solid #4e3517;
  box-shadow: 3px 0 12px rgba(59, 38, 10, 0.18);
  flex-shrink: 0;
}
#sidebar-header { padding: 16px; border-bottom: 1px solid rgba(255,248,232,0.16); text-align: center; }
#sidebar-header h1 { font-size: 1.3rem; }
#current-user { font-size: 0.8rem; color: var(--pasta); margin-top: 4px; display: block; }
#board-list { flex: 1; overflow-y: auto; padding: 8px; }
.board-item {
  padding: 10px 12px; margin-bottom: 4px; border-radius: var(--radius);
  cursor: pointer; font-size: 0.9rem; transition: background 0.15s;
  display: flex; align-items: center; gap: 6px;
}
.board-item:hover { background: var(--surface); }
.board-item.active { background: var(--accent); font-weight: bold; box-shadow: inset 3px 0 0 var(--pasta); }
.board-badge {
  font-size: 0.65rem; padding: 2px 6px; border-radius: 10px;
  background: var(--pasta); color: var(--text-dark); margin-left: auto;
}
#sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,248,232,0.16); display: flex; flex-direction: column; gap: 8px; }
#sidebar-footer button, #admin-link {
  width: 100%; padding: 8px; border: none; border-radius: var(--radius);
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 0.85rem;
  text-align: center; text-decoration: none; display: block;
}
#sidebar-footer button:hover, #admin-link:hover { background: var(--accent); }

/* === Canvas === */
#canvas-area { flex: 1; display: flex; flex-direction: column; position: relative; background: #b8843e; }
#konva-container {
  flex: 1;
  overflow: hidden;
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 16px 18px, var(--paper-fleck) 0 1px, transparent 1.7px),
    radial-gradient(circle at 58px 42px, rgba(167, 126, 61, 0.08) 0 1px, transparent 1.6px),
    linear-gradient(90deg, rgba(255,255,255,0.32), transparent 35%, rgba(107, 74, 32, 0.04)),
    linear-gradient(0deg, rgba(255,255,255,0.24), transparent 42%, rgba(107, 74, 32, 0.035));
  background-size: 74px 74px, 96px 96px, 100% 100%, 100% 100%;
  box-shadow: inset 0 0 42px rgba(91, 58, 20, 0.13);
}
#konva-container canvas { display: block; }

/* === Toolbar === */
#toolbar {
  display: flex; align-items: center; gap: 12px; padding: 8px 16px;
  background: #7b5726; border-bottom: 1px solid #4e3517; flex-wrap: wrap;
  box-shadow: 0 2px 10px rgba(59, 38, 10, 0.14);
}
#shape-palette, #color-palette { display: flex; gap: 6px; }
.shape-btn {
  width: 40px; height: 40px; border: 2px solid transparent; border-radius: var(--radius);
  background: #f1d186; color: var(--text-dark); cursor: pointer; display: flex; align-items: center;
  justify-content: center; font-size: 1.4rem; transition: border-color 0.15s;
}
.shape-btn:hover, .shape-btn.selected { border-color: var(--accent); background: #f6de9c; }
.shape-icon {
  width: 30px;
  height: 30px;
  display: block;
  pointer-events: none;
}
#btn-select-tool {
  width: 64px;
  font-size: 0.75rem;
  font-weight: 700;
}
.color-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; transition: border-color 0.15s, transform 0.15s;
}
.color-btn:hover, .color-btn.selected { border-color: #fff8e8; transform: scale(1.15); }
#btn-delete-shape { padding: 6px 14px; border: none; border-radius: var(--radius); background: var(--accent); color: #fff; cursor: pointer; font-size: 0.85rem; }
#btn-delete-shape.hidden { display: none; }

/* === Reaction Bar === */
#reaction-bar { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.reaction-label { font-size: 0.75rem; color: #888; margin-right: 4px; }
.reaction-label { color: #f8e6b6; }
#zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 12px;
  padding-right: 12px;
  border-right: 1px solid rgba(255, 248, 232, 0.2);
}
.zoom-btn {
  min-width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 248, 232, 0.22);
  border-radius: 6px;
  background: rgba(255, 248, 232, 0.13);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}
.zoom-btn:hover { border-color: var(--pasta); background: rgba(255, 248, 232, 0.22); }
.zoom-reset {
  min-width: 34px;
  font-size: 0.72rem;
}
#zoom-level {
  min-width: 46px;
  text-align: center;
  color: #fff8e8;
  font-size: 0.78rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.reaction-btn {
  background: rgba(255, 248, 232, 0.13); border: 1px solid transparent; border-radius: 50%;
  font-size: 1.3rem; cursor: pointer; padding: 2px;
  transition: transform 0.15s, border-color 0.15s; line-height: 1;
}
.reaction-btn:hover { transform: scale(1.3); border-color: var(--pasta); background: rgba(255, 248, 232, 0.22); }

#reaction-popups {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 900;
  pointer-events: none;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 8px;
}
.reaction-popup {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 92px;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(79, 49, 16, 0.92);
  color: var(--text);
  border: 1px solid rgba(255, 248, 232, 0.22);
  box-shadow: 0 10px 24px rgba(59, 38, 10, 0.26);
  animation: reaction-pop 2.35s ease-out forwards;
}
.reaction-popup-emoji { font-size: 1.45rem; line-height: 1; }
.reaction-popup-name { font-size: 0.75rem; font-weight: 700; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@keyframes reaction-pop {
  0% { opacity: 0; transform: translateY(18px) scale(0.88); }
  12% { opacity: 1; transform: translateY(0) scale(1); }
  72% { opacity: 1; transform: translateY(-10px) scale(1); }
  100% { opacity: 0; transform: translateY(-34px) scale(0.96); }
}

/* === Modals === */
.modal { position: fixed; inset: 0; background: rgba(59,38,10,0.66); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal.hidden { display: none; }
.modal-box { background: #6f4e22; padding: 32px; border-radius: 12px; text-align: center; max-width: 400px; width: 90%; border: 1px solid rgba(255,248,232,0.18); }
.modal-box h2 { margin-bottom: 12px; }
.modal-box input {
  width: 100%; padding: 10px; margin: 12px 0; border: 2px solid var(--surface);
  border-radius: var(--radius); background: var(--paper); color: var(--text-dark); font-size: 1rem;
}
.modal-box input:focus { outline: none; border-color: var(--pasta); }
.modal-box button {
  padding: 10px 24px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; cursor: pointer; font-size: 1rem; margin-top: 8px;
}
.modal-box button.danger { background: #c0392b; }
.modal-buttons { display: flex; gap: 12px; justify-content: center; margin-top: 16px; }
.error { color: var(--accent); font-size: 0.85rem; margin-top: 8px; }
.hidden { display: none; }

/* === Admin Panel === */
.admin-page { display: block; padding: 24px; background: var(--bg); min-height: 100vh; }
.admin-container { max-width: 900px; margin: 0 auto; }
.admin-container header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 32px; padding-bottom: 16px; border-bottom: 2px solid var(--surface); }
.back-link { color: var(--accent); text-decoration: none; font-size: 0.9rem; }
.admin-table { width: 100%; border-collapse: collapse; margin: 12px 0 24px; }
.admin-row { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--surface); gap: 12px; font-size: 0.9rem; }
.admin-row .name { flex: 1; font-weight: 600; }
.admin-row .meta { color: #888; font-size: 0.8rem; }
.admin-row .danger-btn { padding: 4px 12px; border: none; border-radius: 4px; background: #c0392b; color: #fff; cursor: pointer; font-size: 0.8rem; }
.admin-row .danger-btn:hover { background: #e74c3c; }
.promote-btn { padding: 4px 12px; border: none; border-radius: 4px; background: #27ae60; color: #fff; cursor: pointer; font-size: 0.75rem; }
.promote-btn:hover { background: #2ecc71; }
.demote-btn { padding: 4px 12px; border: none; border-radius: 4px; background: #f39c12; color: #fff; cursor: pointer; font-size: 0.75rem; }
.demote-btn:hover { background: #f1c40f; color: #333; }
.admin-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 0.65rem; font-weight: 700; margin-left: 6px; }
.admin-login { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--sidebar-bg); padding: 40px; border-radius: 12px; text-align: center; max-width: 380px; width: 90%; }
.login-box h1 { margin-bottom: 8px; }
.login-box p { color: #888; font-size: 0.85rem; margin-bottom: 16px; }
.login-box input { width: 100%; padding: 10px 14px; border: 2px solid var(--surface); border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 1rem; margin-bottom: 12px; }
.login-box input:focus { outline: none; border-color: var(--accent); }
.login-box button { width: 100%; padding: 10px; border: none; border-radius: var(--radius); background: var(--accent); color: #fff; font-size: 1rem; cursor: pointer; }
.login-box .back-link { display: block; margin-top: 12px; font-size: 0.85rem; }
.logout-btn { padding: 4px 12px; border: 1px solid var(--surface); border-radius: 4px; background: none; color: var(--text); cursor: pointer; font-size: 0.8rem; margin-right: 12px; }
.logout-btn:hover { border-color: var(--accent); color: var(--accent); }
#admin-mode-badge { font-size: 0.75rem; color: #888; margin-right: 8px; }

/* === Mobile === */
@media (max-width: 768px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; height: auto; max-height: 200px; flex-shrink: 0; border-right: none; border-bottom: 2px solid var(--pasta-dark); }
  #board-list { display: flex; overflow-x: auto; padding: 4px; }
  .board-item { white-space: nowrap; margin-right: 4px; margin-bottom: 0; }
  #sidebar-footer { flex-direction: row; }
  #canvas-area { height: calc(100vh - 200px); }
  #toolbar { flex-wrap: wrap; gap: 8px; }
  .shape-btn { width: 36px; height: 36px; font-size: 1.2rem; }
}
