/* =====================================================
 * ホワイトボード - Whiteboard App
 * ===================================================== */

/* --- リセット・基盤 --- */
#handwriting-memo {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
}

#handwriting-memo *,
#handwriting-memo *::before,
#handwriting-memo *::after {
  box-sizing: border-box;
}

/* --- キャンバスラッパー --- */
.wb-canvas-wrapper {
  position: relative;
  margin-bottom: 20px;
  border: 1px solid #e0e0e0 !important;
  border-radius: 8px !important;
  overflow: visible;
  background: #fff !important;
}

.wb-canvas-wrapper .wb-canvas {
  border-radius: 0 0 7px 7px;
}

/* --- ツールバー --- */
.wb-toolbar {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 10px;
  background: #fafafa !important;
  border-bottom: 1px solid #e0e0e0 !important;
  border-radius: 7px 7px 0 0;
  user-select: none;
  overflow: visible;
}

.wb-toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
}

.wb-toolbar-separator {
  width: 1px;
  height: 24px;
  margin: 0 4px;
  background: #e0e0e0;
  flex-shrink: 0;
}

/* --- ツールバーボタン共通 --- */
.wb-btn {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 36px !important;
  height: 36px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 1px solid transparent !important;
  border-radius: 6px !important;
  background: transparent !important;
  color: #555 !important;
  cursor: pointer !important;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
  line-height: 1 !important;
  font-size: 14px !important;
  font-family: inherit !important;
  outline: none;
}

.wb-btn:focus-visible {
  outline: 2px solid #333 !important;
  outline-offset: 1px;
}

.wb-btn:hover {
  background: #f0f0f0 !important;
}

.wb-btn.wb-btn--active {
  background: #e8e8e8 !important;
  border-color: #ccc !important;
  color: #333 !important;
}

.wb-btn:disabled {
  opacity: 0.3;
  cursor: default !important;
}

.wb-btn:disabled:hover {
  background: transparent !important;
}

.wb-btn svg {
  pointer-events: none;
  display: block;
}

/* --- 太さドット --- */
.wb-thickness-dot {
  display: block;
  border-radius: 50%;
  background: currentColor;
}

.wb-thickness-dot--s {
  width: 4px;
  height: 4px;
}

.wb-thickness-dot--m {
  width: 8px;
  height: 8px;
}

.wb-thickness-dot--l {
  width: 14px;
  height: 14px;
}

/* --- カラーパレット --- */
.wb-color-btn {
  position: relative;
  display: block !important;
  width: 22px !important;
  height: 22px !important;
  padding: 0 !important;
  margin: 2px !important;
  border: 2px solid transparent !important;
  border-radius: 50% !important;
  background: var(--wb-color) !important;
  cursor: pointer !important;
  transition: border-color 0.15s, transform 0.15s;
  flex-shrink: 0;
  outline: none;
}

/* タッチターゲット拡張（44px） */
.wb-color-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.wb-color-btn:hover {
  transform: scale(1.15);
  background: var(--wb-color) !important;
}

.wb-color-btn:focus-visible {
  outline: 2px solid #333 !important;
  outline-offset: 2px;
}

.wb-color-btn.wb-btn--active {
  border-color: #333 !important;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px #333;
}

/* カスタム色 */
.wb-color-custom {
  position: relative;
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin: 2px;
  cursor: pointer;
  flex-shrink: 0;
}

/* タッチターゲット拡張 */
.wb-color-custom::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.wb-color-custom-input {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0 !important;
}

.wb-color-custom-swatch {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px dashed #ccc;
  background: conic-gradient(
    #e57373 0deg, #ffd54f 60deg, #81c784 120deg,
    #64b5f6 180deg, #ba68c8 240deg, #e57373 360deg
  );
  background-size: cover;
  transition: border-color 0.15s;
}

.wb-color-custom:hover .wb-color-custom-swatch {
  border-color: #999;
}

.wb-color-custom.wb-btn--active .wb-color-custom-swatch {
  border: 2px solid #333;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px #333;
}

/* --- サブメニュー矢印ボタン --- */
.wb-submenu-arrow {
  position: relative;
  width: 16px !important;
  min-width: 16px !important;
  height: 36px !important;
  padding: 0 !important;
  margin-left: -4px !important;
  border-radius: 0 6px 6px 0 !important;
}

