/* style.css */

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #333;
}

header {
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  padding: 2rem 1rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
  position: relative;
}

.header-text {
  text-align: center;
  flex: 1;
}

.header-text h1 {
  margin: 0;
  color: #4a90e2;
}

.header-text p {
  margin: 0.5rem 0 0 0;
  color: #666;
}

.help-button {
  position: absolute;
  right: 0;
  width: 40px !important;
  height: 40px !important;
  border-radius: 50% !important;
  background: #4a90e2 !important;
  color: white !important;
  border: none !important;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex !important;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  padding: 0 !important;
  margin: 0 !important;
  min-width: 40px;
  min-height: 40px;
  outline: none;
}

.help-button:hover {
  background: #357ab8;
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.3);
}

.tabs {
  display: flex;
  justify-content: center;
  background: transparent;
  max-width: 800px;
  margin: 2rem auto 0;
  gap: 0.5rem;
}

.tab-button {
  padding: 0.75rem 2rem;
  border: none;
  background: rgba(255, 255, 255, 0.7);
  cursor: pointer;
  font-weight: 600;
  color: #333;
  border-radius: 12px 12px 0 0;
  transition: all 0.3s ease;
}

.tab-button:hover {
  background: rgba(255, 255, 255, 0.85);
}

.tab-button.active {
  background: white;
  color: #4a90e2;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.tab-content {
  max-width: 800px;
  margin: 0 auto 2rem;
  padding: 2rem;
  display: block;
  background: white;
  border-radius: 0 0 12px 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.tab-content.hidden {
  display: none;
}

textarea {
  width: 100%;
  font-size: 1rem;
  padding: 0.75rem;
  margin: 0.5rem 0;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  transition: border-color 0.3s;
  box-sizing: border-box;
}

textarea:focus {
  outline: none;
  border-color: #4a90e2;
}

label {
  display: inline-block;
  margin-right: 1rem;
  margin-bottom: 0.5rem;
  color: #555;
}

select {
  padding: 0.5rem;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  background: white;
  cursor: pointer;
  transition: border-color 0.3s;
}

select:focus {
  outline: none;
  border-color: #4a90e2;
}

input[type="checkbox"] {
  margin-right: 0.5rem;
  cursor: pointer;
}

#warning-area,
#decryptWarningArea {
  font-size: 0.9rem;
  margin: 0;
  min-height: 0;
  transition: all 0.3s ease;
  font-weight: 500;
}

#warning-area:not(:empty),
#decryptWarningArea:not(:empty) {
  margin: 0.5rem 0;
  min-height: 1.2rem;
  padding: 0.5rem;
  border-radius: 6px;
}

#warning-area.info,
#decryptWarningArea.info {
  color: #666;
  background: #f0f4f8;
  border: 1px solid #d0d4d8;
}

#warning-area.warning,
#decryptWarningArea.warning {
  color: #f39c12;
  background: #fef9e7;
  border: 1px solid #fcf4a3;
}

#warning-area.error,
#decryptWarningArea.error {
  color: #ff6b6b;
  background: #fff0f0;
  border: 1px solid #ffdddd;
}

.readonly-box {
  background: #e8e9ea;
  padding: 1rem;
  margin: 1.5rem 0 1rem 0;
  border: 1px dashed #ccc;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  color: #666;
  position: relative;
  min-height: 1.5rem;
}

.readonly-box strong {
  color: #333;
  font-weight: 700;
  letter-spacing: 0.5px;
}

#cleanedText::before {
  content: "処理後のテキスト:";
  position: absolute;
  top: -10px;
  left: 10px;
  background: white;
  padding: 0 5px;
  font-size: 0.8rem;
  color: #999;
  font-weight: 600;
}

#intermediateText::before {
  content: "レールから読み取った順序:";
  position: absolute;
  top: -10px;
  left: 10px;
  background: white;
  padding: 0 5px;
  font-size: 0.8rem;
  color: #999;
  font-weight: 600;
}

