/* ============================================
   TradingCalc - Input🀄Edge Brand Styles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@900&display=swap');

:root {
  /* Brand Colors */
  --mahjong-red: #C00000;
  --dark-red: #9A0A25;
  --mahjong-gold: #F7D284;
  --ivory: #F3EDE2;
  --dark-brown: #5C2F1B;
  --light-brown: #A68A72;
  --gray: #6B7280;
  --light-gray: #E5E7EB;

  /* Light Theme */
  --bg-color: #F9F5F0;
  --text-color: var(--dark-brown);
  --primary-color: var(--mahjong-red);
  --secondary-color: var(--light-gray);
  --accent-color: var(--mahjong-gold);
  --modal-bg: #FFFFFF;
  --input-bg: var(--ivory);
  --button-bg: var(--mahjong-red);
  --button-text: white;
  --border-color: var(--light-gray);
  --shadow-color: rgba(92, 47, 27, 0.1);

  /* Risk Colors */
  --risk-extreme: #DC2626;
  --risk-high: #EA580C;
  --risk-moderate: #F59E0B;
  --risk-low: #10B981;

  /* Gradient */
  --gradient-primary: linear-gradient(135deg, #C00000, #9A0A25);
}

[data-theme="dark"] {
  --bg-color: #1A1A1A;
  --text-color: #F3EDE2;
  --primary-color: var(--mahjong-red);
  --secondary-color: #3A3A3A;
  --accent-color: var(--mahjong-gold);
  --modal-bg: #2D2D2D;
  --input-bg: #3A3A3A;
  --button-bg: var(--mahjong-red);
  --button-text: white;
  --border-color: #4A4A4A;
  --shadow-color: rgba(0, 0, 0, 0.3);
  --risk-extreme: #ff6b6b;
  --risk-high: #ff8e8e;
  --risk-moderate: #f9ca24;
  --risk-low: #7bed9f;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  margin: 0;
  padding: 12px;
  transition: background-color 0.3s, color 0.3s;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Mobile-first scaling */
@media (min-width: 360px) {
  body {
    padding: 14px;
  }
}

@media (min-width: 480px) {
  body {
    padding: 16px;
  }
}

@media (min-width: 768px) {
  body {
    padding: 20px;
  }
}

@media (min-width: 1024px) {
  body {
    padding: 24px;
  }
}

/* Main Header */
.main-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--bg-color);
  border-bottom: 2px solid rgba(92, 47, 27, 0.15);
  padding: 10px 12px;
  width: 100%;
}

@media (min-width: 360px) {
  .main-header {
    padding: 12px 14px;
  }
}

@media (min-width: 480px) {
  .main-header {
    padding: 12px 16px;
  }
}

@media (min-width: 768px) {
  .main-header {
    padding: 15px 20px;
  }
}

[data-theme="dark"] .main-header {
  border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.header-container {
  max-width: 1400px;
  /* Wider for desktop nav */
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr auto;
  /* Logo - Actions on mobile */
  align-items: center;
  gap: 12px;
}

@media (min-width: 1024px) {
  .header-container {
    grid-template-columns: 1fr auto 1fr;
    /* Logo - Nav - Actions on desktop */
    gap: 20px;
  }
}

.logo-section {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.logo-icon {
  font-size: 24px;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-weight: 800;
  font-size: clamp(0.9rem, 2.5vw, 1.35rem);
  letter-spacing: -0.5px;
  color: var(--text-color);
  line-height: 1.1;
  display: flex;
  align-items: center;
}

.app-tag {
  font-size: clamp(0.55rem, 1.5vw, 0.8rem);
  opacity: 1;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--primary-color);
  margin-top: 2px;
}

/* Desktop Nav */
.desktop-nav {
  display: none;
  /* Hide by default, show on desktop */
}

@media (min-width: 1024px) {
  .desktop-nav {
    display: block;
  }
}

.nav-links {
  display: flex;
  list-style: none;
  gap: 28px;
  align-items: center;
  justify-content: center;
}

.nav-links a {
  text-decoration: none;
  color: var(--primary-color);
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: capitalize;
  opacity: 1;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.nav-links a:hover {
  opacity: 1;
  color: var(--dark-red);
}

.header-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

/* Menu Button (Hamburger) */
.menu-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.hamburger {
  width: 24px;
  height: 3px;
  background: var(--primary-color);
  position: relative;
  transition: all 0.3s;
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  width: 24px;
  height: 3px;
  background: var(--primary-color);
  left: 0;
  transition: all 0.3s;
}

.hamburger::before {
  top: -7px;
}

.hamburger::after {
  bottom: -7px;
}

/* Side Drawer */
.side-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(300px, 80vw);
  height: 100%;
  background: var(--modal-bg);
  z-index: 2000;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.2);
  transition: right 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  padding: clamp(14px, 4vw, 20px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateX(100%);
}

.side-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 30px;
}

