/**
 * @file style.css
 * Stylesheet for the FGO Damage Calculator.
 * Utilizes a Discord-inspired dark theme color palette and flexbox layout architecture.
 */

/* ==========================================================================
   Base Layout & Typography
   ========================================================================== */
body,
html {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family:
    "gg sans", "Noto Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background-color: #313338;
  color: #dbdee1;
  overflow: hidden;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%; /* Fallback for older browsers */
  height: 100dvh; /* Dynamic height that respects mobile navigation bars */
}

/* ==========================================================================
   Application Header
   ========================================================================== */
.chat-header {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  border-bottom: 1px solid #1e1f22;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  background-color: #313338;
  z-index: 10;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 12px 16px;
  box-sizing: border-box;
}

.channel-title {
  font-size: 1rem;
  font-weight: 600;
  color: #f2f3f5;
  display: flex;
  align-items: center;
}

.hash-icon {
  color: #80848e;
  font-size: 1.4rem;
  margin-right: 6px;
  font-weight: 300;
}

.discord-action-icon {
  color: #b5bac1;
  cursor: pointer;
  transition: color 0.15s ease;
}

.discord-action-icon:hover {
  color: #dbdee1;
}

/* ==========================================================================
   Chat Container & Message Rendering
   ========================================================================== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0;
}

.message {
  display: flex;
  padding: 4px 16px 4px 72px;
  margin: 17px auto 0 auto;
  position: relative;
  max-width: 800px;
  width: 100%;
  box-sizing: border-box;
}

.message:hover {
  background-color: #2e3035;
}

.message .avatar {
  position: absolute;
  left: 16px;
  top: 4px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: transparent;
  cursor: pointer;
}

.animate-message {
  animation: messageSlideIn 0.3s ease-out forwards;
}

@keyframes messageSlideIn {
  0% {
    opacity: 0;
    transform: translateY(15px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-content {
  flex: 1;
  min-width: 0;
}

.msg-header {
  display: flex;
  align-items: baseline;
  margin-bottom: 4px;
}

.username {
  font-weight: 500;
  color: #f2f3f5;
  font-size: 1rem;
  margin-right: 4px;
}

.bot-tag {
  background-color: #5865f2;
  color: #ffffff;
  font-size: 0.65rem;
  font-weight: bold;
  padding: 2px 4px;
  border-radius: 3px;
  margin-right: 8px;
  vertical-align: middle;
}

.timestamp {
  font-size: 0.75rem;
  color: #949ba4;
}

.msg-text {
  font-size: 1rem;
  line-height: 1.375rem;
  color: #dbdee1;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ==========================================================================
   Calculation Embeds
   ========================================================================== */
.embed {
  background-color: #2b2d31;
  border-left: 4px solid #5865f2;
  border-radius: 4px;
  padding: 12px 16px;
  margin-top: 8px;
  max-width: 520px;
}

.embed-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
}

.embed-title {
  font-weight: 600;
  color: #f2f3f5;
  font-size: 1rem;
}

.embed-thumbnail {
  max-width: 80px;
  max-height: 80px;
  border-radius: 4px;
  margin-left: 16px;
  object-fit: cover;
}

.field {
  margin-bottom: 8px;
}

.field-name {
  font-weight: 600;
  color: #f2f3f5;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.field-value {
  font-size: 0.85rem;
  color: #dbdee1;
}

/* ==========================================================================
   Interactive Buttons
   ========================================================================== */
.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn {
  background-color: #4e5058;
  color: #dbdee1;
  border: none;
  border-radius: 4px;
  padding: 6px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn:hover:not(:disabled) {
  background-color: #6d6f78;
}

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

.copy-btn {
  position: absolute;
  right: 16px;
  top: 16px;
  background-color: #2b2d31;
  border: 1px solid #1e1f22;
  color: #dbdee1;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  transition: background-color 0.2s;
  opacity: 0;
}

.message:hover .copy-btn {
  opacity: 1;
}

.copy-btn:hover {
  background-color: #3f4147;
}

/* ==========================================================================
   User Input Area
   ========================================================================== */
.input-area {
  padding: 0 16px calc(24px + env(safe-area-inset-bottom)) 16px;
  background-color: #313338;
}

.input-wrapper {
  background-color: #383a40;
  border-radius: 8px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
}

#calcInput {
  flex: 1;
  background: transparent;
  border: none;
  color: #dbdee1;
  font-size: 1rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 50vh;
}

#calcInput::placeholder {
  color: #949ba4;
}

.send-btn {
    background: none;
    border: none;
    color: #b5bac1;
    cursor: pointer;
    padding: 6px;
    margin-left: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.send-btn:hover:not(:disabled) {
    color: #dbdee1;
    background-color: #4e5058;
}

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

/* ==========================================================================
   Help Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background-color: #313338;
  color: #dbdee1;
  padding: 24px;
  border-radius: 8px;
  width: 450px;
  max-width: 90%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #3f4147;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: #f2f3f5;
}

.close-btn {
  background: none;
  border: none;
  color: #949ba4;
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.close-btn:hover {
  color: #ed4245;
}

.modal-body ul {
  padding-left: 20px;
  line-height: 1.8;
  font-size: 0.9rem;
}

.modal-body code {
  background-color: #1e1f22;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: Consolas, monospace;
  color: #f2f3f5;
}

/* ==========================================================================
   Mobile Adjustments
   ========================================================================== */
@media (max-width: 600px) {
  /* Allow buttons to wrap to the next line */
  .btn-row {
    flex-wrap: wrap;
  }

  /* Make the embed take up the full width minus a little padding */
  .embed {
    max-width: 100%;
  }

  /* Reduce the avatar padding slightly to give text more room */
  .message {
    padding-left: 56px;
  }

  .message .avatar {
    width: 32px;
    height: 32px;
    left: 12px;
  }
}

/* --- CUSTOM CARD TOOLTIPS --- */
.tooltip-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.custom-tooltip {
    position: absolute;
    bottom: calc(100% + 8px); /* Position it slightly above the card icon */
    left: 50%;
    transform: translateX(-50%);
    background-color: #111214; /* Dark Discord UI color */
    color: #dbdee1;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    white-space: nowrap; /* Prevent text from awkwardly wrapping */
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    border: 1px solid #1e1f22;
    z-index: 100;
    
    /* Hide by default with a smooth fade */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    pointer-events: none; /* Prevents the tooltip itself from interfering with mouse hover */
}

/* The little triangle arrow pointing down */
.custom-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #111214 transparent transparent transparent;
}

/* Show the tooltip when hovering (desktop) or focusing/tapping (mobile) */
.tooltip-container:hover .custom-tooltip,
.tooltip-container:focus .custom-tooltip,
.tooltip-container:focus-within .custom-tooltip,
.tooltip-container:active .custom-tooltip {
    opacity: 1;
    visibility: visible;
}

.tooltip-row {
    display: flex;
    align-items: center;
    margin-bottom: 6px;
}

.tooltip-row:last-child {
    margin-bottom: 0;
}