:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252540;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --accent-primary: #667eea;
  --accent-secondary: #764ba2;
  --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --border-radius: 12px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Meiryo', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}

.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* サイドバー */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--bg-tertiary);
  overflow-y: auto;
  overflow-x: hidden;
  transition: all 0.3s ease;
  position: relative;
  z-index: 100;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
}

.sidebar.collapsed .sidebar-content {
  opacity: 0;
  pointer-events: none;
}

.sidebar-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  transition: opacity 0.2s ease;
}

.sidebar-toggle {
  display: none;
  position: absolute;
  right: -40px;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 60px;
  background: var(--bg-secondary);
  border: none;
  border-radius: 0 8px 8px 0;
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  z-index: 101;
  box-shadow: 2px 0 10px rgba(0,0,0,0.3);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.logo i {
  font-size: 28px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo h1 {
  font-size: 20px;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.section {
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
  padding: 16px;
}

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title i {
  color: var(--accent-primary);
}

/* ボタン */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
}

.btn-primary {
  background: var(--accent-gradient);
  color: white;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--bg-tertiary);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid transparent;
}

.btn-icon:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

.btn-icon.active {
  background: var(--accent-gradient);
  border-color: transparent;
}

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ファイル入力 */
.file-input-wrapper {
  position: relative;
}

.file-input-wrapper input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.file-input-btn {
  width: 100%;
  background: var(--bg-secondary);
  border: 2px dashed var(--bg-tertiary);
  padding: 16px;
  text-align: center;
  border-radius: 8px;
  transition: all 0.2s ease;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.file-input-btn:hover {
  border-color: var(--accent-primary);
  background: rgba(102, 126, 234, 0.1);
}

.file-input-btn i {
  font-size: 20px;
  color: var(--accent-primary);
}

/* スライダー */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.slider-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.slider-value {
  width: 60px;
  padding: 4px 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 13px;
  text-align: center;
}

input[type="range"] {
  width: 100%;
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  outline: none;
  -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  background: var(--accent-gradient);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  border: none;
}

/* レイヤーリスト */
.layer-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}

.layer-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 13px;
  border: 2px solid transparent;
  min-height: 44px;
}

.layer-item:hover {
  background: rgba(102, 126, 234, 0.1);
}

.layer-item.selected {
  border-color: var(--accent-primary);
  background: rgba(102, 126, 234, 0.15);
}

.layer-item.locked {
  opacity: 0.6;
}

.layer-item .lock-icon {
  margin-left: auto;
  color: var(--warning);
}

/* ツールグループ */
.tool-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tool-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 16px;
}

.tool-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

.tool-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: white;
}

/* カラーピッカー */
input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 2px;
  border: 2px solid var(--bg-tertiary);
  border-radius: 8px;
  background: var(--bg-secondary);
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 2px;
}

input[type="color"]::-webkit-color-swatch {
  border-radius: 4px;
  border: none;
}

/* セレクト */
select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
}

select:focus {
  outline: none;
  border-color: var(--accent-primary);
}

/* チェックボックス */
.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  min-height: 44px;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent-primary);
}

/* ラジオボタン */
.radio-group {
  display: flex;
  gap: 16px;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  min-height: 44px;
}

.radio-option input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-primary);
}

/* フィルターボタン */
.filter-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.filter-btn {
  padding: 10px 8px;
  background: var(--bg-secondary);
  border: 2px solid transparent;
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 44px;
}

.filter-btn:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent-primary);
}

.filter-btn.active {
  background: var(--accent-gradient);
  border-color: transparent;
}

/* メインエリア */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ツールバー */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
  gap: 16px;
  flex-wrap: wrap;
}

.toolbar-left,
.toolbar-center,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  padding: 4px 12px;
  border-radius: 8px;
}

.zoom-level {
  font-size: 13px;
  color: var(--text-secondary);
  min-width: 50px;
  text-align: center;
}

/* キャンバスエリア */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a12;
  background-image: 
    linear-gradient(45deg, #1a1a2e 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a2e 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a2e 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  overflow: auto;
  position: relative;
  padding: 20px;
}

.canvas-container {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  overflow: auto;
}

.canvas-wrapper {
  position: relative;
  box-shadow: var(--shadow);
  display: inline-block;
}

#myCanvas {
  display: block;
  background: #000;
  cursor: default;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

#myCanvas.eraser-mode {
  cursor: crosshair;
}

#myCanvas.brush-mode {
  cursor: crosshair;
}

#myCanvas.text-mode {
  cursor: text;
}

#myCanvas.crop-mode {
  cursor: crosshair;
}

