/* Google Fonts の読み込み */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&family=Outfit:wght@400;600;800&display=swap');

:root {
  --bg-color: #121212;
  --wood-color: #2b1704;
  --wood-dark: #1f0f02;
  --metal-color: #cfd8dc;
  --metal-dark: #78909c;
  
  /* チョークの色 */
  --color-white: #f8f9fa;
  --color-yellow: #ffd43b;
  --color-pink: #ff8787;
  --color-green: #69db7c;
  
  /* チョークのグロー効果 */
  --glow-white: rgba(248, 249, 250, 0.4);
  --glow-yellow: rgba(255, 212, 59, 0.4);
  --glow-pink: rgba(255, 135, 135, 0.4);
  --glow-green: rgba(105, 219, 124, 0.4);
}

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

body {
  background-color: var(--bg-color);
  background-image: radial-gradient(circle at center, #1e1e1e 0%, #121212 100%);
  font-family: 'Noto Sans JP', 'Outfit', sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: #fff;
}

/* タイトル・ヘッダー */
header {
  position: absolute;
  top: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 10;
}

header h1 {
  font-family: 'Outfit', sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 4px;
  background: linear-gradient(135deg, #cfd8dc, #eceff1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

header p {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.4);
  letter-spacing: 1px;
}

/* 黒板全体のフレーム */
#chalkboard-frame {
  display: flex;
  flex-direction: column;
  background: var(--wood-color);
  background-image: linear-gradient(135deg, var(--wood-color) 0%, var(--wood-dark) 100%);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 
    0 20px 50px rgba(0, 0, 0, 0.7),
    0 5px 15px rgba(0, 0, 0, 0.4),
    inset 0 0 15px rgba(0, 0, 0, 0.9);
  border: 4px solid #3e2723;
  width: auto;
  max-width: 95vw;
  transition: all 0.3s ease;
}

/* 黒板面 (16:9) */
#chalkboard-surface {
  position: relative;
  aspect-ratio: 16 / 9;
  background-color: #1a3c2f;
  background-image: radial-gradient(circle at center, #234f3e 0%, #132e23 100%);
  border: 4px solid var(--metal-color);
  border-bottom: 4px solid var(--metal-dark);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 
    inset 0 4px 20px rgba(0, 0, 0, 0.8),
    inset 0 0 80px rgba(0, 0, 0, 0.4);
  cursor: none; /* カスタムカーソルを使用するため非表示 */
}

/* 黒板の微細な質感（ノイズ） */
#chalkboard-surface::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  opacity: 0.055;
  pointer-events: none;
  z-index: 1;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* 描画キャンバス */
#paint-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  display: block;
}

/* 補助線（グリッド）オーバーレイ */
#grid-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
  opacity: 0;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  background-image: 
    linear-gradient(to right, rgba(255, 255, 255, 0.09) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 255, 255, 0.09) 1px, transparent 1px);
  background-size: calc(100% / 32) calc(100% / 18); /* 32x18 グリッド（16:9で正方形） */
}

#grid-overlay.active {
  opacity: 1;
}

/* チョーク受けトレイ（下部メニュー） */
#chalk-tray {
  margin-top: 16px;
  height: 64px;
  background: linear-gradient(to bottom, var(--metal-color) 0%, #b0bec5 20%, var(--metal-dark) 80%, #546e7a 100%);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  box-shadow: 
    inset 0 3px 5px rgba(255,255,255,0.6),
    inset 0 -3px 5px rgba(0,0,0,0.4),
    0 6px 12px rgba(0, 0, 0, 0.3);
  position: relative;
  z-index: 5;
}

/* セクション分割 */
.tray-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.tray-divider {
  width: 2px;
  height: 32px;
  background: rgba(0, 0, 0, 0.15);
  border-right: 1px solid rgba(255, 255, 255, 0.25);
  margin: 0 4px;
}

/* チョークセレクター */
.chalk-selector {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  height: 48px;
  padding-bottom: 2px;
}

/* チョークのスタイル */
.chalk-stick {
  width: 55px;
  height: 15px;
  border: none;
  cursor: pointer;
  position: relative;
  border-radius: 3px;
  outline: none;
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.25s ease;
  transform-origin: bottom center;
  
  /* チョークの基本構造: 紙スリーブ(左) + チョーク芯(右) */
  background: 
    linear-gradient(to bottom, rgba(255,255,255,0.45) 0%, rgba(0,0,0,0.15) 100%), 
    linear-gradient(to right, #cfd8dc 55%, var(--chalk-color) 55%);
  box-shadow: 
    0 3px 5px rgba(0, 0, 0, 0.3),
    inset -1px 0 2px rgba(0,0,0,0.2);
}

.chalk-stick::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0; left: 55%;
  border-radius: 0 3px 3px 0;
  box-shadow: inset 1px 0 3px rgba(255, 255, 255, 0.4);
}

/* 各色定義 */
.chalk-stick[data-color="white"] { --chalk-color: var(--color-white); --glow-color: var(--glow-white); }
.chalk-stick[data-color="yellow"] { --chalk-color: var(--color-yellow); --glow-color: var(--glow-yellow); }
.chalk-stick[data-color="pink"] { --chalk-color: var(--color-pink); --glow-color: var(--glow-pink); }
.chalk-stick[data-color="green"] { --chalk-color: var(--color-green); --glow-color: var(--glow-green); }

