:root {
  --primary-color: #4a7c7e;
  --primary-hover: #5a8c8e;
  --secondary-color: #7a9e9f;
  --success-color: #4a7c59;
  --error-color: #a44a4a;
  --border-color: #d0d0d0;
  --bg-light: #f8f9fa;
  --text-dark: #333;
  --text-light: #666;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 20px auto;
  max-width: 1200px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  min-height: 100vh;
  color: var(--text-dark);
  padding: 0 20px;
}

h1 {
  text-align: center;
  color: var(--primary-color);
  font-weight: 600;
  margin-bottom: 10px;
}

h2 {
  color: var(--primary-color);
  border-bottom: 2px solid var(--primary-color);
  padding-bottom: 5px;
  margin-bottom: 15px;
}

h3 {
  color: var(--secondary-color);
  margin-top: 20px;
}

.subtitle {
  text-align: center;
  color: var(--text-light);
  font-size: 14px;
  margin-top: -10px;
  margin-bottom: 25px;
  font-style: italic;
}

.tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 0;
  background: var(--bg-light);
  padding: 5px;
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--border-color);
  border-bottom: none;
}

.tab-button {
  flex: 1;
  padding: 10px 15px;
  cursor: pointer;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 5px 5px 0 0;
  color: var(--text-dark);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
}

.tab-button:hover {
  background: var(--primary-color);
  color: white;
  transform: translateY(-2px);
}

.tab-button.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  box-shadow: 0 -2px 8px rgba(74, 124, 126, 0.3);
}

.tab-content {
  display: none;
  border: 1px solid var(--border-color);
  border-top: 3px solid var(--primary-color);
  padding: 25px;
  background: white;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.input-group {
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.input-group label {
  min-width: 150px;
  font-weight: 500;
}

.help-text {
  color: var(--text-light);
  font-size: 12px;
  margin-left: 10px;
  font-style: italic;
}

/* ツールチップのスタイル */
.tooltip {
  position: relative;
  display: inline-block;
  margin-left: 8px;
}

.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background-color: var(--secondary-color);
  color: white;
  font-size: 12px;
  font-weight: bold;
  cursor: help;
  user-select: none;
  transition: all 0.3s ease;
}

.help-icon:hover {
  background-color: var(--primary-color);
  transform: scale(1.1);
}

.tooltip-text {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background-color: #333;
  color: white;
  padding: 10px 15px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  white-space: normal;
  width: 400px;
  max-width: 90vw;
  text-align: left;
  z-index: 1000;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.tooltip-text::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: #333;
}

.tooltip:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* ツールチップがウィンドウ外に出る場合の調整 */
@media (max-width: 600px) {
  .tooltip-text {
    position: fixed;
    left: 10px !important;
    right: 10px;
    max-width: none;
    transform: none;
    bottom: auto;
    top: 50px;
  }

  .tooltip-text::after {
    display: none;
  }
}

/* トースト通知のスタイル */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  background-color: var(--success-color);
  color: white;
  padding: 12px 20px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 2000;
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast.hide {
  opacity: 0;
  transform: translateX(100%);
}

@media (max-width: 600px) {
  .toast {
    top: 10px;
    right: 10px;
    left: 10px;
    transform: translateY(-100%);
  }

  .toast.show {
    transform: translateY(0);
  }

  .toast.hide {
    transform: translateY(-100%);
  }
}

input[type="text"],
input[type="file"],
select,
textarea {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.3s;
  font-family: inherit;
}

input[type="text"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(74, 124, 126, 0.1);
}

input#seed,
input#reservedCodes {
  width: 300px;
}

input#dummyChar,
input#decryptDummyChar {
  width: 50px;
  text-align: center;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 100px;
  max-width: 600px;
}

button {
  padding: 10px 20px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  margin: 5px;
}

button:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

button:active {
  transform: translateY(0);
}

.file-input-button {
  padding: 10px 20px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.3s ease;
  margin: 5px;
  display: inline-block;
  text-align: center;
  user-select: none;
}

.file-input-button:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.file-input-button:active {
  transform: translateY(0);
}

