/* ============================
   模写スタジオ - CSS Design System
   ============================ */

/* --- CSS変数 / デザイントークン --- */
:root {
  /* カラーパレット */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-tertiary: #1a1a2e;
  --bg-card: rgba(26, 26, 46, 0.7);
  --bg-card-hover: rgba(36, 36, 66, 0.8);
  --bg-glass: rgba(20, 20, 35, 0.85);
  --bg-glass-light: rgba(255, 255, 255, 0.03);

  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #5a5a78;

  --accent-purple: #8B5CF6;
  --accent-cyan: #06B6D4;
  --accent-green: #10B981;
  --accent-orange: #F59E0B;
  --accent-red: #EF4444;

  --gradient-main: linear-gradient(135deg, #8B5CF6, #06B6D4);
  --gradient-warm: linear-gradient(135deg, #F59E0B, #EF4444);
  --gradient-cool: linear-gradient(135deg, #06B6D4, #10B981);

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-active: rgba(139, 92, 246, 0.4);

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.15);

  /* タイポグラフィ */
  --font-primary: 'Noto Sans JP', 'Inter', sans-serif;
  --font-mono: 'SF Mono', 'Consolas', monospace;

  /* スペーシング */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* トランジション */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- リセット / ベース --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  position: relative;
}

/* アプリ全体のレイアウト */
.app-layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
}

.main-content-area {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 3px;
}

/* ユーティリティ */
.hidden {
  display: none !important;
}

/* ============================
   ドロップメッセージ
   ============================ */
.drop-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  padding: 40px;
  background: transparent;
  text-align: center;
  border: 4px dashed rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-xl);
  transition: all var(--transition-normal);
  cursor: pointer;
  z-index: 5;
}

.drop-message.drag-over {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.05);
  transform: scale(0.98);
}

.drop-icon {
  color: var(--text-muted);
  transition: color var(--transition-normal), transform var(--transition-normal);
}

.drop-message:hover .drop-icon {
  color: var(--accent-purple);
  transform: translateY(-8px);
}

/* ============================
   ビューア画面
   ============================ */
.viewer-screen {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

/* ツールバー */
.toolbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  height: 52px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 100;
  transition: opacity var(--transition-normal);
}

.toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: start;
  overflow: hidden;
  padding-right: 12px;
}

.toolbar-center {
  display: flex;
  align-items: center;
  justify-self: center;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-self: end;
}

.toolbar-title {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ボタン共通 */
.toolbar-btn,
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.toolbar-btn:hover,
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
}

.toolbar-btn.active,
.icon-btn.active {
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.1);
}

/* スリープ防止トグル */
.wake-lock-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-normal);
  user-select: none;
}

.wake-lock-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.wake-lock-toggle.active {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
}

.wake-lock-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all var(--transition-normal);
}

.wake-lock-toggle.active .wake-lock-indicator {
  background: var(--accent-green);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  animation: indicatorPulse 2s ease-in-out infinite;
}

@keyframes indicatorPulse {
  0%, 100% { box-shadow: 0 0 8px rgba(16, 185, 129, 0.6); }
  50% { box-shadow: 0 0 14px rgba(16, 185, 129, 0.9); }
}

.wake-lock-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.wake-lock-toggle.active .wake-lock-label {
  color: var(--accent-green);
}

/* ビューアボディ */
.viewer-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* サムネイルサイドバー */
.thumbnail-sidebar {
  width: 140px;
  background: rgba(20, 20, 35, 0.4);
  border-left: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition-normal);
  z-index: 50;
}

.thumbnail-sidebar.hidden {
  display: none !important;
}

.thumbnail-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.thumbnail-item {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--bg-card);
  transition: all var(--transition-fast);
  position: relative;
}

.thumbnail-item:hover {
  transform: translateY(-2px);
  border-color: rgba(6, 182, 212, 0.5);
}

.thumbnail-item.active {
  border-color: var(--accent-purple);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.4);
}

.thumbnail-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

/* サムネイル追加ボタン */
.thumbnail-add-btn {
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px dashed rgba(139, 92, 246, 0.4);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  color: var(--text-muted);
  gap: 4px;
}

.thumbnail-add-btn svg {
  width: 24px;
  height: 24px;
  transition: color var(--transition-fast);
}

.thumbnail-add-btn span {
  font-size: 0.75rem;
  font-weight: 500;
  transition: color var(--transition-fast);
}

.thumbnail-add-btn:hover {
  background: rgba(139, 92, 246, 0.05);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
}

.thumbnail-add-btn.active {
  background: rgba(139, 92, 246, 0.1);
  border-color: var(--accent-purple);
  color: var(--text-primary);
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.3);
}

/* サムネイル削除ボタン */
.thumbnail-del-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  font-size: 14px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast), background var(--transition-fast);
  z-index: 10;
}

.thumbnail-item:hover .thumbnail-del-btn {
  opacity: 1;
}

.thumbnail-del-btn:hover {
  background: var(--accent-red);
}

/* キャンバスエリア */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  background:
    radial-gradient(circle at center, rgba(139, 92, 246, 0.02) 0%, transparent 70%);
  cursor: grab;
}

.canvas-area:active {
  cursor: grabbing;
}

.image-container {
  position: relative;
  transition: transform var(--transition-fast);
  transform-origin: center center;
}

.image-container img {
  display: block;
  max-width: none;
  user-select: none;
  -webkit-user-drag: none;
  transition: filter var(--transition-normal);
}

/* グリッドオーバーレイ */
.grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

.grid-line-h,
.grid-line-v {
  position: absolute;
  background: rgba(139, 92, 246, 0.4);
}

.grid-line-h {
  left: 0;
  width: 100%;
  height: 1px;
}

.grid-line-v {
  top: 0;
  height: 100%;
  width: 1px;
}