/* タッチターゲット拡張 */
.wb-submenu-arrow::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
}

.wb-eraser-wrap,
.wb-shape-wrap,
.wb-stamp-wrap {
  display: flex !important;
  align-items: center !important;
}

.wb-eraser-wrap > .wb-btn[data-tool],
.wb-shape-wrap > .wb-btn[data-tool] {
  border-radius: 6px 0 0 6px !important;
}

/* --- スタンプパレット --- */
.wb-stamp-palette {
  min-width: auto !important;
  padding: 8px !important;
  right: 0;
}

.wb-stamp-grid {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 4px !important;
}

.wb-stamp-item {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 40px !important;
  height: 40px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 1px solid transparent !important;
  border-radius: 6px !important;
  background: transparent !important;
  color: #555 !important;
  cursor: pointer !important;
  transition: background 0.15s, border-color 0.15s;
  outline: none;
}

.wb-stamp-item:hover {
  background: #f0f0f0 !important;
}

.wb-stamp-item.wb-btn--active {
  background: #e8e8e8 !important;
  border-color: #ccc !important;
}

.wb-stamp-item:focus-visible {
  outline: 2px solid #333 !important;
  outline-offset: 1px;
}

.wb-stamp-item svg {
  pointer-events: none;
  display: block;
}

/* --- 消しゴムメニュー内のactive表示 --- */
.wb-eraser-menu .wb-menu-item.wb-btn--active,
.wb-shape-menu .wb-menu-item.wb-btn--active {
  background: #f0f0f0 !important;
  font-weight: 600;
}

/* --- オーバーフローメニュー --- */
.wb-menu-wrap {
  position: relative;
}

.wb-overflow-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 160px;
  padding: 4px 0;
  background: #fff !important;
  border: 1px solid #e0e0e0 !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12) !important;
  z-index: 100;
}

.wb-menu-item {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  width: 100% !important;
  padding: 8px 14px !important;
  margin: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: #333 !important;
  font-size: 13px !important;
  font-family: inherit !important;
  cursor: pointer !important;
  text-align: left !important;
  line-height: 1.4 !important;
  white-space: nowrap;
  outline: none;
}

.wb-menu-item:focus-visible {
  background: #f5f5f5 !important;
  outline: 2px solid #333 !important;
  outline-offset: -2px;
}

.wb-menu-item:hover {
  background: #f5f5f5 !important;
}

.wb-menu-item svg {
  flex-shrink: 0;
  pointer-events: none;
}

.wb-menu-item--danger {
  color: #e57373 !important;
}

.wb-menu-item--danger:hover {
  background: #fef0f0 !important;
}

.wb-menu-divider {
  height: 1px;
  margin: 4px 0;
  background: #e0e0e0;
}

/* --- キャンバス --- */
.wb-canvas {
  display: block;
  width: 100%;
  height: 500px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

/* --- キャンバス追加ボタン --- */
#wb-add-canvas {
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 100% !important;
  height: 44px !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 2px dashed #ccc !important;
  border-radius: 8px !important;
  background: transparent !important;
  color: #999 !important;
  cursor: pointer !important;
  font-family: inherit !important;
  transition: border-color 0.15s, color 0.15s;
}

#wb-add-canvas:hover {
  border-color: #999 !important;
  color: #666 !important;
}

#wb-add-canvas:focus-visible {
  outline: 2px solid #333 !important;
  outline-offset: 1px;
}

#wb-add-canvas svg {
  pointer-events: none;
}

/* --- トースト --- */
#wb-toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.wb-toast {
  padding: 10px 20px;
  background: rgba(61, 60, 53, 0.92);
  color: #fff !important;
  font-size: 13px !important;
  font-family: inherit !important;
  border-radius: 8px !important;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  white-space: nowrap;
}

.wb-toast--visible {
  opacity: 1;
  transform: translateY(0);
}

/* --- 確認モーダル --- */
.wb-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
}

.wb-confirm-box {
  background: #fff !important;
  border-radius: 12px !important;
  padding: 24px !important;
  min-width: 280px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18) !important;
}