.button-group {
  margin: 15px 0;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.input-with-button {
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.textarea-container {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.input-with-button textarea {
  width: 100%;
  max-width: 600px;
  flex: 1;
}

.clear-button {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  background: var(--error-color);
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  align-self: flex-start;
  white-space: nowrap;
}

.clear-button:hover {
  background: #c54545;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.clear-button:active {
  transform: translateY(0);
}

.copy-button {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  background: var(--primary-color);
  border: none;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  transition: all 0.3s ease;
  align-self: flex-start;
  white-space: nowrap;
}

.copy-button:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.copy-button:active {
  transform: translateY(0);
}

#matrixDisplay {
  overflow-x: auto;
  overflow-y: auto;
  min-height: 100px;
  max-height: none;
  border: 1px solid var(--border-color);
  padding: 15px;
  background: var(--bg-light);
  border-radius: 4px;
}

#matrixDisplay:empty::before {
  content: "置換表が生成されていません。「3桁乱数表を生成」ボタンをクリックしてください。";
  color: var(--text-light);
  font-family: 'Segoe UI', sans-serif;
  font-style: italic;
  display: block;
  padding: 20px;
  text-align: center;
}

/* マトリクステーブルのスタイル */
.matrix-table {
  border-collapse: collapse;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  width: auto;
  margin: 0 auto;
}

.matrix-table th,
.matrix-table td {
  border: 1px solid #ddd;
  padding: 4px 6px;
  text-align: center;
  position: relative;
}

.matrix-table thead th {
  background: #f0f0f0;
  font-weight: bold;
  color: var(--primary-color);
  position: sticky;
  top: -15px;
  z-index: 10;
}

.matrix-table tbody th {
  background: #f0f0f0;
  font-weight: bold;
  color: var(--primary-color);
  position: sticky;
  left: -15px;
  z-index: 5;
}

.matrix-table tbody td {
  background: white;
  transition: background-color 0.2s ease;
}

/* ホバー効果 */
.matrix-cell.row-highlight {
  background-color: rgba(74, 124, 126, 0.1) !important;
}

.matrix-cell.col-highlight {
  background-color: rgba(74, 124, 126, 0.1) !important;
}

.matrix-cell.cell-highlight {
  background-color: rgba(74, 124, 126, 0.3) !important;
  font-weight: bold;
  transform: scale(1.1);
  z-index: 2;
  box-shadow: 0 0 5px rgba(74, 124, 126, 0.5);
}

.header-highlight {
  background-color: rgba(74, 124, 126, 0.2) !important;
  font-weight: bold;
}

#keyStatus {
  padding: 10px;
  border-radius: 4px;
  margin: 10px 0;
  font-weight: 500;
  transition: all 0.3s;
}

#keyStatus:empty {
  display: none;
}

#keyStatus.success {
  background: #e8f5e9;
  color: var(--success-color);
  border-left: 4px solid var(--success-color);
}

#keyStatus.error {
  background: #ffebee;
  color: var(--error-color);
  border-left: 4px solid var(--error-color);
}

.export-button-container {
  text-align: right;
  margin-top: 15px;
}

.footer {
  margin-top: 40px;
  padding: 20px;
  text-align: center;
  font-size: 0.9em;
  color: var(--text-light);
  border-top: 1px solid var(--border-color);
}

.footer a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
}

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

/* 通信シミュレーター用スタイル */
.comm-instruction {
  background: #e3f2fd;
  border: 1px solid #2196f3;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 25px;
}

.comm-instruction h3 {
  margin: 0 0 15px 0;
  color: #1565c0;
  font-size: 16px;
}

.comm-instruction p {
  margin: 8px 0;
  color: #0d47a1;
  line-height: 1.5;
}

.comm-instruction .example {
  background: rgba(33, 150, 243, 0.1);
  padding: 10px;
  border-radius: 4px;
  font-style: italic;
  margin-top: 12px;
}

.comm-result {
  margin-top: 20px;
}

.result-step {
  margin-bottom: 20px;
  padding: 15px;
  background: var(--bg-light);
  border-radius: 6px;
  border-left: 4px solid var(--primary-color);
}

.result-step h4 {
  margin: 0 0 10px 0;
  color: var(--primary-color);
  font-size: 14px;
  font-weight: 600;
}

.result-step pre {
  margin: 0;
  padding: 10px;
  background: white;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  word-wrap: break-word;
  white-space: pre-wrap;
  min-height: 20px;
}

.result-status {
  margin-top: 15px;
  padding: 12px 15px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
}

.result-status.success {
  background: #e8f5e9;
  color: var(--success-color);
  border-left: 4px solid var(--success-color);
}

.result-status.warning {
  background: #fff3e0;
  color: #e65100;
  border-left: 4px solid #e65100;
}

/* セキュリティ警告スタイル */
.security-warning {
  background: #ffebee;
  border: 1px solid #f44336;
  border-radius: 8px;
  padding: 20px;
  margin: 25px 0;
}

.security-warning h3 {
  margin: 0 0 15px 0;
  color: #c62828;
  font-size: 16px;
  font-weight: 600;
}

.security-warning p {
  margin: 8px 0;
  color: #b71c1c;
  line-height: 1.5;
}

.security-warning ul {
  margin: 12px 0;
  padding-left: 20px;
  color: #b71c1c;
}

.security-warning li {
  margin: 6px 0;
  line-height: 1.4;
}

/* Wide screens - optimize for 26x26 matrix display */
@media (min-width: 1400px) {
  body {
    max-width: 1400px;
  }

  .matrix-table {
    font-size: 13px;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 5px 7px;
  }
}

@media (min-width: 1600px) {
  body {
    max-width: 1600px;
  }

  .matrix-table {
    font-size: 14px;
  }

  .matrix-table th,
  .matrix-table td {
    padding: 6px 8px;
  }
}

/* Mobile and tablet screens */
@media (max-width: 600px) {
  body {
    padding: 0 10px;
    margin: 10px auto;
  }

  .tabs {
    flex-direction: column;
    padding: 5px;
  }

  .tab-button {
    width: 100%;
    margin: 2px 0;
  }

  .input-group {
    flex-direction: column;
    align-items: flex-start;
  }

  .input-group label {
    min-width: auto;
  }

  input#seed,
  input#reservedCodes {
    width: 100%;
  }

  .button-group {
    flex-direction: column;
  }

  button {
    width: 100%;
    margin: 5px 0;
  }

  .textarea-container {
    flex-direction: column;
    gap: 8px;
  }

  .clear-button,
  .copy-button {
    align-self: stretch;
  }
}