.close-drawer {
  background: none;
  border: none;
  font-size: 32px;
  color: var(--text-color);
  cursor: pointer;
  line-height: 1;
}

.drawer-section {
  margin-bottom: 30px;
}

.drawer-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--primary-color);
  margin-bottom: 15px;
  font-weight: 800;
}

.drawer-links {
  list-style: none;
}

.drawer-links li {
  margin-bottom: 12px;
}

.drawer-links a {
  text-decoration: none;
  color: var(--text-color);
  font-size: 1.05rem;
  font-weight: 600;
  transition: color 0.2s;
}

.drawer-links a:hover {
  color: var(--primary-color);
}

.social {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drawer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.theme-toggle-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Overlay */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1500;
  display: none;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
}

.overlay.show {
  display: block;
  opacity: 1;
  pointer-events: auto;
}

/* Calculator */
.calculator {
  width: 100%;
  max-width: 500px;
  margin: clamp(20px, 5vh, 40px) auto;
  background: var(--modal-bg);
  padding: clamp(14px, 4vw, 20px);
  border-radius: 12px;
  box-shadow: 0 4px 16px var(--shadow-color);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.calculator:hover {
  box-shadow: 0 8px 24px rgba(192, 0, 0, 0.15);
}

.calculator-watermark {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 240px;
  opacity: 0.03;
  z-index: 0;
  pointer-events: none;
  font-weight: bold;
  transform: rotate(-15deg);
  user-select: none;
  color: var(--primary-color);
  animation: subtlePulse 5s infinite ease-in-out;
}

.calculator-content {
  position: relative;
  z-index: 1;
}

.calculator-title {
  font-family: 'Montserrat', 'Segoe UI', 'Arial Black', 'Arial', sans-serif;
  font-weight: 450;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: clamp(1.05rem, 3vw, 1.4rem);
  color: var(--primary-color);
  text-align: center;
  margin-bottom: clamp(18px, 4vw, 32px);
  line-height: 1.1;
}

@keyframes subtlePulse {
  0% {
    opacity: 0.03;
    transform: rotate(-15deg) scale(1);
  }

  50% {
    opacity: 0.06;
    transform: rotate(-15deg) scale(1.02);
  }

  100% {
    opacity: 0.03;
    transform: rotate(-15deg) scale(1);
  }
}

h1 {
  text-align: center;
  color: var(--primary-color);
  margin-bottom: clamp(14px, 3vw, 20px);
  font-size: clamp(1.25rem, 5vw, 24px);
  font-weight: 700;
}

/* Input Rows */
.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2vw, 12px);
  margin-bottom: clamp(10px, 2vw, 15px);
}

.input-group {
  flex: 1;
}

.input-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
  color: var(--text-color);
  font-size: clamp(0.8rem, 2vw, 0.95rem);
}

.input-group input,
.input-group select {
  width: 100%;
  padding: clamp(8px, 1.5vw, 10px);
  border: 2px solid var(--border-color);
  border-radius: 6px;
  box-sizing: border-box;
  background-color: var(--input-bg);
  color: var(--text-color);
  transition: all 0.3s ease;
  font-size: clamp(0.8rem, 2vw, 0.95rem);
}

.input-group input:focus,
.input-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(192, 0, 0, 0.1);
}

.input-group input:hover,
.input-group select:hover {
  border-color: var(--accent-color);
}

/* Dropdown */
.dropdown {
  position: relative;
  width: 100%;
}

.dropdown-input {
  width: 100%;
  padding: 10px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--input-bg);
  color: var(--text-color);
  font-size: 14px;
  box-sizing: border-box;
  transition: all 0.3s ease;
}

