/* Roughdraw whiteboard — full app chrome styling */

:root {
  --color-primary: #6965db;
  --color-primary-darker: #5b57d1;
  --color-primary-light: #e0dfff;
  --color-danger: #e03131;
  --island-bg: #ffffff;
  --text-main: #1b1b1f;
  --text-secondary: #54545e;
  --icon-color: var(--text-main);
  --border-muted: rgba(0, 0, 0, 0.08);
  --shadow-island: 0px 0px 0 1px rgba(0, 0, 0, 0.04), 0px 4px 12px -2px rgba(0, 0, 0, 0.18);
  --bg-main: #ffffff;
  --kbd-bg: #efefef;
  --popup-bg: #ffffff;
}

:root[data-theme='dark'] {
  --color-primary-light: #3a3860;
  --island-bg: #232329;
  --text-main: #e3e3e8;
  --text-secondary: #b8b8c0;
  --border-muted: rgba(255, 255, 255, 0.09);
  --shadow-island: 0px 0px 0 1px rgba(255, 255, 255, 0.05), 0px 4px 14px -2px rgba(0, 0, 0, 0.55);
  --bg-main: #121212;
  --kbd-bg: #34343c;
  --popup-bg: #2a2a32;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  overscroll-behavior: none;
}

#root { position: fixed; inset: 0; }

.whiteboard-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}

.island {
  background: var(--island-bg);
  border-radius: 10px;
  box-shadow: var(--shadow-island);
}

/* ------------------------------------------------------------------ */
/* Toolbar (top-center)                                               */
/* ------------------------------------------------------------------ */

.layer-ui__wrapper {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.layer-ui__wrapper > * { pointer-events: auto; }

.Toolbar-island {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 7px;
  max-width: min(96vw, 760px);
  z-index: 30;
}

.Toolbar-container {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: center;
}

.ToolIcon {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  border-radius: 8px;
}

.Icon-btn {
  width: 40px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--icon-color);
  transition: background 90ms ease-in-out, color 90ms ease-in-out;
}
.ToolIcon:hover .Icon-btn { background: rgba(105, 101, 213, 0.08); }
.ToolIcon:active .Icon-btn { transform: scale(0.97); }
.Icon-btn.active {
  background: var(--color-primary-light);
  color: var(--color-primary-darker);
}
.lock-btn { margin-right: 7px; }

.svg-icon, .svg-wrap svg {
  width: 20px;
  height: 20px;
  display: block;
}

/* ------------------------------------------------------------------ */
/* Properties panel (left)                                            */
/* ------------------------------------------------------------------ */

.properties-panel {
  position: absolute;
  top: 64px;
  left: 12px;
  width: 232px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  z-index: 25;
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.property-row { display: grid; grid-template-columns: 86px 1fr; align-items: center; gap: 8px; }
.property-row.flexwrap { display: flex; flex-wrap: wrap; gap: 6px; }
.property-label { font-size: 13px; color: var(--text-secondary); }
.property-controls { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1; }

.segmented {
  display: inline-flex;
  background: transparent;
  border: 1px solid var(--border-muted);
  border-radius: 8px;
  padding: 1px;
  width: 100%;
}
.seg {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 4px 4px;
  font-size: 11.5px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1.1;
  flex: 1 1 0;
  min-width: 0;
  white-space: nowrap;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
.seg:hover { background: rgba(105, 101, 213, 0.08); color: var(--text-main); }
.seg.active { background: var(--color-primary-light); color: var(--color-primary-darker); font-weight: 600; }

.row-value {
  appearance: none;
  border: 1px solid var(--border-muted);
  background: transparent;
  border-radius: 8px;
  height: 28px;
  min-width: 74px;
  padding: 2px 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-main);
  justify-content: space-between;
}
.row-value::after {
  content: '';
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  opacity: 0.55;
}
.swatch-chip {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(128, 128, 140, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  display: inline-block;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, 22px);
  gap: 6px;
}
.swatches.small { grid-template-columns: repeat(6, 20px); }
.swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 1px solid var(--border-muted);
  cursor: pointer;
  padding: 0;
}
.swatches.small .swatch { width: 20px; height: 20px; }
.swatch:hover { transform: scale(1.08); }
.swatch.picked { outline: 2px solid var(--color-primary); outline-offset: 1px; }
.custom-color-row { display: flex; gap: 6px; margin-top: 8px; align-items: center; }
.custom-color-row input[type='text'] {
  flex: 1;
  border: 1px solid var(--border-muted);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
  background: transparent;
  color: var(--text-main);
}
.custom-color-row input[type='color'] {
  width: 26px;
  height: 24px;
  border: 1px solid var(--border-muted);
  background: transparent;
  border-radius: 6px;
  padding: 1px;
}