#myCanvas.resize-nwse {
  cursor: nwse-resize;
}

#myCanvas.resize-nesw {
  cursor: nesw-resize;
}

#myCanvas.resize-ns {
  cursor: ns-resize;
}

#myCanvas.resize-ew {
  cursor: ew-resize;
}

/* ドロップオーバーレイ */
.drop-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(102, 126, 234, 0.2);
  border: 4px dashed var(--accent-primary);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  pointer-events: none;
}

.drop-overlay.active {
  display: flex;
}

.drop-overlay-content {
  text-align: center;
  color: var(--accent-primary);
}

.drop-overlay-content i {
  font-size: 64px;
  margin-bottom: 16px;
}

.drop-overlay-content p {
  font-size: 20px;
  font-weight: 600;
}

/* グリッドオーバーレイ */
.grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
  background-image: 
    linear-gradient(rgba(102, 126, 234, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(102, 126, 234, 0.1) 1px, transparent 1px);
  background-size: 50px 50px;
}

.grid-overlay.active {
  display: block;
}

/* ガイドライン */
.guide-lines {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: none;
}

.guide-lines.active {
  display: block;
}

.guide-lines::before,
.guide-lines::after {
  content: '';
  position: absolute;
  background: rgba(102, 126, 234, 0.5);
}

.guide-lines::before {
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
  transform: translateX(-50%);
}

.guide-lines::after {
  top: 50%;
  left: 0;
  width: 100%;
  height: 1px;
  transform: translateY(-50%);
}

/* ヒントボックス */
.hint-box {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1000;
  max-width: 90%;
}

.hint-box.hidden {
  display: none;
}

.hint-box.hint-info {
  border-left: 4px solid var(--accent-primary);
}

.hint-box.hint-success {
  border-left: 4px solid var(--success);
}

.hint-box.hint-action {
  border-left: 4px solid var(--warning);
}

.hint-icon {
  font-size: 18px;
  color: var(--accent-primary);
}

.hint-text {
  font-size: 14px;
}

.hint-arrow {
  position: fixed;
  width: 40px;
  height: 40px;
  pointer-events: none;
  z-index: 999;
}

.hint-arrow.hidden {
  display: none;
}

/* モーダル */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  padding: 24px;
  border-radius: var(--border-radius);
  max-width: 400px;
  width: 90%;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

/* 保存メニュー */
.save-menu {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--bg-secondary);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: none;
  min-width: 200px;
  z-index: 100;
  overflow: hidden;
}

.save-menu.active {
  display: block;
}

.save-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.2s ease;
  color: var(--text-primary);
  font-size: 14px;
  min-height: 48px;
}

.save-menu-item:hover {
  background: var(--bg-tertiary);
}

.save-menu-item i {
  width: 20px;
  color: var(--accent-primary);
}

.save-btn-wrapper {
  position: relative;
}

/* テキスト入力オーバーレイ */
.text-input-overlay {
  position: absolute;
  background: var(--bg-secondary);
  border: 2px solid var(--accent-primary);
  border-radius: 8px;
  padding: 8px;
  display: none;
  z-index: 500;
  min-width: 200px;
  max-width: 90vw;
  box-shadow: var(--shadow);
}

.text-input-overlay.active {
  display: block;
}

.canvas-text-input {
  width: 100%;
  min-height: 60px;
  background: var(--bg-tertiary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 4px;
  color: var(--text-primary);
  padding: 8px;
  font-size: 16px;
  resize: both;
  outline: none;
}

.canvas-text-input:focus {
  border-color: var(--accent-primary);
}

.text-input-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.text-input-buttons .btn {
  flex: 1;
  padding: 8px;
  font-size: 12px;
  min-height: 36px;
}

/* ハイライト効果 */
.highlight {
  animation: pulse 1.5s infinite;
  position: relative;
}

@keyframes pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(102, 126, 234, 0);
  }
}

/* スクロールバー */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

/* テキストスタイルボタン */
.text-style-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 1px solid var(--bg-tertiary);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.text-style-btn:hover {
  background: var(--bg-tertiary);
}

.text-style-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

/* 共有ボタン */
.share-btn {
  background: var(--success);
  color: white;
}

.share-btn:hover {
  background: #16a34a;
}

/* ==================================
   スマホ対応（レスポンシブ）
   ================================== */