/* チョーク選択状態（トレイから少し浮き出る） */
.chalk-stick.active {
  transform: translateY(-16px) rotate(-4deg);
  box-shadow: 
    0 16px 20px rgba(0, 0, 0, 0.35),
    0 0 12px var(--glow-color);
}

.chalk-stick:hover:not(.active) {
  transform: translateY(-6px) rotate(-1deg);
}

/* 黒板消し */
.eraser-tool {
  width: 72px;
  height: 28px;
  border: none;
  cursor: pointer;
  outline: none;
  border-radius: 4px;
  transition: transform 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.25s ease;
  transform-origin: bottom center;
  
  /* 黒板消しのリアルなレイヤー表現: 木の板(上) + 赤スポンジ(中) + コールテン生地(下) */
  background: linear-gradient(to bottom, 
    #8d6e63 0%, #795548 40%, 
    #ff5722 40%, #ff5722 52%, 
    #37474f 52%, #263238 100%
  );
  box-shadow: 
    0 3px 5px rgba(0, 0, 0, 0.3),
    inset 0 1px 1px rgba(255,255,255,0.2);
  position: relative;
}

/* 木目上のロゴ風刻印 */
.eraser-tool::before {
  content: "KOKUBAN";
  position: absolute;
  top: 1px;
  left: 0;
  width: 100%;
  text-align: center;
  font-family: 'Outfit', sans-serif;
  font-size: 5px;
  font-weight: 800;
  color: rgba(0, 0, 0, 0.45);
  letter-spacing: 0.5px;
  pointer-events: none;
}

.eraser-tool.active {
  transform: translateY(-16px) rotate(3deg);
  box-shadow: 0 16px 20px rgba(0, 0, 0, 0.35);
}

.eraser-tool:hover:not(.active) {
  transform: translateY(-6px) rotate(1deg);
}

/* 一般のトレイ用ボタン (方眼、全消去、Undo/Redoなど) */
.tray-btn {
  background: #37474f;
  background: linear-gradient(to bottom, #455a64 0%, #37474f 100%);
  border: 1px solid rgba(0, 0, 0, 0.3);
  border-bottom: 2px solid rgba(0, 0, 0, 0.5);
  color: #eceff1;
  border-radius: 6px;
  height: 38px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 
    0 2px 4px rgba(0,0,0,0.15),
    inset 0 1px 0 rgba(255,255,255,0.1);
}

.tray-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.tray-btn:hover {
  background: linear-gradient(to bottom, #546e7a 0%, #455a64 100%);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 
    0 4px 8px rgba(0,0,0,0.25),
    inset 0 1px 0 rgba(255,255,255,0.15);
}

.tray-btn:active {
  background: linear-gradient(to bottom, #263238 0%, #37474f 100%);
  transform: translateY(1px);
  box-shadow: 
    0 1px 2px rgba(0,0,0,0.1),
    inset 0 1px 3px rgba(0,0,0,0.3);
  border-bottom-width: 1px;
}

/* トグルボタンのアクティブ状態 */
.tray-btn.active {
  background: #00796b;
  background: linear-gradient(to bottom, #00897b 0%, #00695c 100%);
  color: #e0f2f1;
  border-color: #004d40;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

/* 太さセレクター */
.size-selector {
  display: flex;
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 6px;
  padding: 2px;
}

.size-btn {
  background: transparent;
  border: none;
  color: #78909c;
  font-size: 0.75rem;
  font-weight: bold;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.size-btn:hover {
  color: #37474f;
  background: rgba(255, 255, 255, 0.2);
}

.size-btn.active {
  background: #eceff1;
  color: #263238;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ページ操作 */
.page-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.12);
  padding: 3px 10px;
  border-radius: 20px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.page-btn {
  background: transparent;
  border: none;
  color: #37474f;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  transition: all 0.15s ease;
}

.page-btn svg {
  width: 22px;
  height: 22px;
}

.page-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.35);
  color: #000;
  transform: scale(1.15);
}

.page-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.page-btn:disabled {
  color: #b0bec5;
  cursor: not-allowed;
  opacity: 0.4;
}

.page-indicator {
  font-family: 'Outfit', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  color: #37474f;
  min-width: 45px;
  text-align: center;
}

/* カスタムカーソル */
#custom-cursor {
  position: fixed;
  top: 0;
  left: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  z-index: 9999;
  display: none;
  box-shadow: 0 0 2px rgba(0,0,0,0.5);
  transition: width 0.1s ease, height 0.1s ease;
}

/* ペンカーソル */
#custom-cursor.pencil {
  border: 1px solid rgba(255, 255, 255, 0.8);
  background-color: var(--cursor-color);
  box-shadow: 0 0 6px var(--cursor-glow);
}

/* 消しゴムカーソル */
#custom-cursor.eraser {
  border: 1.5px dashed rgba(255, 255, 255, 0.85);
  background-color: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 8px rgba(0,0,0,0.3);
}

/* ツールチップ効果 */
[title] {
  position: relative;
}

/* デプロイ状態を示す小さなインジケーター（省略可、UIの完成度アップ用） */
.deploy-status {
  position: absolute;
  bottom: 12px;
  right: 20px;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.status-dot {
  width: 6px;
  height: 6px;
  background-color: #69db7c;
  border-radius: 50%;
  box-shadow: 0 0 4px #69db7c;
}