.dropdown-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(192, 0, 0, 0.1);
}

.dropdown-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--input-bg);
  border: 2px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 6px 6px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 12px var(--shadow-color);
}

.dropdown-header {
  padding: 8px 10px;
  background-color: var(--secondary-color);
  color: var(--primary-color);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  border-bottom: 1px solid var(--border-color);
  user-select: none;
  pointer-events: none;
}

.dropdown-item {
  padding: 10px 14px;
  cursor: pointer;
  color: var(--text-color);
  transition: all 0.2s ease;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

[data-theme="dark"] .dropdown-item {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.item-symbol {
  font-weight: 800;
  font-size: 15px;
  color: var(--primary-color);
}

.item-fullname {
  font-size: 11px;
  opacity: 0.8;
  font-weight: 500;
}

.dropdown-item:hover {
  background-color: var(--primary-color);
  color: white;
}

.dropdown.open .dropdown-list {
  display: block;
}

/* Price Section */
.price-section {
  margin: clamp(14px, 3vw, 20px) 0;
}

.price-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  margin-bottom: clamp(10px, 2vw, 15px);
  gap: clamp(8px, 2vw, 12px);
}

.price-row span {
  width: auto;
  font-weight: bold;
  color: var(--text-color);
  white-space: nowrap;
  font-size: clamp(0.75rem, 1.8vw, 0.9rem);
}

.price-row input {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border-color);
  border-radius: 6px;
  background-color: var(--input-bg);
  color: var(--text-color);
  transition: all 0.3s ease;
}

.input-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  gap: clamp(6px, 1.5vw, 10px);
  width: 100%;
  min-width: 0;
}

.input-wrapper input {
  flex: 1;
  min-width: clamp(70px, 30%, 120px);
  /* Prevent being squeezed too small */
}

/* Refresh Button - Text Style */
.refresh-btn {
  background-color: var(--mahjong-gold);
  color: var(--dark-brown);
  border: none;
  border-radius: 8px;
  padding: clamp(8px, 2vw, 12px);
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
  font-size: clamp(0.75rem, 1.8vw, 0.95rem);
  border: 2px solid transparent;
  flex-shrink: 0;
}

.refresh-btn:hover {
  background-color: #eac575;
  transform: translateY(-1px);
}

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

.refresh-btn:disabled {
  opacity: 0.7;
  cursor: wait;
}

.price-row input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(192, 0, 0, 0.1);
}

.trade-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: clamp(10px, 2vw, 15px);
  gap: clamp(8px, 2vw, 10px);
}

.trade-col {
  flex: 1;
}

.trade-col span {
  display: block;
  margin-bottom: 5px;
  font-size: clamp(0.75rem, 1.8vw, 0.9rem);
  font-weight: bold;
  color: var(--text-color);
}

.trade-col input {
  width: 100%;
  padding: clamp(8px, 1.5vw, 10px);
  border: 2px solid var(--border-color);
  border-radius: 6px;
  box-sizing: border-box;
  background-color: var(--input-bg);
  color: var(--text-color);
  transition: all 0.3s ease;
}

.trade-col input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(192, 0, 0, 0.1);
}

/* Buttons */
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2vw, 10px);
  margin-top: clamp(14px, 3vw, 20px);
}

.button-row button {
  flex: 1;
  padding: clamp(10px, 2.5vw, 12px);
  border: none;
  border-radius: 8px;
  font-size: clamp(0.8rem, 2vw, 0.95rem);
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
  position: relative;
  overflow: hidden;
}

.button-row button::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.button-row button:hover::before {
  width: 300px;
  height: 300px;
}

#reset-btn {
  background-color: var(--secondary-color);
  color: var(--text-color);
}

#reset-btn:hover {
  background-color: #d1d5db;
}

#about-btn {
  background-color: var(--light-brown);
  color: white;
}

#about-btn:hover {
  background-color: #8B6F5A;
}

#calculate-btn {
  background: var(--gradient-primary);
  color: var(--button-text);
  box-shadow: 0 4px 12px rgba(192, 0, 0, 0.3);
}

#calculate-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(192, 0, 0, 0.4);
}

