/* CSS変数 - ライトモード（デフォルト） */
:root {
  /* 背景色 */
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f8f9fa;
  
  /* テキスト色 */
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #888888;
  
  /* ボーダー色 */
  --border-primary: #dee2e6;
  --border-secondary: #e9ecef;
  --border-focus: #0077cc;
  
  /* ボタン色 */
  --btn-primary-bg: #0077cc;
  --btn-primary-text: #ffffff;
  --btn-primary-hover: #005fa3;
  --btn-secondary-bg: #6c757d;
  --btn-secondary-text: #ffffff;
  
  /* セル色 */
  --cell-bg: #ffffff;
  --cell-border: #ccc;
  --cell-hole: #ffeb3b;
  --cell-faded: #f8f9fa;
  --cell-rotated: #e3f2fd;
  
  /* 通知色 */
  --notification-error-bg: #fee;
  --notification-error-text: #c53030;
  --notification-error-border: #feb2b2;
  --notification-warning-bg: #fffbeb;
  --notification-warning-text: #d69e2e;
  --notification-warning-border: #fbd38d;
  --notification-success-bg: #f0fff4;
  --notification-success-text: #38a169;
  --notification-success-border: #9ae6b4;
  --notification-info-bg: #ebf8ff;
  --notification-info-text: #3182ce;
  --notification-info-border: #90cdf4;
  
  /* 進捗バー色 */
  --progress-bg: #e9ecef;
  --progress-fill-encryption: linear-gradient(90deg, #007bff, #17a2b8);
  --progress-fill-decryption: linear-gradient(90deg, #fd7e14, #ffc107);
  
  /* フィードバック色 */
  --feedback-bg: rgba(0, 0, 0, 0.8);
  --feedback-text: white;
}

/* ダークモード */
.dark-mode {
  /* 背景色 */
  --bg-primary: #1a1a1a;
  --bg-secondary: #2d2d2d;
  --bg-tertiary: #404040;
  
  /* テキスト色 */
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-muted: #888888;
  
  /* ボーダー色 */
  --border-primary: #555555;
  --border-secondary: #444444;
  --border-focus: #66b3ff;
  
  /* ボタン色 */
  --btn-primary-bg: #0099ff;
  --btn-primary-text: #ffffff;
  --btn-primary-hover: #007acc;
  --btn-secondary-bg: #555555;
  --btn-secondary-text: #e0e0e0;
  
  /* セル色 */
  --cell-bg: #3d3d3d;
  --cell-border: #666666;
  --cell-hole: #ffeb3b;
  --cell-faded: #2a2a2a;
  --cell-rotated: #1e3a5f;
  
  /* 通知色 */
  --notification-error-bg: #3d1a1a;
  --notification-error-text: #ff6b6b;
  --notification-error-border: #8b2635;
  --notification-warning-bg: #3d3520;
  --notification-warning-text: #ffa502;
  --notification-warning-border: #b8860b;
  --notification-success-bg: #1a3d2e;
  --notification-success-text: #51cf66;
  --notification-success-border: #2d8659;
  --notification-info-bg: #1a2a3d;
  --notification-info-text: #74c0fc;
  --notification-info-border: #1c7ed6;
  
  /* 進捗バー色 */
  --progress-bg: #444444;
  --progress-fill-encryption: linear-gradient(90deg, #339af0, #22b8cf);
  --progress-fill-decryption: linear-gradient(90deg, #ff8c42, #ffd43b);
  
  /* フィードバック色 */
  --feedback-bg: rgba(255, 255, 255, 0.9);
  --feedback-text: #333333;
}

/* ベース設定 */
body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  max-width: 900px;
  margin: 0 auto;
  padding: 2em;
  transition: background-color 0.3s ease, color 0.3s ease;
}

h1 {
  font-size: 2rem;
  margin-bottom: 0.5em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  color: var(--text-primary);
}

h2 {
  font-size: 1.3rem;
  margin-top: 0.5em;
  margin-bottom: 1em;
  color: var(--text-primary);
}

/* タブUI */
.tabs {
  display: flex;
  gap: 0.5em;
  margin-bottom: 1em;
}

.tab-button {
  padding: 0.6em 1.2em;
  border: none;
  background-color: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  font-weight: bold;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.tab-button.active {
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.tab-content {
  display: none;
  background: var(--bg-secondary);
  padding: 1.5em;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
  transition: background-color 0.3s ease;
}

.tab-content.active {
  display: block;
}

/* 入力欄・出力欄 */
textarea {
  width: 100%;
  padding: 0.8em;
  font-size: 1em;
  border: 1px solid #ccc;
  border-radius: 6px;
  resize: vertical;
  box-sizing: border-box;
  margin-top: 0.5em;
}

input[type="text"] {
  padding: 0.5em;
  font-size: 1em;
  border: 1px solid #ccc;
  border-radius: 6px;
  width: 100%;
  box-sizing: border-box;
}

/* ボタン共通 */
button {
  padding: 0.6em 1.2em;
  margin: 0.5em 0.5em 0.5em 0;
  font-size: 1em;
  background-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

button:hover {
  background-color: var(--btn-primary-hover);
}

button:disabled {
  background-color: var(--btn-secondary-bg);
  color: var(--text-secondary);
  cursor: not-allowed;
  opacity: 0.6;
}

button:disabled:hover {
  background-color: var(--btn-secondary-bg);
}

/* グリルマトリクス */
#baseMatrix, #grillePreview {
  display: grid;
  grid-template-columns: repeat(3, 50px);
  gap: 6px;
  margin-top: 1em;
}

#grillePreview {
  grid-template-columns: repeat(6, 40px);
  margin-top: 1.5em;
}

.cell {
  width: 50px;
  height: 50px;
  line-height: 50px;
  background-color: var(--cell-bg);
  border: 2px solid var(--cell-border);
  color: var(--text-primary);
  text-align: center;
  font-weight: bold;
  font-size: 1.1em;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.cell-hole {
  background-color: var(--cell-hole);
  border-color: var(--border-focus);
}

.cell-faded {
  background-color: var(--cell-faded);
  color: var(--text-muted);
  opacity: 0.4;
}

.cell-rotated {
  background-color: var(--cell-rotated);
}

/* 通知や補助ラベル */
#errorMessage,
#warningMessage,
#limitNote {
  margin-top: 0.4em;
  font-size: 0.9em;
  white-space: pre-wrap;
}

#errorMessage {
  color: #e53935;
}

#warningMessage {
  color: #fb8c00;
}

#limitNote {
  color: #666;
}

#rotationLabel,
#decryptionRotationLabel,
#stepInfo {
  font-weight: bold;
  color: #444;
  margin-left: 1em;
}

