/* =================================
   1. Reset & Base Styles
   ================================= */
*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  background-color: #f5f5f5;
  color: #222;
}

/* =================================
   2. Layout - Container
   ================================= */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* =================================
   3. Header
   ================================= */
header {
  position: relative;
  padding: 1.5rem 1.5rem 1.25rem;
  margin: -1rem -1rem 0;
  text-align: center;
  border-bottom: 2px solid #ddd;
}

header h1 {
  font-size: 1.5rem;
  margin: 0 0 0.25rem;
  color: #1a1a2e;
  letter-spacing: 0.05em;
}

header .subtitle {
  margin: 0;
  color: #666;
  font-size: 0.9rem;
}

/* Help Button */
.help-btn {
  position: absolute;
  top: 50%;
  right: 1rem;
  transform: translateY(-50%);
  width: 2rem;
  height: 2rem;
  border: 2px solid #999;
  border-radius: 50%;
  background: transparent;
  color: #666;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.help-btn:hover {
  background-color: #4a90d9;
  border-color: #4a90d9;
  color: #fff;
}

/* =================================
   3.5 Tab Navigation
   ================================= */
.tab-nav {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid #ddd;
  margin-bottom: 1.5rem;
}

.tab-btn {
  padding: 0.75rem 1.5rem;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 500;
  color: #666;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: #4a90d9;
}

.tab-btn.active {
  color: #4a90d9;
  border-bottom-color: #4a90d9;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Analysis Placeholder */
.analysis-placeholder {
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  padding: 2rem;
  text-align: center;
}

.placeholder-message {
  color: #666;
  font-size: 1.1rem;
  margin: 1rem 0;
}

.planned-features {
  display: inline-block;
  text-align: left;
  color: #888;
  margin: 1rem 0 0;
  padding-left: 1.5rem;
}

.planned-features li {
  margin: 0.5rem 0;
}

/* =================================
   3.6 Modal
   ================================= */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal[hidden] {
  display: none;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
}

.modal-content {
  position: relative;
  background-color: #fff;
  border-radius: 0.5rem;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  margin: 0;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #ddd;
  font-size: 1.25rem;
  color: #1a1a2e;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.6;
}

.modal-body h3 {
  margin: 1.5rem 0 0.5rem;
  font-size: 1rem;
  color: #1a1a2e;
}

.modal-body h3:first-child {
  margin-top: 0;
}

.modal-body p,
.modal-body ul,
.modal-body ol,
.modal-body dl {
  margin: 0.5rem 0;
}

.modal-body dt {
  font-weight: 600;
  margin-top: 0.5rem;
}

.modal-body dd {
  margin-left: 1rem;
  color: #555;
}

.modal-body code {
  background-color: #f0f0f0;
  padding: 0.1rem 0.3rem;
  border-radius: 0.2rem;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.85em;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  color: #666;
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover {
  color: #000;
}

/* Confirm Modal */
.modal-confirm {
  max-width: 400px;
  text-align: center;
}

.modal-confirm h2 {
  border-bottom: none;
  padding-bottom: 0;
}

.modal-confirm .modal-body {
  padding: 1rem 1.5rem 1.5rem;
}

.modal-confirm .modal-body p {
  font-size: 1rem;
  color: #333;
}

.modal-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  padding: 0 1.5rem 1.5rem;
}

.modal-actions .btn-secondary,
.modal-actions .btn-danger {
  min-width: 100px;
}

/* =================================
   4. Typography
   ================================= */

label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 500;
  font-size: 0.9rem;
}

/* =================================
   4. Form Elements
   ================================= */
fieldset {
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  padding: 1rem;
  margin: 0;
  background: #fff;
}

legend {
  font-weight: 600;
  padding: 0 0.5rem;
  color: #1a1a2e;
}