#decryptIntermediateText::before {
  content: "復号過程 - レール配置:";
  position: absolute;
  top: -10px;
  left: 10px;
  background: white;
  padding: 0 5px;
  font-size: 0.8rem;
  color: #999;
  font-weight: 600;
}

button {
  padding: 0.75rem 2rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  margin-top: 1rem;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.3s;
}

button:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

button:disabled {
  background: linear-gradient(135deg, #ccc 0%, #999 100%);
  cursor: not-allowed;
  opacity: 0.6;
}

#railDisplay,
#decryptDisplay {
  margin-top: 1.5rem;
  padding: 1.5rem;
  font-family: 'Courier New', monospace;
  white-space: pre;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  font-size: 1.1rem;
  line-height: 1.6;
  overflow-x: auto;
}

.rail-grid {
  display: table;
  border-collapse: separate;
  border-spacing: 2px;
  margin: 0 auto;
  background: white;
  padding: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.rail-row {
  display: table-row;
}

.rail-row[data-rail="0"] .rail-cell.filled {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.rail-row[data-rail="1"] .rail-cell.filled {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.rail-row[data-rail="2"] .rail-cell.filled {
  background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.rail-row[data-rail="3"] .rail-cell.filled {
  background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
}

.rail-row[data-rail="4"] .rail-cell.filled {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.rail-row[data-rail="5"] .rail-cell.filled {
  background: linear-gradient(135deg, #30cfd0 0%, #330867 100%);
}

.rail-label {
  display: table-cell;
  padding: 0.5rem 1rem;
  font-weight: 600;
  color: #666;
  text-align: right;
  min-width: 60px;
  vertical-align: middle;
}

.rail-cell {
  display: table-cell;
  width: 32px;
  height: 32px;
  text-align: center;
  vertical-align: middle;
  border-radius: 4px;
  font-weight: 600;
  transition: all 0.3s ease;
}

.rail-cell.filled {
  color: white;
  animation: fadeIn 0.3s ease;
}

.rail-cell.empty {
  background: #f0f0f0;
  opacity: 0.3;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.result-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.copy-btn {
  padding: 0.5rem 1rem;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  margin: 0;
}

.copy-btn:hover {
  background: #357ab8;
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(74, 144, 226, 0.3);
}

#cipherResult,
#plainResult {
  margin-top: 1.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1.1rem;
}

.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.95);
  margin-top: 3rem;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}

.footer a {
  color: #4a90e2;
  text-decoration: none;
  font-weight: 600;
}

.footer a:hover {
  text-decoration: underline;
}

.toast {
  background: #4CAF50;
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.error {
  background: #f44336;
}

.toast.show {
  opacity: 1;
  animation: toastSlideIn 0.3s ease;
}

@keyframes toastSlideIn {
  from {
    transform: translate(-50%, -120%);
    opacity: 0;
  }
  to {
    transform: translate(-50%, -100%);
    opacity: 1;
  }
}

.animation-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1.5rem;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.animation-controls.hidden {
  display: none;
}

.animation-controls button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  margin: 0;
}

.animation-controls label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
}

.animation-controls input[type="range"] {
  width: 150px;
  cursor: pointer;
}

.animation-controls input[type="range"]:hover {
  opacity: 0.8;
}

#speedDisplay {
  min-width: 60px;
  font-weight: 600;
  color: #667eea;
}

.rail-cell.hidden-cell {
  opacity: 0;
  visibility: hidden;
}

.rail-cell.animate-appear {
  animation: cellAppear 0.5s ease forwards;
}

@keyframes cellAppear {
  0% {
    opacity: 0;
    visibility: hidden;
    transform: scale(0) rotate(180deg);
  }
  50% {
    transform: scale(1.2) rotate(90deg);
  }
  100% {
    opacity: 1;
    visibility: visible;
    transform: scale(1) rotate(0deg);
  }
}

.sample-buttons {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.sample-btn {
  padding: 0.5rem 1rem;
  background: #f8f9fa;
  color: #333;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.3s ease;
  margin: 0;
}

.sample-btn:hover {
  background: #e9ecef;
  border-color: #4a90e2;
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(74, 144, 226, 0.2);
}

.sample-btn:active {
  transform: translateY(0);
}

.export-controls {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.export-controls.hidden {
  display: none;
}

.export-controls button {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  margin: 0;
  background: #28a745;
  border: none;
  border-radius: 6px;
  color: white;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
}

.export-controls button:hover {
  background: #218838;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(40, 167, 69, 0.3);
}

.export-controls button:nth-child(2) {
  background: #17a2b8;
}

.export-controls button:nth-child(2):hover {
  background: #138496;
  box-shadow: 0 4px 12px rgba(23, 162, 184, 0.3);
}

.export-controls button:nth-child(3) {
  background: #6f42c1;
}

.export-controls button:nth-child(3):hover {
  background: #5a32a3;
  box-shadow: 0 4px 12px rgba(111, 66, 193, 0.3);
}

/* Lab tab styles */
.experiment-section {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: #f8f9fa;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.experiment-section h3 {
  margin-top: 0;
  color: #4a90e2;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 0.5rem;
}

.experiment-input {
  margin: 1rem 0;
}

.experiment-input label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #555;
}

.experiment-info {
  margin: 1rem 0;
  padding: 1rem;
  background: #f0f4f8;
  border-radius: 6px;
  border: 1px solid #d0d4d8;
}

.experiment-info details {
  margin: 0;
}

.experiment-info summary {
  cursor: pointer;
  font-weight: 600;
  color: #4a90e2;
  padding: 0.5rem 0;
  outline: none;
}

.experiment-info summary:hover {
  color: #357ab8;
}

.experiment-info ul {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.experiment-info li {
  margin: 0.5rem 0;
  color: #555;
}

.experiment-controls {
  display: flex;
  gap: 1rem;
  align-items: center;
  margin: 1rem 0;
  flex-wrap: wrap;
}

.experiment-results {
  margin-top: 1.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.lab-results-table {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lab-result-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: white;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  transition: all 0.3s ease;
}

.lab-result-row:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.lab-result-row.high-score {
  border-left: 4px solid #28a745;
}

.lab-result-row.medium-score {
  border-left: 4px solid #ffc107;
}

.lab-result-row.low-score {
  border-left: 4px solid #dc3545;
}

.lab-result-info {
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.lab-result-text {
  flex: 1;
  font-family: 'Courier New', monospace;
  background: #f8f9fa;
  padding: 0.5rem;
  border-radius: 4px;
  word-break: break-all;
}

.lab-score {
  font-size: 0.9rem;
  color: #666;
  font-weight: 500;
}

.lab-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.lab-stat-card {
  background: white;
  border-radius: 8px;
  border: 1px solid #e0e0e0;
  overflow: hidden;
  transition: all 0.3s ease;
}

.lab-stat-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.lab-stat-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 1rem;
}

.lab-stat-header h5 {
  margin: 0;
  font-size: 1rem;
}

.lab-stat-content {
  padding: 1rem;
}

.lab-stat-content p {
  margin: 0 0 1rem 0;
  word-break: break-all;
  font-family: 'Courier New', monospace;
  background: #f8f9fa;
  padding: 0.5rem;
  border-radius: 4px;
}

.lab-stat-metrics {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.metric-value {
  font-weight: 600;
  color: #4a90e2;
}

.lab-summary {
  margin-top: 2rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.lab-summary h5 {
  margin-top: 0;
  color: #4a90e2;
}

/* Study tab styles */
.study-section {
  margin-bottom: 2.5rem;
  padding: 0;
}

.study-section h3 {
  color: #4a90e2;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.study-section h4 {
  color: #333;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
}

.study-highlight {
  background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
  padding: 1.5rem;
  border-radius: 8px;
  border: 1px solid #d0d4d8;
  margin: 1rem 0;
}

.study-highlight h4 {
  margin-top: 0;
  color: #4a90e2;
}

.study-tips {
  background: #f0f8ff;
  padding: 1.5rem;
  border-radius: 8px;
  border-left: 4px solid #4a90e2;
  margin: 1rem 0;
}

.study-tips h4 {
  margin-top: 0;
  color: #4a90e2;
}

.method-explanation {
  margin: 1rem 0;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

.example-box {
  background: #fff;
  padding: 1rem;
  border-radius: 6px;
  border: 1px solid #d0d4d8;
  margin: 1rem 0;
  font-family: 'Courier New', monospace;
  line-height: 1.6;
}

.example-box strong {
  color: #4a90e2;
  font-weight: 600;
}

.study-section ul {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.study-section li {
  margin: 0.5rem 0;
  line-height: 1.6;
}

.study-section ol {
  margin: 1rem 0;
  padding-left: 1.5rem;
}

.study-section ol li {
  margin: 0.8rem 0;
  line-height: 1.6;
}

.study-section p {
  line-height: 1.7;
  margin: 1rem 0;
}

.study-section strong {
  color: #333;
  font-weight: 600;
}

/* Rail example grid styles */
.rail-example {
  margin: 1rem 0;
  padding: 1rem;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

.rail-example-grid {
  display: grid;
  grid-template-columns: 80px repeat(5, 40px);
  gap: 2px;
  align-items: center;
  font-family: 'Courier New', monospace;
  font-size: 14px;
}

.rail-example-grid .rail-label {
  font-weight: 600;
  color: #666;
  text-align: right;
  padding-right: 0.5rem;
}

.rail-example-grid .rail-cell {
  width: 35px;
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-weight: 600;
  border: 1px solid #d0d4d8;
}

.rail-example-grid .rail-cell.filled {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.rail-example-grid .rail-cell.empty {
  background: #f0f0f0;
  color: #999;
}

/* Crypto explanation styles */
.crypto-explanation {
  margin-top: 0.5rem;
  padding: 1rem;
  background: #f0f8ff;
  border-radius: 6px;
  border-left: 3px solid #4a90e2;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #555;
}

/* Modal styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-content {
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  max-width: 700px;
  max-height: 80vh;
  width: 90%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.modal-close {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.3s ease;
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.help-section {
  margin-bottom: 2rem;
}

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

.help-section h3 {
  color: #4a90e2;
  border-bottom: 2px solid #e0e0e0;
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.help-section h4 {
  color: #333;
  margin: 1.5rem 0 0.5rem 0;
  font-size: 1rem;
}

.help-section ul,
.help-section ol {
  margin: 0.5rem 0;
  padding-left: 1.5rem;
}

.help-section li {
  margin: 0.5rem 0;
  line-height: 1.6;
}

.help-section a {
  color: #4a90e2;
  text-decoration: none;
}

.help-section a:hover {
  text-decoration: underline;
}

@media print {
  .rail-grid {
    background: white !important;
    box-shadow: none !important;
    border: 2px solid #000 !important;
  }
  
  .rail-cell {
    border: 1px solid #000 !important;
  }
  
  .rail-cell.filled {
    background: #f0f0f0 !important;
    color: #000 !important;
    font-weight: bold !important;
  }
  
  .rail-label {
    font-weight: bold !important;
    color: #000 !important;
  }
}

.sync-controls-top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

#syncFromEncrypt {
  padding: 0.5rem 1rem;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
  margin: 0;
  font-size: 0.9rem;
}

#syncFromEncrypt:hover {
  background: #0056b3;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 123, 255, 0.3);
}

.sync-status {
  font-size: 0.9rem;
  color: #666;
  font-weight: 500;
}

.sync-status.success {
  color: #28a745;
}

.sync-status.error {
  color: #dc3545;
}
