/* Global */
* { box-sizing: border-box; margin: 0; padding: 0; font-family: Arial, Helvetica, sans-serif; }
body { background: #ffffff; overflow: hidden; font-size: 14px; }

/* Top bar */
#topbar{
  position: fixed; left: 0; top: 0; width: 100%; height: 52px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.92);
  border-bottom: 1px solid rgba(0,0,0,0.10);
  box-shadow: 0 10px 28px rgba(0,0,0,0.08);
  z-index: 15000;
}
.topbar-title{
  font-weight: 800;
  letter-spacing: 4px;
  font-size: 14px;
  opacity: 0.9;
}
.topbar-btn{
  position: absolute;
  right: 14px; top: 10px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid rgba(0,0,0,0.12);
  background: rgba(255,255,255,0.96);
  border-radius: 12px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  opacity: 0.85;
}
.topbar-btn:hover{ background: rgba(0,0,0,0.06); }

/* App world */
#app{
  width: 100vw; height: 100vh;
  position: relative;
  background: #ffffff;
  overflow: hidden;
  touch-action: none;
  padding-top: 52px;
}
#world{
  position: absolute;
  left: 0; top: 0;
  width: 8000px; height: 8000px;
  transform-origin: 0 0;
}
#connections-layer{
  position: absolute;
  left: 0; top: 0;
  width: 8000px; height: 8000px;
  pointer-events: auto;
  overflow: visible;
  z-index: 1;
}

#drawings-layer{
  position: absolute;
  left: 0; top: 0;
  width: 8000px; height: 8000px;
  pointer-events: none; /* SVG background is transparent to clicks */
  overflow: visible;
  z-index: 2; /* Above hexes so drawings/images are clickable */
  fill: none;
}

#drawings-layer > * {
  pointer-events: auto; /* Each drawing receives events individually */
}

/* Selection box for drag-select */
#selection-box {
  position: absolute;
  border: 2px solid #2b6cff;
  background: rgba(43, 108, 255, 0.1);
  pointer-events: none;
  display: none;
  z-index: 10000;
}
#selection-box.selecting {
  display: block;
}
#selection-box.reverse {
  border-style: dashed;
  background: rgba(43, 108, 255, 0.15);
}

:root{
  --hex-clip: polygon(25% 0%, 75% 0%, 100% 50%, 75% 100%, 25% 100%, 0% 50%);
}

.hex{
  --fill: #c9fbff;
  --borderColor: rgba(0,0,0,0.25);
  --border: 1;

  width: 120px;
  height: 104px;
  position: absolute;
  cursor: pointer;

  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;

  z-index: 2;

  filter: drop-shadow(-6px 10px 8px rgba(0,0,0,0.10));
  transition: transform 120ms ease, filter 160ms ease, opacity 160ms ease, outline-color 160ms ease;
}

.tool-separator{
  height: 1px;
  background: rgba(0,0,0,0.10);
  margin: 8px 6px;
}

/* Drawing panel */
.draw-panel{
  position: fixed;
  right: 76px;
  top: 70px;
  width: 220px;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 16px;
  box-shadow: 0 14px 40px rgba(0,0,0,0.14);
  padding: 10px 12px;
  z-index: 16000;
}
.draw-title{
  font-weight: 800;
  letter-spacing: 1px;
  opacity: 0.85;
  margin-bottom: 8px;
}
.draw-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0;
}
.draw-row span{ font-size: 12px; opacity: 0.85; min-width: 60px; }
.draw-row input[type="range"]{ flex: 1; }
.draw-row input[type="number"]{ width: 64px; padding: 4px 6px; border-radius: 10px; border: 1px solid rgba(0,0,0,0.12); }
.draw-hint{ font-size: 11px; opacity: 0.65; margin-top: 8px; }