input[type="text"],
textarea {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
  font-size: 1rem;
  font-family: "Consolas", "Monaco", monospace;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

textarea {
  min-height: 6rem;
  resize: vertical;
}

textarea[readonly] {
  background-color: #f9f9f9;
}

.helper-text {
  font-size: 0.8rem;
  color: #666;
  margin: 0.5rem 0 0;
}

/* Error Styles */
.input-error {
  border-color: #dc3545 !important;
  background-color: #fff5f5;
}

.input-error:focus {
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2) !important;
}

.error-messages {
  background-color: #f8d7da;
  border: 1px solid #f5c6cb;
  border-radius: 0.5rem;
  padding: 1rem;
  color: #721c24;
  font-size: 0.9rem;
  white-space: pre-line;
}

.error-messages[hidden] {
  display: none;
}

/* =================================
   6. Settings Section
   ================================= */
.settings {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  padding: 1.5rem;
}

.section-title {
  margin: 0 0 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #4a90d9;
  font-size: 1.1rem;
  font-weight: 600;
  color: #1a1a2e;
}

/* Scramblers */
.scramblers-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.scrambler-inputs {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.wiring-group {
  flex: 1;
}

.position-group {
  width: 3.5rem;
}

.position-group input {
  text-align: center;
  text-transform: uppercase;
}

.notch-group {
  width: auto;
  min-width: 4.5rem;
}

.notch-group input.notch {
  width: 2.5rem;
  text-align: center;
  text-transform: uppercase;
}

.notch-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  cursor: pointer;
}

.notch-toggle-label input[type="checkbox"] {
  width: 0.9rem;
  height: 0.9rem;
  cursor: pointer;
  accent-color: #4a90d9;
}

.notch-toggle-label span {
  user-select: none;
}

/* Disable notch input when toggle is off */
.notch-group:has(.notch-toggle:not(:checked)) .notch {
  opacity: 0.5;
  background-color: #f0f0f0;
  pointer-events: none;
}

/* Attack tab notch group - inline style */
.attack-notch-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.attack-notch-group .notch-toggle-label {
  font-size: 0.75rem;
  margin-bottom: 0;
  white-space: nowrap;
}

.attack-notch-group .notch-toggle-label input[type="checkbox"] {
  width: 0.8rem;
  height: 0.8rem;
}

.attack-notch-group .notch {
  width: 2rem;
  padding: 0.35rem 0.25rem;
  text-align: center;
  text-transform: uppercase;
  font-size: 0.85rem;
}

/* Disable notch input when toggle is off */
.attack-notch-group:has(.notch-toggle:not(:checked)) .notch {
  opacity: 0.5;
  background-color: #f0f0f0;
  pointer-events: none;
}

.wiring {
  text-transform: uppercase;
}

/* Preset Select */
.preset-group {
  width: 100%;
}

.preset-select {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
  font-size: 0.9rem;
  background-color: #fff;
  cursor: pointer;
}

.preset-select:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

/* Reflector Inputs */
.reflector-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.reflector-inputs .preset-group {
  max-width: 200px;
}

/* Mode Toggle */
.mode-toggle {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.mode-toggle legend {
  width: 100%;
  margin-bottom: 0.5rem;
}

.mode-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  cursor: pointer;
  font-weight: normal;
  margin-bottom: 0;
}

.mode-toggle input[type="radio"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.mode-toggle .helper-text {
  width: 100%;
}

/* Toggleable Fieldsets */
.toggleable {
  transition: opacity 0.2s, background-color 0.2s;
}

.toggleable.disabled {
  opacity: 0.5;
  background-color: #f0f0f0;
}

.toggleable.disabled .toggle-content {
  pointer-events: none;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0;
}

.toggle-label input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  accent-color: #4a90d9;
}

.toggle-label span {
  user-select: none;
}

/* Action Buttons */
.action-buttons {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 0;
  flex-wrap: wrap;
}

.action-buttons .btn-danger {
  margin-left: 2rem;
}