/* フッター */
.footer {
  text-align: center;
  margin-top: 3em;
  font-size: 0.95em;
  color: #888;
}

a {
  color: #0077cc;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* トースト通知（暗号文コピー） */
.toast {
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  margin-left: 10px;
  background-color: #323232;
  color: #fff;
  padding: 0.6em 1em;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  font-size: 0.9em;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateY(-50%) translateX(5px);
  pointer-events: auto;
}

.rotate-animation {
  animation: rotateBoard 0.4s linear;
  transform-origin: center center;
}
@keyframes rotateBoard {
  from { transform: rotate(0deg); }
  to { transform: rotate(90deg); }
}

.highlight-once {
  animation: flashCell 0.4s ease-in-out;
}
@keyframes flashCell {
  0% { background-color: #ffeb3b; }
  100% { background-color: inherit; }
}

#encryptionGrid,
#decryptionGrid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  transform-origin: center center;
}

/* 通知システム */
.notification {
  padding: 0.8em 1.2em;
  margin: 0.5em 0;
  border-radius: 6px;
  font-size: 0.9em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  animation: slideIn 0.3s ease-out;
}

.notification-error {
  background-color: var(--notification-error-bg);
  color: var(--notification-error-text);
  border: 1px solid var(--notification-error-border);
}

.notification-warning {
  background-color: var(--notification-warning-bg);
  color: var(--notification-warning-text);
  border: 1px solid var(--notification-warning-border);
}

.notification-success {
  background-color: var(--notification-success-bg);
  color: var(--notification-success-text);
  border: 1px solid var(--notification-success-border);
}

.notification-info {
  background-color: var(--notification-info-bg);
  color: var(--notification-info-text);
  border: 1px solid var(--notification-info-border);
}

.notification::before {
  content: "ℹ️";
  font-size: 1.2em;
}

.notification-error::before { content: "❌"; }
.notification-warning::before { content: "⚠️"; }
.notification-success::before { content: "✅"; }

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.notification-container {
  margin: 0.5em 0;
}

/* 詳細進捗表示 */
.progress-container {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-secondary);
  border-radius: 8px;
  padding: 1em;
  margin: 1em 0;
  font-size: 0.9em;
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.8em;
  font-weight: 500;
}

.progress-info span {
  color: var(--text-secondary);
}

.progress-bar {
  background: var(--progress-bg);
  border-radius: 10px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 0.6em;
  transition: background-color 0.3s ease;
}

.progress-fill {
  background: var(--progress-fill-encryption);
  height: 100%;
  border-radius: 10px;
  transition: width 0.4s ease;
  width: 0%;
}

.next-info {
  color: var(--text-muted);
  font-size: 0.85em;
  font-style: italic;
}

/* 暗号化と復号で色を少し変える */
#encryptionProgress .progress-fill {
  background: var(--progress-fill-encryption);
}

#decryptionProgress .progress-fill {
  background: var(--progress-fill-decryption);
}