.draw-text-input{
  position: fixed;
  z-index: 20000;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.16);
  box-shadow: 0 12px 36px rgba(0,0,0,0.18);
  width: 240px;
  background: rgba(255,255,255,0.98);
  font-size: 14px;
}
.hex:hover{ filter: drop-shadow(-7px 12px 10px rgba(0,0,0,0.14)); }

.hex::before{
  content: "";
  position: absolute;
  inset: 0;
  background: var(--borderColor);
  clip-path: var(--hex-clip);
  z-index: 0;
}
.hex::after{
  content: "";
  position: absolute;
  inset: calc(var(--border) * 1px);
  background: var(--fill);
  clip-path: var(--hex-clip);
  z-index: 0;
}

.hex > *{ position: relative; z-index: 2; }

.hex.selected{ 
  outline: 4px solid #2b6cff; 
  outline-offset: 4px;
  filter: drop-shadow(-6px 10px 8px rgba(0,0,0,0.10)) drop-shadow(0 0 16px rgba(43, 108, 255, 0.5));
  animation: pulse-outline 2s ease-in-out infinite;
}

@keyframes pulse-outline {
  0%, 100% { outline-color: #2b6cff; }
  50% { outline-color: #5890ff; }
}

.hex.connect-source{ outline: 2px dashed #00a3ff; outline-offset: 3px; }

.hex .note{
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  line-height: 1.2;
}
.hex .text-bubble{
  display: inline-block;
  padding: 6px 8px;
  border-radius: 10px;
  background: #ffffff;
  max-width: 100%;
  outline: none;
  font-size: 14px;
  word-break: break-word;
}

.conn-line{
  stroke: rgba(0,0,0,0.35);
  stroke-width: 3;
  fill: none;
  transition: stroke 120ms ease, stroke-width 120ms ease, opacity 120ms ease;
}
.conn-line:hover{ stroke: rgba(0,0,0,0.6); stroke-width: 4; }

.hide-completed .hex.completed{ display: none !important; }

/* Drawing selection */
.drawing-object {
  cursor: pointer;
  transition: opacity 120ms ease, outline-color 160ms ease;
}
.drawing-object:hover {
  opacity: 0.8;
}
.drawing-object.selected-drawing {
  outline: 6px solid #2b6cff !important;
  outline-offset: 6px !important;
  filter: drop-shadow(0 0 20px rgba(43, 108, 255, 0.8)) drop-shadow(0 0 8px rgba(43, 108, 255, 1));
  animation: pulse-outline 2s ease-in-out infinite;
}

/* Image selection - blue border since outline doesn't work on SVG image */
image.selected-drawing {
  outline: none !important;
  filter: drop-shadow(0 0 0 3px #2b6cff) drop-shadow(0 0 12px rgba(43,108,255,0.6)) !important;
}
#image-resize-overlay {
  position: absolute;
  pointer-events: none;
  display: none;
  z-index: 5000;
}
#image-resize-overlay .resize-box {
  position: absolute;
  border: 2px solid #2b6cff;
  pointer-events: none;
}
#image-resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #2b6cff;
  border: 2px solid #fff;
  border-radius: 3px;
  bottom: -7px;
  right: -7px;
  cursor: se-resize;
  pointer-events: all;
  z-index: 5001;
}

/* Toolbar */
#toolbar{
  position: fixed;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 10px;

  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #d0d0d0;
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.12);
  z-index: 14000;
}
#toolbar button{
  width: 44px;
  height: 44px;
  border: 1px solid #d0d0d0;
  border-radius: 12px;
  background: #ffffff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}
#toolbar button:hover{ background: rgba(0,0,0,0.06); }

.tool-menu{
  position: fixed;
  right: 72px;
  top: 50%;
  transform: translateY(-50%);
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.14);
  z-index: 14001;
  max-height: 90vh;
  overflow-y: auto;
}
.tool-menu.hidden{ display: none; }