.palette-pop {
  position: fixed;
  z-index: 90;
  padding: 12px;
}

input[type='range'] { accent-color: var(--color-primary); width: 118px; }
.opacity-val { font-size: 11.5px; color: var(--text-secondary); min-width: 32px; text-align: right; }

.mini-action {
  appearance: none;
  border: 1px solid var(--border-muted);
  background: transparent;
  border-radius: 8px;
  width: 30px;
  height: 26px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-main);
}
.mini-action:hover { background: rgba(105, 101, 213, 0.08); }
.mini-action svg { width: 15px; height: 15px; }

.select-arrowhead {
  border: 1px solid var(--border-muted);
  background: transparent;
  color: var(--text-main);
  border-radius: 7px;
  padding: 3px 4px;
  font-size: 12px;
  max-width: 66px;
}

/* ------------------------------------------------------------------ */
/* Top-right island                                                   */
/* ------------------------------------------------------------------ */

.top-right-island {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 2px;
  padding: 4px 6px;
  z-index: 30;
}
.island-btn-wrap { display: block; }

/* ------------------------------------------------------------------ */
/* Bottom-left menu + bottom-right zoom                               */
/* ------------------------------------------------------------------ */

.main-menu-island {
  position: absolute;
  left: 12px;
  bottom: 14px;
  z-index: 30;
}
.menu-btn {
  width: 42px;
  height: 38px;
  border: 0;
  background: var(--island-bg);
  box-shadow: var(--shadow-island);
  border-radius: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--icon-color);
}
.menu-btn:hover { color: var(--color-primary-darker); }

.zoom-island {
  position: absolute;
  right: 12px;
  bottom: 14px;
  display: flex;
  align-items: center;
  padding: 2px;
  gap: 2px;
  z-index: 30;
}
.zoom-btn {
  width: 30px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 17px;
  cursor: pointer;
  color: var(--text-main);
}
.zoom-btn:hover { background: rgba(105, 101, 213, 0.08); }
.zoom-value {
  min-width: 46px;
  text-align: center;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 2px;
  border-radius: 6px;
}
.zoom-value:hover { color: var(--color-primary-darker); }

.zoom-pop {
  position: fixed;
  z-index: 95;
  display: flex;
  flex-direction: column;
  padding: 6px;
  min-width: 150px;
}
.zoom-item {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-main);
}
.zoom-item:hover { background: rgba(105, 101, 213, 0.1); }

.menu-panel {
  position: fixed;
  z-index: 85;
  width: 252px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.name-row input {
  width: 100%;
  border: 1px solid var(--border-muted);
  background: transparent;
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 600;
}
.menu-section-title {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: 6px 4px 3px;
}
.menu-sep { height: 1px; background: var(--border-muted); margin: 6px 0; }
.menu-item {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 7px 9px;
  border-radius: 8px;
  font-size: 13.5px;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}
.menu-item:hover { background: rgba(105, 101, 213, 0.09); }
.grid-item { justify-content: space-between; }
.grid-select {
  border: 1px solid var(--border-muted);
  background: transparent;
  color: var(--text-main);
  border-radius: 7px;
  font-size: 12px;
  padding: 3px 5px;
}

/* ------------------------------------------------------------------ */
/* Context menu                                                       */
/* ------------------------------------------------------------------ */

.context-menu {
  position: fixed;
  z-index: 120;
  padding: 5px;
  display: flex;
  flex-direction: column;
  min-width: 210px;
}
.context-item {
  appearance: none;
  border: 0;
  background: transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 7px 10px;
  font-size: 13.5px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--text-main);
}
.context-item:hover { background: rgba(105, 101, 213, 0.1); }
.context-item.danger { color: var(--color-danger); }
.ctx-shortcut { font-size: 11.5px; color: var(--text-secondary); }

/* ------------------------------------------------------------------ */
/* Help dialog                                                        */
/* ------------------------------------------------------------------ */