@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }

  /* サイドバー */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 300px;
    min-width: 300px;
    z-index: 1000;
    transform: translateX(0);
    transition: transform 0.3s ease;
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 300px;
    min-width: 300px;
  }

  .sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .sidebar.collapsed .sidebar-toggle {
    right: -50px;
  }

  /* メインエリア */
  .main-area {
    width: 100%;
    height: 100vh;
  }

  /* ツールバー */
  .toolbar {
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .toolbar-left,
  .toolbar-center,
  .toolbar-right {
    flex-shrink: 0;
  }

  .zoom-controls {
    display: none;
  }

  /* キャンバスエリア */
  .canvas-area {
    padding: 10px;
  }

  /* ボタンサイズ拡大 */
  .btn {
    min-height: 48px;
    padding: 12px 16px;
  }

  .btn-icon {
    width: 48px;
    height: 48px;
  }

  .tool-btn {
    width: 48px;
    height: 48px;
    font-size: 18px;
  }

  .filter-btn {
    min-height: 48px;
    padding: 12px 8px;
  }

  .layer-item {
    min-height: 48px;
    padding: 12px;
  }

  /* セクション */
  .section {
    padding: 12px;
  }

  /* ヒントボックス */
  .hint-box {
    bottom: 70px;
    left: 10px;
    right: 10px;
    transform: none;
    max-width: none;
  }

  /* モーダル */
  .modal-content {
    margin: 16px;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* 保存メニュー */
  .save-menu {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    border-radius: 16px 16px 0 0;
    min-width: auto;
  }

  .save-menu-item {
    padding: 16px 20px;
    min-height: 56px;
  }

  /* テキスト入力オーバーレイ */
  .text-input-overlay {
    position: fixed;
    left: 10px !important;
    right: 10px;
    bottom: 80px;
    top: auto !important;
    width: auto;
    min-width: auto;
  }

  .canvas-text-input {
    min-height: 80px;
    font-size: 18px;
  }

  /* フォント選択 */
  select {
    font-size: 16px;
    min-height: 48px;
  }

  /* スライダー */
  input[type="range"]::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
  }

  /* カラーピッカー */
  input[type="color"] {
    width: 48px;
    height: 48px;
  }

  /* ロゴ */
  .logo h1 {
    font-size: 18px;
  }

  /* レイヤーリスト */
  .layer-list {
    max-height: 150px;
  }

  /* フィルターグリッド */
  .filter-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* 非常に小さい画面 */
@media (max-width: 480px) {
  .sidebar {
    width: 100%;
    min-width: 100%;
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
  }

  .toolbar {
    padding: 6px 8px;
  }

  .btn-group {
    gap: 4px;
  }

  .section-title {
    font-size: 11px;
  }

  .hint-box {
    padding: 10px 14px;
    font-size: 13px;
  }
}

/* 横向き対応 */
@media (max-width: 768px) and (orientation: landscape) {
  .sidebar {
    width: 280px;
    min-width: 280px;
  }

  .toolbar {
    padding: 6px 12px;
  }

  .btn {
    min-height: 40px;
    padding: 8px 12px;
  }

  .btn-icon {
    width: 40px;
    height: 40px;
  }

  .tool-btn {
    width: 40px;
    height: 40px;
  }
}

/* タッチデバイス用の追加スタイル */
@media (hover: none) and (pointer: coarse) {
  /* タップ時のハイライト無効化 */
  * {
    -webkit-tap-highlight-color: transparent;
  }

  /* ホバー効果を無効化 */
  .btn:hover,
  .btn-icon:hover,
  .tool-btn:hover,
  .filter-btn:hover,
  .layer-item:hover,
  .save-menu-item:hover {
    transform: none;
    box-shadow: none;
  }

  /* アクティブ状態のフィードバック */
  .btn:active,
  .btn-icon:active,
  .tool-btn:active {
    transform: scale(0.95);
    opacity: 0.8;
  }

  /* リサイズハンドルを大きく */
  #myCanvas {
    touch-action: none;
  }
}

/* PWA風のスプラッシュ対応 */
@media (display-mode: standalone) {
  .app-container {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
}
/* ==================================
   フッター
   ================================== */

.app-footer {
  position: fixed;
  bottom: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(15, 15, 26, 0.9);
  backdrop-filter: blur(8px);
  border-top-left-radius: 8px;
  font-size: 12px;
  z-index: 50;
}

.app-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.app-footer a:hover {
  color: var(--accent-primary);
}

.footer-separator {
  color: var(--bg-tertiary);
}

.footer-copyright {
  color: var(--text-secondary);
}

/* スマホでフッターを調整 */
@media (max-width: 768px) {
  .app-footer {
    left: 0;
    right: 0;
    border-radius: 0;
    justify-content: center;
    padding: 6px 12px;
    font-size: 11px;
  }
}