.tool-item{
  display: flex;
  align-items: center;
  width: 100%;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.10);
  background: #ffffff;
  cursor: pointer;
  padding: 0 10px;
  text-align: left;
  gap: 0;
}
.tool-item .tool-icon{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  font-size: 15px;
  line-height: 1;
  /* No background - the .tool-item border is the container */
}
.tool-item:hover{ background: rgba(0,0,0,0.04); }
.tool-item span:not(.tool-icon){ font-size: 13px; font-weight: 600; opacity: 0.80; margin-left: 8px; }

.tool-separator{
  height: 1px;
  background: rgba(0,0,0,0.10);
  margin: 4px 2px;
}

/* Drawing panel */
.draw-panel{
  position: fixed;
  right: 230px;
  top: 50%;
  transform: translateY(-50%);
  width: 190px;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.14);
  z-index: 14000;
}
.draw-panel.hidden{ display: none; }

.draw-title{
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1px;
  opacity: 0.85;
  margin-bottom: 8px;
}

.draw-row{
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}
.draw-row span{
  width: 64px;
  font-size: 12px;
  font-weight: 700;
  opacity: 0.8;
}
.draw-row input[type="color"]{
  width: 44px;
  height: 28px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  padding: 0;
  background: transparent;
}
.draw-row input[type="range"]{ flex: 1; }
.draw-row input[type="number"]{
  width: 54px;
  height: 30px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 10px;
  padding: 0 8px;
  font-size: 12px;
}
.draw-hint{ font-size: 11px; opacity: 0.65; margin-top: 6px; }

.draw-text-input{
  position: fixed;
  z-index: 20000;
  border: 1px solid rgba(0,0,0,0.22);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 220px;
  font-size: 14px;
  outline: none;
  box-shadow: 0 16px 34px rgba(0,0,0,0.20);
}
.draw-text-input.hidden{ display: none; }

/* Zoom UI */
#zoom-ui{
  position: fixed;
  left: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.12);
  z-index: 14000;
}
#zoom-ui button{
  height: 36px;
  min-width: 44px;
  padding: 0 12px;
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  font-size: 18px;
  font-weight: 700;
}
#zoom-ui button:hover{ background: rgba(0,0,0,0.06); }
#zoom-reset{ min-width: 70px; } /* prevents clipping */
#zoom-indicator{
  min-width: 60px;
  text-align: center;
  font-weight: 800;
  opacity: 0.8;
}

/* Mode indicator */
#mode-indicator{
  position: fixed;
  left: 50%;
  top: 66px;
  transform: translateX(-50%);
  padding: 10px 14px;
  background: rgba(0,0,0,0.75);
  color: white;
  border-radius: 12px;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 1px;
  z-index: 16000;
}
#mode-indicator.hidden{ display: none; }

/* Bottom-right hint */
#help-hint{
  position: fixed;
  right: 14px;
  bottom: 14px;
  font-weight: 600;
  letter-spacing: 1px;
  font-size: 12px;
  opacity: 0.55;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 12px;
  padding: 8px 10px;
  box-shadow: 0 10px 28px rgba(0,0,0,0.08);
  z-index: 14000;
  user-select: none;
  pointer-events: none;
}

/* Help panel */
#help-panel{
  position: fixed;
  right: 14px;
  top: 66px;
  width: 340px;
  max-height: calc(100vh - 140px);
  overflow: auto;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.14);
  z-index: 15500;
}
#help-panel.hidden{ display: none; }

.panel-title{
  position: sticky;
  top: 0;
  background: rgba(255,255,255,0.96);
  border-bottom: 1px solid rgba(0,0,0,0.08);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
  font-weight: 800;
  letter-spacing: 1px;
  font-size: 13px;
}
.panel-close{
  width: 32px;
  height: 32px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-size: 16px;
}
.panel-close:hover{ background: rgba(0,0,0,0.06); }
.panel-body{ padding: 12px; }
.panel-section{ margin-bottom: 14px; }
.panel-heading{ font-weight: 800; opacity: 0.85; margin-bottom: 8px; }
.panel-body ul{ padding-left: 18px; }
.panel-body li{ margin: 6px 0; font-size: 13px; line-height: 1.35; }