.btn-primary {
  padding: 0.75rem 2rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background-color: #4a90d9;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-secondary {
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #4a90d9;
  background-color: transparent;
  border: 2px solid #4a90d9;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background-color: #4a90d9;
  color: #fff;
}

.btn-secondary.copied {
  background-color: #28a745;
  border-color: #28a745;
  color: #fff;
}

.btn-danger {
  padding: 0.75rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: #dc3545;
  background-color: transparent;
  border: 2px solid #dc3545;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover {
  background-color: #dc3545;
  color: #fff;
}

.btn-primary:hover {
  background-color: #3a7bc8;
}

.btn-primary:active {
  background-color: #2d6cb5;
}

/* =================================
   6. Action Buttons (standalone)
   ================================= */

/* =================================
   7. Input Section
   ================================= */
.input-section {
  display: flex;
  flex-direction: column;
}

/* =================================
   8. Results Section
   ================================= */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.output-area {
  display: flex;
  flex-direction: column;
}

.log-area {
  display: flex;
  flex-direction: column;
}

.area-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.area-header label {
  margin-bottom: 0;
}

.copy-btn {
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #4a90d9;
  background-color: transparent;
  border: 1px solid #4a90d9;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: all 0.2s;
}

.copy-btn:hover {
  background-color: #4a90d9;
  color: #fff;
}

.copy-btn.copied {
  background-color: #28a745;
  border-color: #28a745;
  color: #fff;
}

.log-area pre {
  background: #1a1a2e;
  color: #e0e0e0;
  padding: 1rem;
  border-radius: 0.5rem;
  overflow: auto;
  font-size: 0.8rem;
  font-family: "Consolas", "Monaco", monospace;
  line-height: 1.5;
  white-space: pre;
  min-height: 10rem;
  max-height: 30rem;
  margin: 0;
}

.log-area pre:empty::before {
  content: "処理ログがここに表示されます";
  color: #666;
}

/* =================================
   9. Footer
   ================================= */
.footer {
  text-align: center;
  padding: 1.25rem 1.5rem;
  margin: 1rem -1rem -1rem;
  color: #666;
  font-size: 0.85rem;
  border-top: 2px solid #ddd;
}

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

.footer a:hover {
  color: #2d6cb5;
  text-decoration: underline;
}

/* =================================
   10. Media Queries (Tablet 600px+)
   ================================= */
@media (min-width: 600px) {
  header h1 {
    font-size: 1.75rem;
  }

  .scramblers-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }

  .scrambler-inputs {
    flex-direction: column;
    align-items: stretch;
  }

  .position-group {
    width: 100%;
  }
}

/* =================================
   11. Media Queries (PC 900px+)
   ================================= */
@media (min-width: 900px) {
  .container {
    padding: 2rem;
  }

  header {
    margin: -2rem -2rem 0;
    padding: 2rem 2rem 1.5rem;
  }

  header h1 {
    font-size: 1.75rem;
  }

  .footer {
    margin: 1.5rem -2rem -2rem;
    padding: 1.5rem 2rem;
  }

  textarea {
    min-height: 8rem;
  }

  .log-area pre {
    font-size: 0.875rem;
  }
}

/* =================================
   12. Analysis Section Styles
   ================================= */

