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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f0ebe3;
  color: #2d2d2d;
  min-height: 100vh;
}

/* Navbar */
#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: #2d2d2d;
  color: #f0ebe3;
}

.logo {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

#nav-links {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-btn {
  background: none;
  border: 1px solid rgba(240,235,227,0.3);
  color: #f0ebe3;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  text-decoration: none;
}

.nav-btn:hover {
  background: rgba(240,235,227,0.15);
}

.nav-btn.active {
  background: #f0ebe3;
  color: #2d2d2d;
}

#nav-user {
  font-size: 0.85rem;
  opacity: 0.7;
}

/* Views */
.view {
  display: none;
}

.view.active {
  display: block;
}

.view.active#plaza-view {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 50px);
}

/* Auth */
.auth-container {
  max-width: 360px;
  margin: 120px auto;
  text-align: center;
}

.auth-container h2 {
  font-size: 2rem;
  margin-bottom: 8px;
}

.subtitle {
  color: #666;
  margin-bottom: 32px;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#auth-form input {
  padding: 12px 16px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  background: white;
  transition: border-color 0.2s;
}

#auth-form input:focus {
  outline: none;
  border-color: #2d2d2d;
}

.auth-buttons {
  display: flex;
  gap: 12px;
}

.auth-buttons button {
  flex: 1;
  padding: 12px;
  border: 2px solid #2d2d2d;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

#login-btn {
  background: #2d2d2d;
  color: white;
}

#login-btn:hover {
  background: #444;
}

#register-btn {
  background: white;
  color: #2d2d2d;
}

#register-btn:hover {
  background: #f5f5f5;
}

.error {
  color: #d32f2f;
  font-size: 0.85rem;
}

/* Chat */
.chat-container {
  max-width: 700px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 80px);
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-msg {
  padding: 12px 16px;
  border-radius: 12px;
  max-width: 85%;
  line-height: 1.5;
}

.chat-msg.user {
  background: #2d2d2d;
  color: white;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg.assistant {
  background: white;
  border: 1px solid #e0e0e0;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg.thinking {
  background: #fff8e1;
  border: 1px dashed #ffb74d;
  align-self: flex-start;
  font-size: 0.85rem;
  opacity: 0.85;
}

.chat-msg .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  opacity: 0.6;
  margin-bottom: 4px;
}

.thinking-saved {
  font-size: 0.8rem;
  color: #388e3c;
  margin-top: 8px;
  font-style: italic;
}

.thinking-back {
  color: #e65100;
}

.find-in-plaza-btn {
  background: none;
  border: 1px solid #388e3c;
  color: #388e3c;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  cursor: pointer;
  margin-left: 8px;
  transition: all 0.2s;
}

.find-in-plaza-btn:hover {
  background: #388e3c;
  color: #fff;
}

.send-to-plaza {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed #ffb74d;
}

.send-to-plaza input[type="number"] {
  width: 42px;
  padding: 6px 4px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 0.8rem;
  font-family: inherit;
  text-align: center;
  -moz-appearance: textfield;
}

.send-to-plaza input[type="number"]::-webkit-inner-spin-button,
.send-to-plaza input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
}

.send-to-plaza button {
  padding: 6px 14px;
  background: #2d2d2d;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
}

.send-to-plaza button:hover {
  background: #444;
}

.send-to-plaza button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-error {
  color: #e65100;
  font-size: 0.8rem;
  margin-top: 4px;
  width: 100%;
}

.walker-context-menu {
  position: absolute;
  background: white;
  border-radius: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
  z-index: 50;
  min-width: 140px;
  max-height: 300px;
  overflow-y: auto;
  padding: 4px 0;
}

.context-menu-header {
  padding: 6px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #eee;
  margin-bottom: 2px;
}

.context-menu-item {
  padding: 8px 16px;
  font-size: 0.85rem;
  cursor: pointer;
}

.context-menu-item:hover {
  background: #f0f0f0;
}

.keyword-edit-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.keyword-edit-input {
  padding: 6px 10px;
  border: 2px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  width: 160px;
  text-align: center;
}