/* Inspector (alignment fixed) */
#inspector-popup{
  position: fixed;
  left: 14px;
  top: 66px;
  width: 270px;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.14);
  z-index: 15500;
  padding: 10px 12px;
}
#inspector-popup.hidden{ display: none; }

/* Drawing Inspector */
#drawing-inspector{
  position: fixed;
  left: 14px;
  top: 66px;
  width: 270px;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.14);
  z-index: 15500;
  padding: 10px 12px;
}
#drawing-inspector.hidden{ display: none; }

.inspector-title{
  font-weight: 800;
  letter-spacing: 1px;
  margin-bottom: 10px;
  cursor: move;
  user-select: none;
  font-size: 13px;
}

/* ✅ Clean, consistent grid */
.inspector-row{
  display: grid;
  grid-template-columns: 92px 1fr auto; /* label | range/select | number/color */
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0.85;
}
.inspector-row input[type="range"]{ width: 100%; }
.inspector-row input[type="number"]{ width: 70px; padding: 4px 6px; }
.inspector-row input[type="color"]{ width: 44px; height: 28px; padding: 0; border: none; background: transparent; }
.inspector-row select{ width: 100%; padding: 4px 6px; }
.inspector-inline{ display: flex; gap: 6px; justify-content: flex-end; grid-column: 2 / 4; }
.inspector-inline button{
  width: 34px;
  height: 30px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
}
.inspector-inline button:hover{ background: rgba(0,0,0,0.06); }
.inspector-inline button.active{ outline: 2px solid rgba(43,108,255,0.35); outline-offset: 2px; }

.inspector-btn{
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  margin-top: 8px;
}
.inspector-btn:hover{ background: rgba(0,0,0,0.06); }
.inspector-btn:disabled{ opacity: 0.45; cursor: not-allowed; }
.inspector-btn.danger{ border-color: rgba(255,0,0,0.25); }
.inspector-btn.danger:hover{ background: rgba(255,0,0,0.06); }

/* Completed / halftone */
.hex.completed{ opacity: 0.45; filter: grayscale(0.55) contrast(0.95) drop-shadow(-5px 9px 7px rgba(0,0,0,0.08)); }
.hex.completed::after{
  /* diagonal hatch (original feel) */
  background-image: repeating-linear-gradient(
    45deg,
    rgba(0,0,0,0.16) 0px,
    rgba(0,0,0,0.16) 2px,
    transparent 2px,
    transparent 7px
  );
}

/* Hexflows panel */
.hexflows-panel{
  position: fixed;
  right: 14px;
  top: 62px;
  width: 350px;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 16px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.14);
  z-index: 15500;
  padding: 12px;
}
.hexflows-panel.hidden{ display: none; }

.hexflows-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.hexflows-title{
  font-weight: 800;
  letter-spacing: 2px;
  font-size: 12px;
  opacity: 0.85;
}
.hexflows-close{
  width: 32px;
  height: 32px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-size: 16px;
}
.hexflows-close:hover{ background: rgba(0,0,0,0.06); }

.hexflows-actions{
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
}

/* ✅ FIX: Reset Canvas fits */
.hexflows-action{
  flex: 1;
  min-height: 44px;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
  white-space: normal;     /* allow wrap */
  line-height: 1.1;
}
.hexflows-action:hover{ background: rgba(0,0,0,0.06); }
.hexflows-action.danger{ border-color: rgba(255,0,0,0.25); }
.hexflows-action.danger:hover{ background: rgba(255,0,0,0.06); }