/* キーボードショートカットフィードバック */
@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translateY(-10px);
  }
  20%, 80% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-5px);
  }
}

.shortcut-feedback {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  font-family: 'Inter', monospace;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* ショートカットヘルプボタン */
#showShortcutHelp {
  background: #ffffff !important;
  border: 2px solid #6c757d !important;
  color: #212529 !important;
  padding: 0.5em 1em;
  border-radius: 6px;
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  outline: none;
  text-decoration: none;
}

#showShortcutHelp:hover {
  background: #0077cc !important;
  border-color: #0077cc !important;
  color: #ffffff !important;
  box-shadow: 0 4px 8px rgba(0, 119, 204, 0.3);
  transform: translateY(-2px);
}

#showShortcutHelp:active {
  background: #005fa3 !important;
  border-color: #005fa3 !important;
  color: #ffffff !important;
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 95, 163, 0.4);
}

#showShortcutHelp:focus {
  border-color: #0077cc;
  box-shadow: 0 0 0 3px rgba(0, 119, 204, 0.25);
}

/* テーマトグルボタン */
#themeToggle {
  background: var(--bg-secondary) !important;
  border: 2px solid var(--border-primary) !important;
  color: var(--text-primary) !important;
  padding: 0.4em 0.8em;
  border-radius: 6px;
  font-size: 1.2em;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  outline: none;
  text-decoration: none;
  margin-left: 0.5em;
}

#themeToggle:hover {
  background: var(--btn-primary-bg) !important;
  border-color: var(--btn-primary-bg) !important;
  color: var(--btn-primary-text) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#themeToggle:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#themeToggle:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 119, 204, 0.25);
}

/* ヘルプボタン */
#helpButton {
  background: var(--bg-secondary) !important;
  border: 2px solid var(--border-primary) !important;
  color: var(--text-primary) !important;
  padding: 0.4em 0.8em;
  border-radius: 6px;
  font-size: 1.2em;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  outline: none;
  text-decoration: none;
  margin-right: 0.5em;
}

#helpButton:hover {
  background: var(--btn-primary-bg) !important;
  border-color: var(--btn-primary-bg) !important;
  color: var(--btn-primary-text) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#helpButton:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

#helpButton:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(0, 119, 204, 0.25);
}

/* モーダル */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.3s ease-out;
}

.modal.show {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background-color: var(--bg-secondary);
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  max-width: 800px;
  max-height: 90vh;
  width: 90%;
  display: flex;
  flex-direction: column;
  animation: slideInFromTop 0.3s ease-out;
  transition: background-color 0.3s ease;
}

.modal-header {
  padding: 1.5em 2em 1em 2em;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-secondary);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.5rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  margin: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  line-height: 1;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background-color: var(--cell-faded);
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5em 2em 2em 2em;
  overflow-y: auto;
  flex: 1;
  color: var(--text-primary);
}

.modal-body section {
  margin-bottom: 2em;
}

.modal-body section:last-child {
  margin-bottom: 0;
}

.modal-body h3 {
  color: var(--text-primary);
  font-size: 1.2rem;
  margin-bottom: 1em;
  border-bottom: 2px solid var(--border-secondary);
  padding-bottom: 0.5em;
}

.modal-body h4 {
  color: var(--text-secondary);
  font-size: 1rem;
  margin: 1em 0 0.5em 0;
}

.modal-body p {
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1em;
}

.modal-body ul {
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 1em;
  padding-left: 1.5em;
}

.modal-body li {
  margin-bottom: 0.5em;
}

.modal-body a {
  color: var(--btn-primary-bg);
  text-decoration: none;
}

.modal-body a:hover {
  text-decoration: underline;
}

/* ヘルプテーブル */
.help-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  background-color: var(--bg-tertiary);
  border-radius: 8px;
  overflow: hidden;
}

.help-table th,
.help-table td {
  padding: 0.8em 1em;
  text-align: left;
  border-bottom: 1px solid var(--border-secondary);
}

.help-table th {
  background-color: var(--cell-faded);
  color: var(--text-primary);
  font-weight: 600;
}

.help-table td {
  color: var(--text-secondary);
}

.help-table tr:last-child td {
  border-bottom: none;
}

.help-table kbd {
  background-color: var(--cell-bg);
  border: 1px solid var(--border-primary);
  border-radius: 4px;
  padding: 0.2em 0.5em;
  font-family: monospace;
  font-size: 0.9em;
  color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* モーダルアニメーション */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideInFromTop {
  from {
    opacity: 0;
    transform: translateY(-50px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* スクロールバーのカスタマイズ（Webkit系ブラウザ） */
.modal-body::-webkit-scrollbar {
  width: 8px;
}

.modal-body::-webkit-scrollbar-track {
  background: var(--bg-tertiary);
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
  background: var(--border-primary);
  border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