.keyword-edit-input:focus {
  outline: none;
  border-color: #2d2d2d;
}

.keyword-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.keyword-edit-actions button {
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}

.keyword-edit-save {
  background: #2d2d2d;
  color: white;
}

.keyword-edit-cancel {
  background: #e0e0e0;
  color: #333;
}

#chat-form {
  display: flex;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid #ddd;
}

#chat-input {
  flex: 1;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
}

#chat-input:focus {
  outline: none;
  border-color: #2d2d2d;
}

#send-btn {
  padding: 12px 24px;
  background: #2d2d2d;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
  align-self: flex-end;
}

#send-btn:hover {
  background: #444;
}

#send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Plaza */
.plaza-header {
  text-align: center;
  padding: 24px;
  position: relative;
  flex-shrink: 0;
}

.plaza-header-buttons {
  position: absolute;
  top: 24px;
  right: 24px;
  display: flex;
  gap: 8px;
}

#navigate-menu {
  position: relative;
}

#navigate-btn {
  background: #2d2d2d;
  color: #f0ebe3;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

#navigate-btn:hover {
  background: #444;
}

#navigate-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  min-width: 200px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
}

#navigate-dropdown.hidden {
  display: none;
}

.nav-walker-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-walker-item:hover {
  background: #f0f0f0;
}

.nav-walker-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

#connect-menu {
  position: relative;
}

#connect-btn {
  background: #2d2d2d;
  color: #f0ebe3;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

#connect-btn:hover {
  background: #444;
}

#connect-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  min-width: 240px;
  max-height: 350px;
  overflow-y: auto;
  z-index: 100;
  padding: 8px 0;
}

#connect-dropdown.hidden {
  display: none;
}

.connect-step-label {
  padding: 6px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.connect-walker-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.connect-walker-item:hover {
  background: #f0f0f0;
}

.connect-walker-item.selected {
  background: #e8f4fd;
  font-weight: 600;
}

.connect-walker-color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

#plaza {
  transform-origin: 0 0;
  transition: transform 0.4s ease;
}

#visibility-menu {
  position: relative;
}

#visibility-btn {
  background: #2d2d2d;
  color: #f0ebe3;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

#visibility-btn:hover {
  background: #444;
}

#visibility-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  min-width: 220px;
  z-index: 100;
}

#visibility-dropdown.hidden {
  display: none;
}

.vis-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
}

.vis-item:hover {
  background: #f0f0f0;
}

#vis-line-list {
  border-top: 1px solid #eee;
  max-height: 250px;
  overflow-y: auto;
}

#vis-line-list.hidden {
  display: none;
}

.vis-line-entry {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.vis-line-entry:hover {
  background: #f0f0f0;
}

.plaza-header h2 {
  font-size: 1.5rem;
}

.plaza-header p {
  color: #666;
  font-size: 0.9rem;
}

#plaza-scroll {
  overflow: auto;
  flex: 1;
  position: relative;
  cursor: grab;
}

#plaza-scroll:active {
  cursor: grabbing;
}

#plaza-scroll::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

#plaza-scroll::-webkit-scrollbar-track {
  background: transparent;
}

#plaza-scroll::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 4px;
}

#plaza-scroll::-webkit-scrollbar-thumb:hover {
  background: #555;
}

#plaza {
  position: relative;
  min-width: 4000px;
  min-height: 4000px;
  padding: 16px;
  background-image: radial-gradient(circle, #3a3a3a 1px, transparent 1px);
  background-size: 30px 30px;
}

#threads-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#threads-svg .thread-hit {
  pointer-events: stroke;
}

#threads-svg path {
  stroke: #2d2d2d;
  stroke-width: 2;
  stroke-dasharray: 6 3;
  fill: none;
}

#threads-svg path.thread-invisible {
  opacity: 0;
}

#threads-svg path.thread-hit {
  stroke: transparent;
  stroke-width: 16;
  stroke-dasharray: none;
  fill: none;
  pointer-events: stroke;
  cursor: pointer;
}

