/* ==========================================================================
   MegaNumbers CSS - Dark Modern Glassmorphism & Cyber Theme
   ========================================================================== */

:root {
  --bg-dark: #0b0f19;
  --bg-card: #151c2e;
  --bg-glass: rgba(26, 34, 56, 0.7);
  --border-glass: rgba(255, 255, 255, 0.1);
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent-cyan: #06b6d4;
  --accent-pink: #ec4899;
  --accent-amber: #f59e0b;
  --accent-green: #10b981;
  
  --text-main: #f8fafc;
  --text-sub: #94a3b8;
  --text-muted: #64748b;
  
  --font-main: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
  --font-mono: 'Fira Code', monospace;
  
  --radius-lg: 20px;
  --radius-md: 12px;
  --radius-sm: 8px;
  
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);
  --shadow-card: 0 20px 40px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 10% 10%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 90% 80%, rgba(236, 72, 153, 0.12) 0px, transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.logo-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--accent-pink));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.logo-area h1 {
  font-size: 1.4rem;
  font-weight: 900;
  letter-spacing: -0.5px;
  background: linear-gradient(to right, #ffffff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.75rem;
  color: var(--text-sub);
  font-weight: 500;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  font-family: var(--font-main);
  font-weight: 600;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1.2rem;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-glass);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
  transform: translateY(-1px);
}

.btn-icon {
  padding: 0.6rem;
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
}
.btn-icon:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #4338ca);
  color: #fff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.4);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

.btn-large {
  padding: 1rem 2rem;
  font-size: 1.1rem;
  border-radius: var(--radius-md);
  font-weight: 700;
}

.btn-success {
  background: linear-gradient(135deg, var(--accent-green), #059669);
  color: #fff;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}
.btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-2px);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}
.btn-danger:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  transform: translateY(-2px);
}

.key-hint {
  font-size: 0.75rem;
  opacity: 0.7;
  font-weight: 400;
  margin-left: 4px;
}

/* Controls Panel */
.controls-panel {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 1rem;
  align-items: center;
  background: var(--bg-glass);
  padding: 1rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.control-group label {
  font-size: 0.75rem;
  color: var(--text-sub);
  font-weight: 600;
}

.custom-select {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-glass);
  color: var(--text-main);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
}
.custom-select:focus {
  border-color: var(--primary);
}

.radio-toggle {
  display: flex;
  background: rgba(15, 23, 42, 0.8);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
}

.radio-toggle input {
  display: none;
}

.radio-toggle label {
  flex: 1;
  text-align: center;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.2s ease;
  color: var(--text-sub);
}

.radio-toggle input:checked + label {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

/* Stats Card */
.stats-card {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  background: rgba(15, 23, 42, 0.6);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-glass);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 800;
  font-family: var(--font-mono);
}

.stat-value.streak {
  color: var(--accent-amber);
}

.stat-divider {
  width: 1px;
  height: 24px;
  background: var(--border-glass);
}

/* Card Section & 3D Flip */
.card-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.card-wrapper {
  width: 100%;
  height: 380px;
  perspective: 1200px;
}

.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  outline: none;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-glass);
  padding: 1.8rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

/* Front Face Styling */
.card-front {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.card-badge {
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.4);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-badge.success {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.4);
}

.card-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1;
}

.question-label {
  font-size: 0.9rem;
  color: var(--text-sub);
  margin-bottom: 0.8rem;
}

.question-main {
  font-size: 3rem;
  font-weight: 900;
  font-family: var(--font-mono);
  background: linear-gradient(135deg, #ffffff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.2;
  word-break: break-word;
}

.question-sub {
  font-size: 1.1rem;
  color: var(--accent-cyan);
  margin-top: 0.5rem;
  font-weight: 600;
}

.card-footer-prompt {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Back Face Styling */
.card-back {
  background: linear-gradient(135deg, rgba(17, 24, 39, 0.95), rgba(30, 27, 75, 0.95));
  transform: rotateY(180deg);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.back-body {
  justify-content: flex-start;
  gap: 1rem;
  padding-top: 0.5rem;
}

.primary-answer-box {
  background: rgba(255, 255, 255, 0.05);
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: relative;
}

.answer-tag {
  font-size: 0.65rem;
  color: var(--accent-green);
  font-weight: 700;
  text-transform: uppercase;
}

.primary-answer {
  font-size: 2.2rem;
  font-weight: 900;
  color: #fff;
  line-height: 1.2;
}

.primary-reading {
  font-size: 1rem;
  color: var(--text-sub);
  font-weight: 500;
}

.details-grid {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem 1rem;
  text-align: left;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.5rem 0.7rem;
  border-radius: var(--radius-sm);
}

.detail-label {
  font-size: 0.65rem;
  color: var(--text-muted);
}

.detail-value {
  font-size: 0.9rem;
  font-weight: 700;
  color: #e2e8f0;
}

.detail-value.mono {
  font-family: var(--font-mono);
  color: var(--accent-amber);
}

.badge-mbt {
  color: var(--accent-cyan);
  font-family: var(--font-mono);
  font-weight: 700;
}

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

.btn-speech {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 6px;
  transition: color 0.2s;
}
.btn-speech:hover {
  color: var(--accent-pink);
}

.number-breakdown {
  font-size: 0.8rem;
  color: var(--text-sub);
  background: rgba(99, 102, 241, 0.1);
  width: 100%;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px dashed rgba(99, 102, 241, 0.3);
}

/* Action Buttons Area */
.action-buttons {
  display: flex;
  justify-content: center;
  gap: 1rem;
  width: 100%;
}

.eval-buttons {
  display: flex;
  gap: 1rem;
  width: 100%;
  justify-content: center;
}

.hidden {
  display: none !important;
}

/* Modal Window */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.modal-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 1.2rem;
  cursor: pointer;
}
.btn-close:hover {
  color: #fff;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.tip-banner {
  background: rgba(6, 182, 212, 0.1);
  border-left: 4px solid var(--accent-cyan);
  padding: 0.8rem 1rem;
  border-radius: 4px;
  font-size: 0.85rem;
  color: #c7d2fe;
  line-height: 1.5;
}

.table-scroll {
  overflow-x: auto;
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.ref-table th, .ref-table td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ref-table th {
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-sub);
  font-weight: 600;
}

.ref-table tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

.highlight-row {
  background: rgba(99, 102, 241, 0.1);
}

.tag-unit {
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.8rem;
}
.tag-m { background: rgba(236, 72, 153, 0.2); color: #f472b6; }
.tag-b { background: rgba(6, 182, 212, 0.2); color: #67e8f9; }
.tag-t { background: rgba(245, 158, 11, 0.2); color: #fde047; }

/* Responsive adjustments */
@media (max-width: 680px) {
  .controls-panel {
    grid-template-columns: 1fr;
  }
  .question-main {
    font-size: 2.2rem;
  }
  .card-wrapper {
    height: 420px;
  }
  .details-grid {
    grid-template-columns: 1fr;
  }
}

/* PWA & Touch Screen Adjustments */
@media (max-width: 680px) {
  body {
    padding: 1rem 0.75rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
  
  .key-hint {
    display: none; /* Hide PC keyboard shortcut hints on mobile */
  }

  .card-footer-prompt span {
    font-size: 0.8rem;
  }
}