#calculate-btn:active {
  transform: translateY(0);
}

@keyframes errorPulse {
  0% {
    box-shadow: 0 0 0 0px rgba(220, 38, 38, 0.4);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
  }

  100% {
    box-shadow: 0 0 0 0px rgba(220, 38, 38, 0);
  }
}

/* Leverage Suggestion Styles */
/* Suggested Output Labels (Manual override) */
.suggested-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--mahjong-gold);
  margin-right: 4px;
  opacity: 0.9;
}

.suggested-value {
  color: var(--text-color);
  font-weight: 700;
}

/* Refined Static Dual-Mode Layout */
.grid-item.dual-mode-row {
  grid-column: 1 / -1;
  background: rgba(0, 0, 0, 0.03);
  padding: 12px;
  border-radius: 8px;
  border: 1px dashed var(--divider-color);
  margin-top: 4px;
}

.dual-header-grid {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--divider-color);
  padding-bottom: 4px;
}

.dual-header-grid .grid-label {
  opacity: 0.8;
  font-size: 0.75rem;
}

.dual-mode-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
}

.dual-mode-line:last-child {
  margin-bottom: 0;
}

.dual-mode-line i {
  font-style: italic;
  font-size: 12px;
  color: var(--text-color);
  opacity: 0.6;
  white-space: nowrap;
}

.dual-mode-value {
  font-weight: 700;
  color: var(--text-color);
  margin-left: 8px;
  white-space: nowrap;
}

.dual-leader {
  flex-grow: 1;
  height: 1px;
  border-bottom: 1px dotted var(--divider-color);
  margin: 0 10px;
  align-self: flex-end;
  margin-bottom: 4px;
  opacity: 0.5;
}

.dual-mode-margin {
  font-weight: 800;
  color: var(--text-color);
  white-space: nowrap;
}