.wb-confirm-msg {
  margin: 0 0 20px !important;
  font-size: 14px !important;
  font-family: inherit !important;
  color: #333 !important;
  line-height: 1.6 !important;
}

.wb-confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.wb-confirm-cancel {
  padding: 8px 18px !important;
  border: 1px solid #ccc !important;
  border-radius: 6px !important;
  background: transparent !important;
  color: #666 !important;
  font-size: 13px !important;
  font-family: inherit !important;
  cursor: pointer !important;
  line-height: 1.4 !important;
}

.wb-confirm-cancel:hover {
  background: #f5f5f5 !important;
}

.wb-confirm-ok {
  padding: 8px 18px !important;
  border: 1px solid transparent !important;
  border-radius: 6px !important;
  background: #3d3c35 !important;
  color: #fff !important;
  font-size: 13px !important;
  font-family: inherit !important;
  cursor: pointer !important;
  line-height: 1.4 !important;
}

.wb-confirm-ok:hover {
  background: #555 !important;
}

.wb-confirm-cancel:focus-visible,
.wb-confirm-ok:focus-visible {
  outline: 2px solid #333 !important;
  outline-offset: 1px;
}

/* --- ズームコントロール --- */
.wb-zoom-controls {
  display: inline-flex;
  align-items: center;
  gap: 0;
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  height: 28px;
}
.wb-zoom-btn {
  width: 26px !important;
  height: 26px !important;
  min-width: 26px;
  padding: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  background: transparent;
}
.wb-zoom-btn:hover {
  background: rgba(0, 0, 0, 0.06);
}
.wb-zoom-indicator {
  width: auto !important;
  min-width: 38px;
  height: 26px !important;
  padding: 0 4px !important;
  font-size: 11px !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  border-radius: 0 !important;
  border-left: 1px solid #ddd !important;
  border-right: 1px solid #ddd !important;
  border-top: none !important;
  border-bottom: none !important;
  line-height: 26px;
}
.wb-zoom-indicator[data-at-default="true"] {
  opacity: 0.4;
}

/* --- テキスト入力オーバーレイ --- */
.wb-text-input {
  position: absolute;
  z-index: 20;
  background: transparent;
  border: 1px dashed rgba(100, 100, 100, 0.4);
  border-radius: 2px;
  padding: 2px 4px;
  margin: 0;
  min-width: 60px;
  min-height: 1.4em;
  font-family: sans-serif;
  line-height: 1.4;
  outline: none;
  resize: none;
  overflow: hidden;
  box-sizing: border-box;
}

/* --- レスポンシブ --- */
@media screen and (max-width: 600px) {
  .wb-toolbar {
    gap: 2px;
    padding: 4px 6px;
    flex-wrap: wrap;
  }

  .wb-toolbar-separator {
    width: 0;
    height: 0;
    margin: 0;
    border: none;
    visibility: hidden;
  }

  .wb-toolbar-group {
    padding: 2px 4px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 4px;
  }

  .wb-toolbar-group.wb-tools {
    order: 1;
  }

  .wb-toolbar-group.wb-thickness {
    order: 2;
  }

  .wb-toolbar-group.wb-colors {
    order: 4;
    flex-basis: 100%;
    justify-content: center;
  }

  .wb-toolbar-group.wb-actions {
    order: 3;
    margin-left: auto;
  }

  .wb-canvas {
    height: 400px;
  }

  .wb-btn {
    width: 40px !important;
    height: 40px !important;
  }

  .wb-color-btn {
    width: 24px !important;
    height: 24px !important;
  }

  .wb-color-custom {
    width: 24px;
    height: 24px;
  }

  .wb-color-custom-swatch {
    width: 24px;
    height: 24px;
  }

  .wb-overflow-menu {
    right: auto;
    left: 0;
    min-width: 140px;
  }

  .wb-menu-wrap {
    position: static;
  }

  .wb-eraser-wrap,
  .wb-shape-wrap,
  .wb-stamp-wrap {
    position: relative;
  }

  .wb-submenu-arrow {
    width: 18px !important;
    min-width: 18px !important;
    height: 40px !important;
  }

  .wb-stamp-palette {
    left: 0 !important;
    right: auto !important;
  }

  .wb-stamp-item {
    width: 44px !important;
    height: 44px !important;
  }
}