/* Analysis Section */
.analysis-section {
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.section-description {
  color: #666;
  font-size: 0.9rem;
  margin: 0;
}

/* Attack Settings */
.attack-settings {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.attack-fieldset {
  margin: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  border-radius: 0.25rem;
  background-color: #fafafa;
}

.attack-fieldset legend {
  padding: 0 0.25rem;
  font-size: 0.9rem;
}

.attack-scramblers {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.scrambler-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.attack-preset-select {
  padding: 0.35rem;
  font-size: 0.85rem;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
}

.attack-fieldset .wiring {
  font-size: 0.85rem;
  padding: 0.35rem 0.5rem;
}

/* Attack Inputs */
.attack-inputs {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.attack-inputs .input-group {
  display: flex;
  flex-direction: column;
}

.attack-inputs textarea {
  min-height: 5rem;
}

/* Plaintext Grid */
.plaintext-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 0.5rem;
  background-color: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 0.25rem;
  overflow-x: auto;
  min-height: 3rem;
}

.grid-placeholder {
  color: #888;
  font-size: 0.9rem;
  margin: 0;
  padding: 0.5rem;
}

.grid-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.grid-cipher-char {
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.8rem;
  font-weight: 600;
  color: #1a1a2e;
  width: 1.2rem;
  text-align: center;
}

input.grid-plain-input {
  width: 1.2rem;
  height: 1.2rem;
  min-width: 1.2rem;
  max-width: 1.2rem;
  padding: 0;
  text-align: center;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.8rem;
  text-transform: uppercase;
  border: 1px solid #ccc;
  border-radius: 2px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

input.grid-plain-input:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 1px rgba(74, 144, 217, 0.3);
}

.grid-separator {
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.7rem;
  color: #888;
  padding: 0 1px;
  display: flex;
  align-items: center;
  min-height: 2rem;
}

/* Search Info */
.search-info {
  padding: 0.75rem 1rem;
  background-color: #f0f8ff;
  border-radius: 0.25rem;
  font-size: 0.9rem;
  color: #0066cc;
}

.search-space strong {
  font-weight: 600;
}

/* Attack Actions */
.attack-actions {
  display: flex;
  justify-content: center;
  padding: 0.5rem 0;
}

/* Progress Indicator */
.progress-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1rem;
  background-color: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 0.5rem;
  color: #856404;
}

.progress-indicator[hidden] {
  display: none;
}

.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid #ffc107;
  border-top-color: #856404;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Attack Results */
.attack-results-section {
  margin-top: 0.5rem;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #ddd;
}

.results-header h3 {
  margin: 0;
  font-size: 1rem;
  color: #1a1a2e;
}

#attack-result-count {
  font-size: 0.9rem;
  color: #666;
  font-weight: 500;
}

.attack-results {
  max-height: 400px;
  overflow-y: auto;
  padding: 0.5rem;
  background-color: #f9f9f9;
  border-radius: 0.25rem;
}

.attack-results .placeholder-message {
  text-align: center;
  color: #888;
  padding: 2rem 1rem;
  margin: 0;
}

.no-results {
  text-align: center;
  color: #666;
  padding: 1.5rem 1rem;
  margin: 0;
}

/* Individual Result Item */
.attack-result-item {
  background-color: #fff;
  border: 1px solid #ddd;
  border-radius: 0.5rem;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.attack-result-item:last-child {
  margin-bottom: 0;
}

.result-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.result-number {
  font-weight: 600;
  color: #4a90d9;
  min-width: 2rem;
}

.result-positions {
  font-family: "Consolas", "Monaco", monospace;
  font-size: 1.1rem;
  font-weight: 600;
  color: #1a1a2e;
  background-color: #e7f3ff;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
}

.btn-apply-result {
  margin-left: auto;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  color: #28a745;
  background-color: transparent;
  border: 1px solid #28a745;
  border-radius: 0.25rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-apply-result:hover {
  background-color: #28a745;
  color: #fff;
}

.result-match-reason {
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.result-match-reason label {
  display: block;
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.25rem;
}

.match-reason-content {
  background-color: #f0f8ff;
  border: 1px solid #d0e8ff;
  border-radius: 0.25rem;
  padding: 0.5rem;
  font-size: 0.8rem;
  color: #333;
}

.match-pairs-list {
  margin: 0.25rem 0 0;
  padding-left: 1.25rem;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.75rem;
}

.match-pairs-list li {
  margin: 0.1rem 0;
}

.result-decrypted {
  font-size: 0.85rem;
}

.result-decrypted label {
  display: block;
  font-size: 0.8rem;
  color: #666;
  margin-bottom: 0.25rem;
}

.result-decrypted code {
  display: block;
  background-color: #1a1a2e;
  color: #e0e0e0;
  padding: 0.5rem;
  border-radius: 0.25rem;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.8rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Result Trace */
.result-trace {
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.result-trace summary {
  cursor: pointer;
  color: #4a90d9;
  font-weight: 500;
  padding: 0.25rem 0;
}

.result-trace summary:hover {
  text-decoration: underline;
}

.trace-log {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  background-color: #1a1a2e;
  color: #e0e0e0;
  border-radius: 0.25rem;
  font-family: "Consolas", "Monaco", monospace;
  font-size: 0.7rem;
  line-height: 1.3;
  overflow-x: auto;
  max-height: 300px;
  overflow-y: auto;
}

/* =================================
   13. Media Queries for Analysis (Tablet 600px+)
   ================================= */
@media (min-width: 600px) {
  .attack-scramblers {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
  }

  .scrambler-row {
    flex-direction: column;
  }

  .attack-results {
    max-height: 500px;
  }

  .grid-cipher-char {
    width: 1.3rem;
    font-size: 0.85rem;
  }

  input.grid-plain-input {
    width: 1.3rem;
    height: 1.3rem;
    min-width: 1.3rem;
    max-width: 1.3rem;
    font-size: 0.85rem;
  }
}

/* =================================
   14. Media Queries for Analysis (PC 900px+)
   ================================= */
@media (min-width: 900px) {
  .analysis-section {
    padding: 2rem;
  }

  .attack-results {
    max-height: 600px;
  }

  .result-header {
    flex-wrap: nowrap;
  }
}

/* =================================
   15. Drag-and-Drop Styles
   ================================= */

/* Drag Handle */
.drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  margin-right: 0.5rem;
  background: transparent;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
  cursor: grab;
  color: #888;
  font-size: 0.9rem;
  line-height: 1;
  vertical-align: middle;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: all 0.15s ease;
}

.drag-handle:hover {
  background-color: #f0f0f0;
  border-color: #4a90d9;
  color: #4a90d9;
}

.drag-handle:active,
.drag-handle.dragging {
  cursor: grabbing;
  background-color: #e0e8f0;
}

.drag-handle:focus {
  outline: 2px solid #4a90d9;
  outline-offset: 2px;
}

.drag-handle-icon {
  display: block;
  line-height: 1;
}

/* Dragging States */
.scrambler.dragging,
.attack-fieldset.dragging {
  opacity: 0.5;
  transform: scale(0.98);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 100;
  position: relative;
}

/* Drop Target */
.scrambler.drag-over,
.attack-fieldset.drag-over {
  border: 2px dashed #4a90d9 !important;
  background-color: #f0f8ff !important;
}

/* Container during drag */
.scramblers-container.drag-active,
.attack-scramblers.drag-active {
  min-height: 80px;
}

.scramblers-container.drag-active .scrambler:not(.dragging),
.attack-scramblers.drag-active .attack-fieldset:not(.dragging) {
  transition: transform 0.2s ease, border 0.15s ease, background-color 0.15s ease;
}

/* Ghost element during drag */
.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.85;
  transform: rotate(2deg);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  background: white;
  border-radius: 0.5rem;
}

/* Touch device adjustments */
@media (hover: none) and (pointer: coarse) {
  .drag-handle {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 1.1rem;
  }

  .scrambler.touch-active,
  .attack-fieldset.touch-active {
    transform: scale(1.02);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  }
}

/* Keyboard reordering focus state */
.scrambler.keyboard-focus,
.attack-fieldset.keyboard-focus {
  outline: 3px solid #4a90d9;
  outline-offset: 2px;
}

/* Tablet+ grid adjustments for drag handle */
@media (min-width: 600px) {
  .drag-handle {
    margin-right: 0.5rem;
  }
}