/* Stable Capture State (Force stability for mobile rendering) */
.results-card.capturing {
  opacity: 1 !important;
  transform: none !important;
  display: block !important;
  background: var(--modal-bg) !important;
  border: 4px solid var(--primary-color) !important;
  box-shadow: none !important;
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  z-index: 100;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal-content {
  background-color: var(--modal-bg);
  margin: clamp(8%, 10vh, 12%) auto;
  padding: clamp(1.2rem, 3vw, 2.5rem);
  border-radius: 16px;
  width: min(95%, 500px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  /* transition: background-color 0.3s; */
  position: relative;
  animation: slideUp 0.4s ease;
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-content h2 {
  color: var(--mahjong-red);
  margin-bottom: 2rem;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.about-content p {
  line-height: 1.6;
  margin-bottom: 1.2rem;
  font-size: 0.95rem;
  text-align: justify;
}

.about-contact-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1.5px solid var(--border-color);
}

.about-contact-section h3 {
  color: var(--mahjong-red);
  margin-bottom: 1rem;
}

.about-contact-section p {
  text-align: left;
  margin-bottom: 1rem;
}

.contact-links {
  margin: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  text-decoration: none;
  color: var(--text-color);
  font-weight: 700;
  transition: all 0.2s ease;
  font-size: 0.95rem;
}

.contact-item:hover {
  color: var(--mahjong-gold);
}

.contact-item b {
  color: var(--mahjong-red);
  min-width: 80px;
  display: inline-block;
}

.version-text {
  display: block;
  margin-top: 5px;
  font-size: 10px;
  opacity: 0.6;
}

.about-footer {
  margin-top: 3rem;
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.6;
  font-weight: 700;
  border-top: 1px solid var(--border-color);
  padding-top: 1.5rem;
  letter-spacing: 0.5px;
}

.close {
  color: var(--text-color);
  opacity: 0.5;
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.3s ease;
  line-height: 1;
}

.close:hover {
  color: var(--primary-color);
  opacity: 1;
  transform: rotate(90deg);
}

/* === New Results Layout === */

/* === New Results Layout (Detailed) === */

.modal-header-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(3px, 1vw, 5px);
  margin-bottom: clamp(16px, 4vw, 25px);
}

.direction-tag {
  background-color: var(--primary-color);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.modal-header-section h2 {
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  margin: clamp(3px, 1vw, 5px) 0;
  color: var(--text-color);
  font-weight: 800;
  line-height: 1;
}

.asset-class-label {
  font-size: 1rem;
  color: var(--gray);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
}

.results-hero {
  text-align: center;
  margin-bottom: clamp(16px, 4vw, 25px);
  padding: clamp(14px, 3vw, 20px);
  background: var(--input-bg);
  border-radius: 12px;
  border: 2px solid var(--mahjong-gold);
  position: relative;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.hero-label {
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-color);
  opacity: 0.7;
  margin-bottom: 5px;
  font-weight: 600;
}

.hero-value {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 800;
  color: var(--primary-color);
  line-height: 1;
  margin: clamp(6px, 2vw, 10px) 0;
  text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
}

.full-width-grid-item {
  grid-column: 1 / -1;
  border-top: 1px dashed var(--border-color);
  margin-top: 5px;
  padding-top: 5px;
}

.hero-notional {
  font-size: 0.75rem;
  color: var(--gray);
  background: rgba(0, 0, 0, 0.05);
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  margin: 2px;
}

/* Split Table (Max Efficiency Refined) */
.split-table {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.split-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  align-items: center;
}

.table-header {
  border-bottom: 2px solid var(--border-color);
  padding-top: 0;
  padding-bottom: 8px;
  margin-bottom: 8px;
  font-weight: 800;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  color: var(--text-color);
}

.split-col {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.tiny-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gray);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  opacity: 0.8;
}

.tiny-value {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-color);
}

.danger-text {
  color: var(--risk-extreme);
}

.success-text {
  color: var(--risk-low);
}

.comment-box {
  padding: 10px;
  background-color: var(--secondary-color);
  border-radius: 8px;
  border-left: 4px solid var(--accent-color);
  margin-top: 15px;
  text-align: center;
  font-weight: bold;
  font-size: 0.85rem;
}

.about-content {
  line-height: 1.6;
  margin-bottom: 20px;
}

.about-content p {
  margin-bottom: 15px;
}

.about-content ul {
  margin-left: 20px;
  margin-bottom: 15px;
}

.about-content li {
  margin-bottom: 8px;
}

.notice {
  font-style: italic;
  padding: 10px;
  background-color: rgba(247, 210, 132, 0.15);
  border-left: 4px solid var(--accent-color);
  margin-top: 15px;
  border-radius: 4px;
}

/* Risk Levels */
.risk-extreme {
  color: var(--risk-extreme);
  background-color: rgba(220, 38, 38, 0.1);
  border-left-color: var(--risk-extreme);
}

.risk-high {
  color: var(--risk-high);
  background-color: rgba(234, 88, 12, 0.1);
  border-left-color: var(--risk-high);
}

.risk-moderate {
  color: var(--risk-moderate);
  background-color: rgba(245, 158, 11, 0.1);
  border-left-color: var(--risk-moderate);
}

.risk-low {
  color: var(--risk-low);
  background-color: rgba(16, 185, 129, 0.1);
  border-left-color: var(--risk-low);
}

/* Responsive */
@media (max-width: 480px) {
  .input-row {
    flex-direction: column;
    gap: 10px;
  }

  .trade-row {
    flex-direction: column;
    gap: 10px;
  }

  .modal-content {
    margin: 10% auto;
    width: 95%;
  }

  .calculator-watermark {
    font-size: 180px;
  }
}

/* ====== COMPREHENSIVE RESPONSIVE BREAKPOINTS ====== */

/* Extra Small Devices (320px - 359px) - iPhone SE, Small Android */
@media (max-width: 359px) {
  html {
    font-size: 14px;
  }

  .menu-btn {
    width: 36px;
    height: 36px;
  }

  .hamburger {
    width: 20px;
  }

  .hamburger::before,
  .hamburger::after {
    width: 20px;
  }

  .calculator {
    max-width: calc(100vw - 24px);
  }

  .modal-content {
    max-width: calc(100vw - 20px);
  }

  .close {
    top: 1rem;
    right: 1rem;
    font-size: 24px;
  }
}

/* Small Devices (360px - 479px) - Most Android, iPhone 5, SE */
@media (min-width: 360px) and (max-width: 479px) {
  .dropdown-list {
    max-height: 160px;
  }

  .split-col {
    gap: clamp(4px, 1vw, 6px);
  }

  .tiny-label {
    font-size: clamp(0.6rem, 1.3vw, 0.7rem);
  }

  .tiny-value {
    font-size: clamp(0.8rem, 1.8vw, 0.95rem);
  }
}

/* Medium Devices (480px - 599px) - iPhone XR, Standard phones */
@media (min-width: 480px) and (max-width: 599px) {
  body {
    padding: 16px;
  }

  .calculator {
    padding: 16px;
  }

  .input-row {
    gap: 12px;
  }
}

/* Standard Tablets (600px - 767px) - iPad Mini */
@media (min-width: 600px) and (max-width: 767px) {
  .header-container {
    gap: 16px;
  }

  .calculator {
    max-width: 550px;
  }

  .info-section {
    padding: 24px;
  }
}

/* Tablet Landscape (768px - 1023px) - iPad, Tab S7 */
@media (min-width: 768px) and (max-width: 1023px) {
  html {
    font-size: 17px;
  }

  .calculator {
    max-width: 600px;
  }

  .info-container {
    max-width: 100%;
  }
}

/* Desktop Small (1024px - 1279px) - Small laptops */
@media (min-width: 1024px) and (max-width: 1279px) {
  .calculator {
    max-width: 520px;
  }
}

/* Desktop Standard (1280px - 1439px) - Standard desktops */
@media (min-width: 1280px) and (max-width: 1439px) {
  body {
    padding: 24px;
  }

  .calculator {
    max-width: 540px;
  }
}

/* Desktop Large (1440px - 1919px) - Large monitors */
@media (min-width: 1440px) and (max-width: 1919px) {
  body {
    padding: 32px;
  }

  .calculator {
    max-width: 560px;
  }
}

/* Ultra Wide (2560px+) - 4K displays */
@media (min-width: 2560px) {
  html {
    font-size: 18px;
  }

  body {
    padding: 40px;
  }

  .calculator {
    max-width: 600px;
    margin: 60px auto;
  }

  .info-container {
    max-width: 1200px;
  }
}

/* Landscape Mode Adjustments */
@media (max-height: 500px) and (orientation: landscape) {
  .main-header {
    padding: 8px 12px;
  }

  h1 {
    margin-bottom: 8px;
  }

  .calculator {
    margin: 12px auto;
  }
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--ivory);
}

