/**
 * Modal Dialog Styles
 * React-compatible styling for vanilla JS modals
 */

/* CSS Variables - Aligned with Remix Theme */
:root {
  --ht-modal-font: "Inter", "Noto Sans JP", ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --ht-modal-body: #1a1a1a;
  --ht-modal-background: #fff;
  --ht-modal-border: #e5e7eb;
  --ht-modal-danger: #B7282E;
}

/* Overlay */
.ht-modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1200;
  transition: opacity 0.4s ease-in-out;
}

/* Dialog Container */
.ht-modal-dialog {
  font-family: var(--ht-modal-font);
  background-color: var(--ht-modal-background);
  border: 1px solid var(--ht-modal-border);
  border-radius: 0.5rem;
  padding: 1.5rem;
  max-width: 28rem;
  width: 100%;
  position: relative;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Close Button */
.ht-modal-close {
  position: absolute;
  top: -0.75rem;
  right: -0.75rem;
  width: 2rem;
  height: 2rem;
  background-color: var(--ht-modal-body);
  color: var(--ht-modal-background);
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: background-color 0.2s;
  z-index: 10;
}

.ht-modal-close:hover {
  opacity: 0.9;
}

.ht-modal-close:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Title */
.ht-modal-title {
  font-family: var(--ht-modal-font);
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 2rem;
  text-align: center;
  color: var(--ht-modal-body);
  line-height: 1.75rem;
}

.ht-modal-title-error {
  color: var(--ht-modal-danger);
}

/* Message */
.ht-modal-message {
  color: rgba(26, 26, 26, 0.8);
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
  line-height: 1.5;
  text-align: center;
}

/* Buttons Container */
.ht-modal-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

/* Button Base */
.ht-modal-btn {
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  font-size: 0.875rem;
  border: none;
}

.ht-modal-btn:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.ht-modal-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Cancel Button */
.ht-modal-btn-cancel {
  background-color: transparent;
  color: #1a1a1a;
  border: 1px solid #e5e7eb;
}

.ht-modal-btn-cancel:hover:not(:disabled) {
  background-color: rgba(26, 26, 26, 0.1);
}

/* Confirm Button - Default */
.ht-modal-btn-confirm {
  background-color: var(--ht-modal-body);
  color: var(--ht-modal-background);
}

.ht-modal-btn-confirm:hover:not(:disabled) {
  opacity: 0.9;
}

/* Confirm Button - Danger Variant */
.ht-modal-btn-danger {
  background-color: var(--ht-modal-danger);
  color: var(--ht-modal-background);
}

.ht-modal-btn-danger:hover:not(:disabled) {
  opacity: 0.9;
}

/* Dark Mode Support (if needed in future) */
@media (prefers-color-scheme: dark) {
  .ht-modal-overlay {
    background-color: rgba(0, 0, 0, 0.5);
  }

  .ht-modal-dialog {
    background-color: #1a1a1a;
    border-color: #404040;
    color: #fff;
  }

  .ht-modal-title {
    color: #fff;
  }

  .ht-modal-message {
    color: rgba(255, 255, 255, 0.8);
  }

  .ht-modal-close {
    background-color: #fff;
    color: #1a1a1a;
  }

  .ht-modal-close:hover {
    background-color: rgba(255, 255, 255, 0.9);
  }

  .ht-modal-btn-cancel {
    color: #fff;
    border-color: #404040;
  }

  .ht-modal-btn-cancel:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.1);
  }

  .ht-modal-btn-confirm {
    background-color: #fff;
    color: #1a1a1a;
  }

  .ht-modal-btn-confirm:hover:not(:disabled) {
    background-color: rgba(255, 255, 255, 0.9);
  }
}

/* Responsive */
@media (max-width: 640px) {
  .ht-modal-dialog {
    padding: 1.25rem;
    max-width: calc(100vw - 2rem);
  }

  .ht-modal-title {
    font-size: 1.125rem;
    margin-bottom: 1.5rem;
  }

  .ht-modal-buttons {
    flex-direction: column-reverse;
  }

  .ht-modal-btn {
    width: 100%;
  }
}

/* Tutorial Modal (How to Use) Styles */
#tutorial-modal .ht-modal-dialog {
  max-width: 45rem;
  max-height: 85vh;
}

#tutorial-modal .ht-modal-title {
  font-size: 1.3rem;
  margin: 0;
  padding: 0 0 1.5rem 0;
  text-align: center;
  justify-content: center;
}

#tutorial-modal .ht-modal-content {
  overflow-y: auto;
  max-height: calc(85vh - 150px);
  padding: 2.5rem 3rem 2.5rem 2.5rem;
  margin-right: -1.5rem;
}

