/* --- 全体的なデザインと配色の定義 --- */
@layer base {
  :root {
    --background-color: 249 250 251; /* gray-50 */
    --card-background: 255 255 255; /* white */
    --text-color: 17 24 39; /* gray-900 */
    --text-muted-color: 107 114 128; /* gray-500 */
    --border-color: 229 231 235; /* gray-200 */
    --primary-color: 17 24 39; /* gray-900 */
    --primary-hover-color: 55 65 81; /* gray-700 */
    --secondary-color: 243 244 246; /* gray-100 */
    --secondary-hover-color: 229 231 235; /* gray-200 */
    --focus-ring-color: 99 102 241; /* indigo-500 */
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --background-color: 17 24 39; /* gray-900 */
      --card-background: 31 41 55; /* gray-800 */
      --text-color: 243 244 246; /* gray-100 */
      --text-muted-color: 156 163 175; /* gray-400 */
      --border-color: 55 65 81; /* gray-700 */
      --primary-color: 243 244 246; /* gray-100 */
      --primary-hover-color: 209 213 219; /* gray-300 */
      --secondary-color: 55 65 81; /* gray-700 */
      --secondary-hover-color: 75 85 99; /* gray-600 */
      --focus-ring-color: 129 140 248; /* indigo-400 */
    }
  }
}
body {
  font-family: Inter, ui-sans-serif, system-ui, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  background-color: rgb(var(--background-color));
  color: rgb(var(--text-color));
  line-height: 1.5;
}
.tool-card {
  background-color: rgb(var(--card-background));
  border: 1px solid rgb(var(--border-color));
  padding: 2rem;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,.05), 0 2px 4px -2px rgba(0,0,0,.05);
  border-radius: 1.5rem;
}
.drop-area { position: relative; padding: 2rem; border: 2px dashed rgb(var(--border-color)); border-radius: 1rem; text-align:center; cursor:pointer; transition: .2s; }
.drop-area.dragover { border-color: rgb(var(--focus-ring-color)); }

/* Buttons */
.btn { display:inline-flex; align-items:center; justify-content:center; gap:.5rem; font-weight:600; padding:.75rem 1.25rem; border-radius:.75rem; transition:.2s; }
.btn-primary { background: rgb(var(--primary-color)); color: rgb(var(--background-color)); }
.btn-primary[disabled] { opacity:.6; cursor:not-allowed; }
.btn-secondary { background: rgb(var(--card-background)); color: rgb(var(--text-color)); border:1px solid rgb(var(--border-color)); }
.btn-tool { position: relative; width:44px; height:44px; display:inline-flex; align-items:center; justify-content:center; border-radius:.75rem; border:2px solid transparent; background: rgb(var(--secondary-color)); }
.btn-tool.active { border-color: rgb(var(--focus-ring-color)); }
.btn-color { width:28px; height:28px; border-radius:9999px; border:2px solid transparent; }
.btn-color.active { border-color: rgb(var(--focus-ring-color)); }

/* Tooltip */
.btn-tool[data-tooltip]::after { content: attr(data-tooltip); position: absolute; bottom: 115%; left: 50%; transform: translateX(-50%); background-color: rgb(var(--primary-color)); color: rgb(var(--background-color)); padding: 4px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; opacity: 0; visibility: hidden; transition: opacity 0.2s, visibility 0.2s; pointer-events: none; z-index: 10; }
.btn-tool[data-tooltip]:hover::after { opacity: 1; visibility: visible; }

/* Canvas & Tool Panel Layout */
#canvas-container { position:relative; width:100%; border:1px solid rgb(var(--border-color)); border-radius:.75rem; overflow:hidden; }
#drawing-canvas { display: block; max-width: 100%; }
#tool-panel { width:320px; flex-shrink:0; border-left:1px solid rgb(var(--border-color)); padding-left:1.5rem; }

/* Message Box */
.message-box { position:fixed; bottom:20px; left:50%; transform:translateX(-50%); background:rgba(17,24,39,.9); color:#fff; padding:.8rem 1.2rem; border-radius:9999px; z-index:50; }

/* Navigation */
.main-nav { border-bottom:1px solid rgb(var(--border-color)); }
.nav-link { padding: .75rem 1rem; font-size: 0.875rem; color: rgb(var(--text-muted-color)); text-decoration: none; transition: .2s; border-bottom: 2px solid transparent; white-space: nowrap; }
.nav-link:hover { color: rgb(var(--text-color)); }
.nav-link.active { font-weight: 600; color: rgb(var(--text-color)); border-bottom-color: rgb(var(--primary-color)); }

/* Forms: 修正箇所 */
input[type="text"],
input[type="number"],
textarea,
select {
    width: 100%;
    background-color: rgb(var(--background-color));
    border: 1px solid rgb(var(--border-color));
    border-radius: 0.75rem;
    padding: 0.75rem;
    font-size: 1rem;
    transition: all 0.2s ease-in-out;
    color: rgb(var(--text-color)); /* 入力文字の色を定義 */
}
input[type="text"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: rgb(var(--focus-ring-color));
    box-shadow: 0 0 0 3px rgba(var(--focus-ring-color), 0.3);
}
input::placeholder,
textarea::placeholder {
  color: rgb(var(--text-muted-color));
  opacity: 1; /* ブラウザによる過度な透過を防ぐ */
}

/* --- アクセシビリティ向上のためのフォーカススタイルを追加 --- */
.btn:focus-visible, .nav-link:focus-visible, input[type="radio"]:focus-visible, button:focus-visible {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(var(--focus-ring-color), 0.5);
}


/* Image Comparison Tool Specific */
.file-upload-container { position: relative; }
.file-upload-input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
#comparison-container { position: relative; width: 100%; min-height: 500px; overflow: hidden; border-radius: 1rem; background-color: rgb(var(--secondary-color)); cursor: grab; user-select: none; }
#comparison-container:active { cursor: grabbing; }
.comparison-image, #difference-canvas { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); max-width: 100%; max-height: 100%; object-fit: contain; }

/* PDF & Image Converter Tool Specific */
.grid-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 1rem; max-height: 400px; overflow-y: auto; padding: 0.5rem; border: 1px dashed rgb(var(--border-color)); border-radius: 1rem; }
.grid-item { position: relative; border: 1px solid rgb(var(--border-color)); border-radius: 0.75rem; overflow: hidden; background-color: rgb(var(--secondary-color)); }
.grid-item img { width: 100%; height: 100px; object-fit: cover; pointer-events: none; }
.grid-item .overlay { position: absolute; bottom: 0; left: 0; right: 0; padding: 0.5rem; background-color: rgba(0, 0, 0, 0.5); color: white; font-size: 0.75rem; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-item .delete-btn { position: absolute; top: 0.5rem; right: 0.5rem; background-color: rgba(255, 0, 0, 0.7); color: white; border: none; border-radius: 50%; width: 24px; height: 24px; display: flex; justify-content: center; align-items: center; cursor: pointer; opacity: 0; transition: opacity 0.2s; }
.grid-item:hover .delete-btn { opacity: 1; }
.grid-item.dragging { opacity: 0.5; }

/* Result Area for Ratio Calculator */
.result-area { margin-top: 1.5rem; padding: 1.5rem; border-radius: 1rem; background-color: rgb(var(--secondary-color)); }
.result-area .result-label { font-size: 0.875rem; font-weight: 600; color: rgb(var(--text-muted-color)); }
.result-area .result-value { font-size: 2.25rem; font-weight: 800; color: rgb(var(--text-color)); margin-top: 0.5rem; }