::-webkit-scrollbar-thumb {
  background: var(--mahjong-gold);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--primary-color);
}

/* Luxury Minimalist Toast */
.toast {
  visibility: hidden;
  min-width: 320px;
  background: var(--bg-color);
  /* Matches theme */
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  /* Sharp professional corners */
  padding: 0;
  position: fixed;
  z-index: 2000;
  left: 50%;
  top: 30px;
  transform: translateX(-50%) translateY(-20px);
  box-shadow: 0 10px 30px var(--shadow-color);
  opacity: 0;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.toast.show {
  visibility: visible;
  opacity: 1;
  top: 40px;
  transform: translateX(-50%) translateY(0);
  cursor: pointer;
}

.toast-content {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 20px;
  gap: 15px;
}

.toast-body {
  flex: 1;
}

.toast-title {
  font-weight: 800;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 4px;
  opacity: 0.8;
}

.toast-message {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-color);
  font-size: 20px;
  cursor: pointer;
  opacity: 0.3;
  transition: opacity 0.2s;
  line-height: 1;
  padding: 0;
}

.toast-close:hover {
  opacity: 1;
}

/* Progress Bar */
.toast-progress {
  height: 2px;
  width: 100%;
  background: rgba(0, 0, 0, 0.05);
}

.toast-progress-bar {
  height: 100%;
  width: 100%;
  background: var(--primary-color);
  transition: width linear;
}

/* Luxury Palette */
.toast-error {
  border-top: 3px solid var(--risk-extreme);
}

.toast-error .toast-title {
  color: var(--risk-extreme);
}

.toast-error .toast-progress-bar {
  background: var(--risk-extreme);
}

.toast-success {
  border-top: 3px solid var(--risk-low);
}

.toast-success .toast-title {
  color: var(--risk-low);
}

.toast-success .toast-progress-bar {
  background: var(--risk-low);
}

.toast-warning {
  border-top: 3px solid var(--risk-moderate);
}