.hexflows-subtitle{
  font-weight: 800;
  font-size: 11px;
  opacity: 0.75;
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.hexflows-list{ display: flex; flex-direction: column; gap: 8px; }
.hexflows-empty{ font-size: 12px; opacity: 0.65; padding: 6px 2px; }

.hexflow-row{ display: flex; align-items: center; gap: 8px; }
.hexflow-item{
  flex: 1;
  text-align: left;
  height: 38px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hexflow-item:hover{ background: rgba(0,0,0,0.06); }
.hexflow-item.current{ outline: 2px solid rgba(43,108,255,0.35); outline-offset: 2px; }

.hexflow-mini{
  width: 32px;
  height: 32px;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.12);
  background: #fff;
  cursor: pointer;
  font-size: 15px;
}
.hexflow-mini:hover{ background: rgba(0,0,0,0.06); }
.hexflow-mini.danger{ border-color: rgba(255,0,0,0.22); }
.hexflow-mini.danger:hover{ background: rgba(255,0,0,0.06); }

/* ── Auth Screen ─────────────────────────────── */
#auth-screen {
  position: fixed; inset: 0; z-index: 10000;
  background: #1a1a2e;
  display: flex; align-items: center; justify-content: center;
}
#auth-screen.hidden { display: none; }

#auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 40px;
  width: 360px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

#auth-logo {
  font-size: 22px; font-weight: 900; letter-spacing: 2px;
  color: #1a1a2e; text-align: center; margin-bottom: 4px;
}

#auth-tabs {
  display: flex; gap: 0; border-radius: 8px; overflow: hidden;
  border: 1px solid #ddd;
}
.auth-tab {
  flex: 1; padding: 9px; border: none; background: #f5f5f5;
  cursor: pointer; font-size: 13px; font-weight: 600; color: #666;
  transition: all .15s;
}
.auth-tab.active {
  background: #1a1a2e; color: #fff;
}

#auth-error {
  font-size: 12px; color: #d32f2f; min-height: 16px;
  text-align: center;
}

#auth-email, #auth-password {
  width: 100%; padding: 11px 14px; border: 1.5px solid #ddd;
  border-radius: 8px; font-size: 14px; box-sizing: border-box;
  outline: none; transition: border-color .15s;
}
#auth-email:focus, #auth-password:focus { border-color: #1a1a2e; }

#auth-submit {
  width: 100%; padding: 12px; background: #1a1a2e; color: #fff;
  border: none; border-radius: 8px; font-size: 14px; font-weight: 700;
  cursor: pointer; transition: opacity .15s;
}
#auth-submit:hover { opacity: .85; }
#auth-submit:disabled { opacity: .5; cursor: default; }

#auth-offline-btn-wrap { text-align: center; }
#auth-offline {
  background: none; border: none; color: #888; font-size: 12px;
  cursor: pointer; text-decoration: underline; padding: 0;
}
#auth-offline span { color: #aaa; }

/* ── Account Panel ───────────────────────────── */
#account-btn { font-size: 12px; }

#account-panel {
  position: fixed; top: 48px; right: 12px; z-index: 9000;
  background: #fff; border: 1px solid #ddd; border-radius: 10px;
  padding: 14px 18px; box-shadow: 0 6px 24px rgba(0,0,0,.15);
  min-width: 200px; display: flex; flex-direction: column; gap: 10px;
}
#account-panel.hidden { display: none; }

#account-email {
  font-size: 13px; color: #444; word-break: break-all;
}

#account-signout {
  padding: 8px 14px; background: #f5f5f5; border: 1px solid #ddd;
  border-radius: 7px; font-size: 13px; cursor: pointer; font-weight: 600;
  color: #333;
}
#account-signout:hover { background: #ffe0e0; border-color: #d32f2f; color: #d32f2f; }

/* sync indicator in topbar */
#sync-indicator {
  font-size: 11px; color: #aaa; margin-left: 8px; align-self: center;
  transition: color .3s;
}
#sync-indicator.syncing { color: #f59e0b; }
#sync-indicator.synced  { color: #22c55e; }
#sync-indicator.error   { color: #d32f2f; }