#tutorial-modal h2 {
  font-size: 1rem;
  margin-top: 1.5rem;
  margin-bottom: 1rem;
  color: #1a1a1a;
}

#tutorial-modal h3 {
  font-size: 1rem;
  margin-top: 1.25rem;
  margin-bottom: 0.75rem;
  color: #1a1a1a;
}

#tutorial-modal h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
  color: #1a1a1a;
}

#tutorial-modal p {
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 0.75rem;
  color: rgba(26, 26, 26, 0.8);
}

#tutorial-modal ul {
  list-style: none;
  padding-left: 0;
  margin-bottom: 1rem;
}

#tutorial-modal ul li {
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 0.5rem;
  padding-left: 1.25rem;
  position: relative;
  color: rgba(26, 26, 26, 0.8);
}

#tutorial-modal ul li::before {
  content: "-";
  position: absolute;
  left: 0.5rem;
  color: #B7282E;
  font-weight: bold;
}

#tutorial-modal a {
  color: #B7282E;
  text-decoration: underline;
  font-weight: 500;
}

#tutorial-modal a:hover {
  opacity: 0.8;
}

#tutorial-modal .tutorial-footer {
  border-top: 1px solid #e5e7eb;
  padding-top: 1rem;
  margin-top: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

#tutorial-modal .tutorial-dont-show {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.875rem;
}

#tutorial-modal .tutorial-dont-show--floating {
  position: absolute;
  top: 3rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 0.75rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  z-index: 5;
}

#tutorial-modal .tutorial-dont-show--floating label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  color: #1a1a1a;
  font-size: 0.75rem;
}

#tutorial-modal .tutorial-dont-show--floating small {
  font-size: 0.75rem;
  color: rgba(26, 26, 26, 0.6);
}

@media (max-width: 640px) {
  #tutorial-modal .tutorial-dont-show--floating {
    position: static;
    background: transparent;
    box-shadow: none;
    padding: 0;
    margin-bottom: 1rem;
  }
}

#tutorial-modal .tutorial-dont-show input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

#tutorial-modal small {
  font-size: 0.75rem;
  color: rgba(26, 26, 26, 0.6);
}

/* Tutorial Modal Responsive */
@media (max-width: 640px) {
  #tutorial-modal .ht-modal-dialog {
    max-width: calc(100vw - 2rem);
    max-height: 90vh;
  }

  #tutorial-modal .ht-modal-title {
    font-size: 1.25rem;
  }

  #tutorial-modal h2 {
    font-size: 1.125rem;
  }

  #tutorial-modal h3 {
    font-size: 1rem;
  }

  #tutorial-modal p,
  #tutorial-modal ul li {
    font-size: 0.8125rem;
  }
}

/* Font/Icon Modal Styles */
#font-modal .ht-modal-dialog,
#icon-modal .ht-modal-dialog {
  max-height: 85vh;
}

#font-modal .ht-modal-title,
#icon-modal .ht-modal-title {
  font-size: 1.25rem;
  margin: 0;
  padding: 0 0 1.5rem 0;
  text-align: center;
  justify-content: center;
}

#font-modal .ht-modal-content,
#icon-modal .ht-modal-content {
    overflow-y: auto;
    max-height: calc(85vh - 150px);
    padding-right: 1rem;
    margin-right: -1.5rem;
}

/* Font Item Loading/Error States (Phase 3) */
.font-item.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.4;
}

/* Phase 4.1: 改善されたローディングスピナー */
.font-item.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid rgba(26, 26, 26, 0.1);
  border-top-color: var(--ht-modal-body);
  border-radius: 50%;
  animation: font-spinner 0.8s ease-in-out infinite;
}

@keyframes font-spinner {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

.font-item.error {
  background-color: rgba(183, 40, 46, 0.1);
  border-color: var(--ht-modal-danger);
  animation: font-error-shake 0.4s ease-in-out;
}

@keyframes font-error-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Dark Mode for Loading States */
@media (prefers-color-scheme: dark) {
  .font-item.loading::after {
    border-top-color: #fff;
  }

  .font-item.error {
    background-color: rgba(183, 40, 46, 0.2);
  }
}

/* Font/Icon Modal Responsive */
@media (max-width: 640px) {
  #font-modal .ht-modal-dialog,
  #icon-modal .ht-modal-dialog {
    max-width: calc(100vw - 2rem);
    max-height: 90vh;
  }

  #font-modal .ht-modal-title,
  #icon-modal .ht-modal-title {
    font-size: 1.125rem;
  }
}

/* モバイル表示用（768px以下） */
@media screen and (max-width: 768px) {
  #tutorial-modal .ht-modal-content {
    padding: 0rem 2rem 5rem 1rem;
    margin-right: -1rem;
  }
}