.toast-warning .toast-title {
  color: var(--risk-moderate);
}

.toast-warning .toast-progress-bar {
  background: var(--risk-moderate);
}

/* Sticky Toast Enhancement */
.toast-sticky {
  border-left: 5px solid var(--accent-color);
  box-shadow: 0 15px 40px var(--shadow-color);
}

.toast-sticky .toast-progress {
  display: none !important;
}

.spinning {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

/* Educational Content Section Styling */
.info-container {
  max-width: 1000px;
  margin: clamp(20px, 5vh, 40px) auto;
  padding: 0 clamp(12px, 3vw, 20px);
}

.info-section {
  margin-bottom: clamp(24px, 5vw, 40px);
  background: var(--input-bg);
  padding: clamp(16px, 4vw, 30px);
  border-radius: 16px;
  border: 1px solid var(--border-color);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.info-section h2 {
  color: var(--mahjong-red);
  margin-bottom: clamp(16px, 3vw, 25px);
  font-size: clamp(1.3rem, 4vw, 1.8rem);
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}

.info-section h3 {
  color: var(--text-color);
  margin-top: clamp(16px, 3vw, 25px);
  margin-bottom: clamp(10px, 2vw, 15px);
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  font-weight: 800;
}

.info-list {
  list-style: none;
  padding: 0;
  margin: clamp(10px, 2vw, 15px) 0;
}

.info-list li {
  margin-bottom: clamp(10px, 2vw, 15px);
  padding-left: clamp(24px, 5vw, 28px);
  position: relative;
  line-height: 1.7;
  font-size: clamp(0.8rem, 2vw, 0.95rem);
}

.info-list li::before {
  content: "🀄";
  position: absolute;
  left: 0;
  top: 1px;
  font-size: clamp(12px, 2vw, 14px);
}

.math-block {
  background: rgba(0, 0, 0, 0.03);
  padding: clamp(14px, 3vw, 20px);
  border-radius: 10px;
  border-left: 5px solid var(--primary-color);
  margin: clamp(16px, 3vw, 25px) 0;
  font-family: inherit;
  font-weight: 800;
  font-size: clamp(0.9rem, 2.5vw, 1.2rem);
  text-align: center;
  color: var(--text-color);
  letter-spacing: 0.5px;
}

/* Info Table Styling */
.info-table-wrapper {
  overflow-x: auto;
  margin: clamp(16px, 3vw, 25px) 0;
  border-radius: 10px;
  border: 1.5px solid var(--border-color);
  background: var(--input-bg);
  -webkit-overflow-scrolling: touch;
}

.info-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: clamp(0.75rem, 1.8vw, 0.9rem);
  min-width: 500px;
}

.info-table th,
.info-table td {
  padding: clamp(10px, 2vw, 15px) clamp(12px, 2.5vw, 20px);
  border-bottom: 1.5px solid var(--border-color);
}

.info-table th {
  background: rgba(0, 0, 0, 0.05);
  color: var(--mahjong-gold);
  text-transform: uppercase;
  font-size: clamp(0.6rem, 1.2vw, 0.75rem);
  font-weight: 800;
  letter-spacing: 1.5px;
}

.info-table tr:last-child td {
  border-bottom: none;
}

.info-table tr:hover {
  background: rgba(0, 0, 0, 0.02);
}

@media (max-width: 768px) {
  .info-section {
    padding: 20px;
  }

  .info-section h2 {
    font-size: 1.5rem;
  }

  .math-block {
    font-size: 1rem;
    padding: 15px;
  }
}

/* Risk Type Toggle - Integrated into Input */
.input-with-action {
  display: flex;
  align-items: center;
  background-color: var(--input-bg);
  border: 2px solid var(--border-color);
  border-radius: 6px;
  transition: all 0.3s ease;
  overflow: hidden;
}

.input-with-action:focus-within {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(192, 0, 0, 0.1);
}

.input-with-action input {
  border: none !important;
  box-shadow: none !important;
  background: transparent !important;
  padding: 10px !important;
  flex: 1;
  min-width: 0;
}

.risk-type-toggle-mini {
  display: flex;
  background: var(--secondary-color);
  border-radius: 4px;
  padding: 2px;
  margin-right: 6px;
  border: 1px solid var(--border-color);
}

.risk-toggle-btn {
  padding: 2px 8px;
  border: none;
  background: transparent;
  color: var(--text-color);
  font-size: 11px;
  font-weight: bold;
  cursor: pointer;
  border-radius: 3px;
  transition: all 0.2s ease;
}

.risk-toggle-btn.active {
  background: var(--primary-color);
  color: white;
}

/* Refined Metrics Grid (Compact) */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2vw, 10px);
  margin-top: clamp(12px, 2vw, 15px);
  background: rgba(0, 0, 0, 0.05);
  padding: clamp(10px, 2vw, 12px);
  border-radius: 10px;
}