.help-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.35);
  display: grid;
  place-items: center;
}
.help-card {
  width: min(92vw, 660px);
  max-height: 84vh;
  overflow-y: auto;
  padding: 18px 22px;
}
.help-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.help-header h3 { margin: 0; font-size: 18px; }
.close-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}
.shortcut-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.shortcut-table caption {
  text-align: left;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: 8px 0 4px;
}
.shortcut-table td { padding: 4.5px 4px; font-size: 13.5px; border-top: 1px solid var(--border-muted); }
.shortcut-table td:last-child { text-align: right; }
kbd {
  background: var(--kbd-bg);
  border-radius: 5px;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 11.5px;
  color: var(--text-main);
}

/* ------------------------------------------------------------------ */
/* Welcome hints / toast / stats HUD                                  */
/* ------------------------------------------------------------------ */

.welcome-hints {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 15;
  pointer-events: none;
}
.hint-card {
  pointer-events: auto;
  padding: 20px 26px;
  max-width: 430px;
  text-align: center;
  animation: hint-zoom-settle 420ms cubic-bezier(.2,.9,.27,1.4) both;
}
@keyframes hint-zoom-settle {
  from { transform: scale(1.22); opacity: 0; filter: blur(2px); }
  to   { transform: scale(1); opacity: 1; filter: blur(0); }
}
.hint-title { font-weight: 700; font-size: 19px; margin-bottom: 8px; }
.hint-sub { font-size: 13.5px; color: var(--text-secondary); line-height: 1.65; }
.hint-dismiss {
  margin-top: 14px;
  appearance: none;
  border: 0;
  background: var(--color-primary);
  color: #fff;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 13.5px;
  cursor: pointer;
}
.hint-dismiss:hover { background: var(--color-primary-darker); }

.toast {
  position: absolute;
  bottom: 62px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 150;
  padding: 8px 16px;
  font-size: 13.5px;
  border-radius: 8px;
}

.stats-overlay {
  position: absolute;
  top: 12px;
  left: 256px;
  z-index: 20;
  background: rgba(20, 20, 24, 0.78);
  color: #cfeacc;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 12px;
  display: flex;
  gap: 8px;
}
.hud-mono { font-family: 'SF Mono', Consolas, Menlo, monospace; letter-spacing: 0.02em; }
.hud-sep { opacity: 0.5; }

/* ------------------------------------------------------------------ */
/* Text editor                                                        */
/* ------------------------------------------------------------------ */

.text-editor {
  position: fixed;
  z-index: 80;
  background: transparent;
  border: 1.5px dashed rgba(105, 101, 213, 0.55);
  outline: none;
  resize: none;
  padding: 2px 3px;
  overflow: hidden;
  white-space: pre;
  min-height: 1em;
}

.link-prompt {
  position: fixed;
  z-index: 210;
  width: 360px;
  max-width: 92vw;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.link-title { font-weight: 700; font-size: 15px; }
.link-input {
  border: 1px solid var(--border-muted);
  border-radius: 8px;
  background: transparent;
  color: var(--text-main);
  padding: 7px 9px;
  font-size: 13.5px;
}
.link-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn {
  appearance: none;
  border: 1px solid var(--border-muted);
  background: transparent;
  color: var(--text-main);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn.primary { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btn.primary:hover { background: var(--color-primary-darker); }
.btn:hover:not(.primary) { background: rgba(105, 101, 213, 0.08); }

/* ------------------------------------------------------------------ */
/* Responsive / mobile                                                */
/* ------------------------------------------------------------------ */

@media (max-width: 720px) {
  .Toolbar-island {
    top: 6px;
    max-width: calc(100vw - 104px);
  }
  .top-right-island { top: 6px; right: 8px; padding: 2px 3px; }
  .Icon-btn { width: 34px; height: 34px; }

  .properties-panel {
    top: auto;
    bottom: 60px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 44vh;
    padding: 10px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    align-content: flex-start;
    overflow-x: visible;
  }
  .properties-panel .property-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 128px;
  }
  .property-label { font-size: 11px; }

  .welcome-hints .hint-card { margin: 0 14px; }
  .hint-sub kbd { font-size: 10.5px; }

  .zoom-value { min-width: 38px; }
  .stats-overlay { left: 12px; top: 56px; flex-wrap: wrap; }

  .menu-panel { width: min(88vw, 260px); }
}

@media (max-width: 400px) {
  .Toolbar-container { gap: 0; }
  .Icon-btn { width: 31px; height: 31px; }
  .svg-icon { width: 17px; height: 17px; }
}