.thread-context-menu {
  position: fixed;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 1000;
  min-width: 120px;
  padding: 4px 0;
}

.thread-menu-item {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
}

.thread-menu-item:hover {
  background: #f0f0f0;
}

.reason-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.reason-dialog {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  min-width: 300px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

.reason-dialog label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 14px;
}

.reason-input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
  box-sizing: border-box;
}

.reason-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.reason-actions button {
  padding: 6px 16px;
  border: 1px solid #ccc;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.reason-save {
  background: #2d2d2d;
  color: #fff;
  border-color: #2d2d2d;
}

.reason-tooltip {
  position: fixed;
  background: #2d2d2d;
  color: #fff;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 13px;
  pointer-events: none;
  z-index: 999;
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#draw-line {
  stroke: #999;
  stroke-width: 2;
  stroke-dasharray: 4 4;
  fill: none;
}

.walker {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: grab;
  width: 230px;
  z-index: 2;
  animation: bob 3s ease-in-out infinite;
}

.walker.dragging {
  cursor: grabbing;
  z-index: 10;
  animation: none;
}

.walker:nth-child(even) {
  animation-delay: -1.5s;
}

.walker:nth-child(3n) {
  animation-delay: -0.7s;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.walker svg {
  width: 220px;
  height: 280px;
  pointer-events: none;
}

.walker-username {
  font-size: 0.65rem;
  color: #999;
}

.walker-timer {
  font-size: 0.6rem;
  color: #e67e22;
  font-weight: 600;
  margin-top: 2px;
}

.walker-back-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2d2d2d;
  color: #f0ebe3;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.95rem;
  z-index: 200;
  animation: toastFade 4s ease forwards;
}

@keyframes toastFade {
  0%, 70% { opacity: 1; }
  100% { opacity: 0; }
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: white;
  border-radius: 16px;
  padding: 32px;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: #999;
}

.modal-close:hover {
  color: #333;
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.modal-keyword {
  background: #fff3e0;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #e65100;
}

#modal-username {
  font-weight: 700;
}

#modal-date {
  font-size: 0.8rem;
  color: #999;
}

.modal-section {
  margin-bottom: 20px;
}

.modal-section h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #999;
  margin-bottom: 8px;
}

#modal-thinking {
  background: #fff8e1;
  border: 1px dashed #ffb74d;
  border-radius: 8px;
  padding: 16px;
  font-size: 0.85rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  font-family: inherit;
}

#modal-response {
  background: #f5f5f5;
  border-radius: 8px;
  padding: 16px;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.status-popup {
  position: fixed;
  top: 52px;
  right: 16px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding: 16px 20px;
  min-width: 240px;
  z-index: 200;
}

.status-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 12px;
}

.status-subtitle {
  font-weight: 600;
  font-size: 0.85rem;
  margin-top: 12px;
  margin-bottom: 6px;
  color: #e65100;
}

.status-row {
  font-size: 0.85rem;
  padding: 3px 0;
}

.status-active {
  padding-left: 8px;
}

.status-indent {
  padding-left: 12px;
  color: #666;
}

.admin-popup {
  position: fixed;
  top: 52px;
  right: 16px;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  padding: 16px 20px;
  min-width: 260px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
}

.admin-title {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 12px;
}

.admin-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.85rem;
}

.admin-user-row:last-child {
  border-bottom: none;
}

.admin-username {
  font-weight: 500;
}

.admin-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.admin-toggle input {
  accent-color: #2d2d2d;
  cursor: pointer;
}

.admin-toggle-label {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 24px;
}

.comeback-btn {
  display: block;
  margin-top: 16px;
  padding: 10px 20px;
  background: #e65100;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  width: 100%;
}

.comeback-btn:hover {
  background: #bf360c;
}

.comeback-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Empty plaza */
.plaza-empty {
  text-align: center;
  padding: 60px 24px;
  color: #999;
}

.plaza-empty svg {
  width: 120px;
  height: 180px;
  opacity: 0.3;
  margin-bottom: 16px;
}