.grid-item {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: clamp(1px, 0.5vw, 2px);
  min-width: 0;
}

.grid-label {
  font-size: clamp(0.6rem, 1.5vw, 0.7rem);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.8;
  /* Increased from 0.6 for better visibility */
  font-weight: 700;
}

.grid-label small {
  display: block;
  font-style: italic;
  font-weight: 400;
  text-transform: none;
  opacity: 0.8;
  /* Increased to match parent label */
  font-size: clamp(0.65rem, 1.2vw, 0.75rem);
  margin-top: 2px;
}

.grid-value {
  font-size: clamp(0.75rem, 1.8vw, 0.85rem);
  font-weight: 800;
  color: var(--text-color);
  opacity: 1;
  /* Ensure full visibility */
  word-break: break-word;
}

.grid-value small {
  font-weight: 400;
  font-size: clamp(0.65rem, 1.2vw, 0.75rem);
  opacity: 1;
  /* Match parent visibility */
}

/* Modal Actions and Branding */
.modal-actions-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(8px, 2vw, 10px);
  margin-top: clamp(14px, 3vw, 20px);
  padding-top: clamp(10px, 2vw, 15px);
  border-top: 1px solid var(--border-color);
}

.action-btn {
  flex: 1;
  padding: clamp(7px, 1.5vw, 8px) clamp(10px, 2vw, 12px);
  border-radius: 8px;
  border: 1.5px solid var(--border-color);
  background: var(--input-bg);
  color: var(--text-color);
  font-size: clamp(0.7rem, 1.5vw, 0.8rem);
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(4px, 1vw, 6px);
}

.btn-icon {
  width: clamp(13px, 3vw, 16px);
  height: clamp(13px, 3vw, 16px);
  flex-shrink: 0;
}

.action-btn:hover {
  background: var(--secondary-color);
  border-color: var(--accent-color);
  transform: translateY(-2px);
}

.action-btn.download {
  background: var(--secondary-color);
}

.action-btn.share {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.action-btn.share:hover {
  filter: brightness(1.1);
}

.card-branding {
  margin-top: 15px;
  text-align: center;
  font-size: 12px;
  opacity: 1;
  /* Keep visible for trademark */
  color: var(--text-color);
  letter-spacing: 0.5px;
}

.card-branding strong {
  color: var(--primary-color);
}

/* Force two-column layout for paired inputs on all viewports and provide helpers */
.input-row > *,
.trade-row > *,
.button-row > *,
.price-row > * {
  min-width: 0; /* prevents overflowing content in grid items */
}

/* Helper to force an item to span both columns (use class="full" or "span-2" on the element) */
.input-row .full,
.input-row .span-2,
.instrument-row,
.instrument {
  grid-column: 1 / -1;
}

/* Ensure input/select elements fill their grid cell and do not cause wrapping */
.input-group input,
.input-group select,
.input-group textarea,
.trade-col input,
.price-row input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* Keep Price + Refresh aligned horizontally and keep refresh button from shrinking */
.price-row {
  align-items: center;
  grid-auto-flow: column;
}
.price-row .refresh-btn,
.price-row button {
  justify-self: end;
  flex-shrink: 0;
}

/* Ensure Reset and Calculate remain side-by-side and full width of each column */
.button-row {
  grid-auto-flow: column;
}
.button-row button {
  width: 100%;
}

/* Small tweak for very narrow devices to reduce gaps but keep layout intact */
@media (max-width: 320px) {
  .input-row,
  .trade-row,
  .button-row {
    gap: 6px;
  }
}