/* コントロールパネル */
.control-panel {
  padding: 10px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 100;
  transition: opacity var(--transition-normal);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 16px;
  overflow: visible;
  flex-wrap: wrap;
  padding-bottom: 2px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.control-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.control-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.control-divider {
  width: 1px;
  height: 28px;
  background: var(--border-subtle);
  flex-shrink: 0;
}

/* コントロールボタン */
.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-active);
  color: var(--text-primary);
}

.ctrl-btn.active {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent-purple);
  color: var(--accent-purple);
}

.ctrl-value {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  min-width: 48px;
  text-align: center;
}

/* セレクト */
.ctrl-select {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: var(--font-primary);
  cursor: pointer;
  outline: none;
  transition: all var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
  padding-right: 24px;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239898b0' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}

.ctrl-select:hover {
  border-color: var(--border-active);
}

.ctrl-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* スライダー */
.ctrl-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.ctrl-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-purple);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 6px rgba(139, 92, 246, 0.4);
  transition: box-shadow var(--transition-fast);
}

.ctrl-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 12px rgba(139, 92, 246, 0.7);
}

.ctrl-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-purple);
  cursor: pointer;
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 6px rgba(139, 92, 246, 0.4);
}

/* リセットボタン */
.reset-btn {
  font-size: 0.75rem !important;
  padding: 0 12px !important;
  color: var(--accent-orange) !important;
  border-color: rgba(245, 158, 11, 0.2) !important;
}

.reset-btn:hover {
  background: rgba(245, 158, 11, 0.1) !important;
  border-color: var(--accent-orange) !important;
}

/* タイマー表示 */
.timer-display {
  font-size: 0.9rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent-cyan);
  min-width: 50px;
  text-align: center;
  padding: 4px 8px;
  background: rgba(6, 182, 212, 0.08);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(6, 182, 212, 0.2);
}

.timer-display.warning {
  color: var(--accent-orange);
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.2);
  animation: timerBlink 1s ease-in-out infinite;
}

.timer-display.danger {
  color: var(--accent-red);
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.2);
  animation: timerBlink 0.5s ease-in-out infinite;
}

@keyframes timerBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* トースト通知 */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 24px;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 24px;
  font-size: 0.85rem;
  color: var(--text-primary);
  z-index: 1000;
  opacity: 0;
  transition: opacity var(--transition-normal), transform var(--transition-normal);
  pointer-events: none;
  box-shadow: var(--shadow-md);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================
   サムネイルトグル・フルスクリーン制御
   ============================ */
.toggle-thumbnails-btn {
  position: absolute;
  top: 50%;
  left: -24px;
  width: 24px;
  height: 48px;
  transform: translateY(-50%);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  border-right: none;
  border-radius: 8px 0 0 8px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  transition: all var(--transition-fast);
}

.toggle-thumbnails-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
}

.thumbnail-sidebar {
  position: relative;
  transition: transform var(--transition-normal), margin-left var(--transition-normal);
}

.thumbnail-sidebar.collapsed {
  transform: translateX(100%);
  margin-left: -140px; /* offset the width to avoid layout shifting if hidden */
}

.thumbnail-sidebar.collapsed .toggle-thumbnails-btn svg {
  transform: scaleX(-1);
}

/* フルスクリーン時のUI制御 */
body.is-fullscreen .toolbar {
  position: absolute;
  left: 0;
  right: 0;
  transition: transform var(--transition-normal), opacity var(--transition-normal);
  z-index: 100;
}

body.is-fullscreen .toolbar {
  top: 0;
  transform: translateY(-100%);
  opacity: 0;
}

body.is-fullscreen.show-ui .toolbar {
  transform: translateY(0);
  opacity: 1;
}

/* タイマーポップアップ */
.timer-popup-container {
  display: flex;
  align-items: center;
}

.timer-popup {
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  background: var(--bg-card-hover);
  color: var(--accent-cyan);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid var(--accent-cyan);
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast), transform var(--transition-fast);
  z-index: 200;
}

.timer-popup-container:hover .timer-popup {
  opacity: 1;
  transform: translateX(-50%) translateY(12px);
}

/* 下部パネル用のポップアップ（上に向かって表示） */
.timer-popup.bottom-popup {
  top: auto;
  bottom: 100%;
  transform: translateX(-50%) translateY(-8px);
}
.timer-popup-container:hover .timer-popup.bottom-popup {
  opacity: 1;
  transform: translateX(-50%) translateY(-12px);
  z-index: 9999;
}

/* グリッド中央線強調 */
.grid-line-center {
  position: absolute;
  background: var(--accent-cyan);
  z-index: 11;
  box-shadow: 0 0 6px rgba(6, 182, 212, 0.8);
}
.grid-line-center.h {
  top: 50%;
  left: 0;
  width: 100%;
  height: 2px;
  transform: translateY(-50%);
}
.grid-line-center.v {
  top: 0;
  left: 50%;
  width: 2px;
  height: 100%;
  transform: translateX(-50%);
}

/* ============================
   レスポンシブ調整
   ============================ */
@media (max-width: 768px) {
  .landing-content {
    padding: 24px;
    gap: 28px;
  }

  .logo-title {
    font-size: 2rem;
  }

  .upload-zone {
    padding: 32px 20px;
  }

  .features-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }

  .feature-card {
    padding: 12px 8px;
  }

  .controls-row {
    gap: 10px;
  }

  .control-label {
    display: none;
  }
}

/* フルスクリーン時にUI を隠すモード */
.viewer-screen.ui-hidden .toolbar,
.viewer-screen.ui-hidden .control-panel {
  opacity: 0;
  pointer-events: none;
}

.viewer-screen.ui-hidden .canvas-area {
  cursor: none;
}
