/* ==========================================
   MDデッキリーダー — スタイルシート
   テーマ: 遊戯王ダーク系（濃紺/金/白）
   ========================================== */

:root {
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a2035;
  --bg-card-hover: #1e2540;
  --border-color: #2a3a5c;
  --accent-gold: #c9a227;
  --accent-gold-light: #e5c158;
  --accent-blue: #3b82f6;
  --text-primary: #e8eaf0;
  --text-secondary: #8b9ab5;
  --text-muted: #5a6a8a;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.7);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

/* ==========================================
   Reset & Base
   ========================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Segoe UI', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

a {
  color: var(--accent-gold-light);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--accent-gold);
  text-decoration: underline;
}

/* ==========================================
   Header
   ========================================== */

.site-header {
  background: linear-gradient(135deg, #0d1528 0%, #1a1f3a 50%, #0d1528 100%);
  border-bottom: 2px solid var(--accent-gold);
  padding: 1.5rem 1rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(201,162,39,0.12) 0%, transparent 70%);
  pointer-events: none;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.site-header h1 {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 800;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, var(--accent-gold-light), var(--accent-gold));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  margin-bottom: 0.3rem;
}

.header-sub {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ==========================================
   Main Layout
   ========================================== */

.main-content {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 2rem auto;
  padding: 0 1rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.card h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-gold-light);
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

/* ==========================================
   Drop Zone
   ========================================== */

.drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: rgba(255,255,255,0.02);
  position: relative;
}

.drop-zone:hover,
.drop-zone.hover {
  border-color: var(--accent-gold);
  background: rgba(201,162,39,0.06);
  box-shadow: 0 0 20px rgba(201,162,39,0.15);
}

.drop-zone.dragover {
  border-color: var(--accent-gold-light);
  background: rgba(201,162,39,0.12);
  transform: scale(1.01);
  box-shadow: 0 0 30px rgba(201,162,39,0.25);
}

.drop-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
  line-height: 1;
}

.drop-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.drop-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.drop-formats {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ==========================================
   Preview
   ========================================== */

.preview-area {
  margin-top: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  padding: 1rem;
  background: rgba(0,0,0,0.2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

#previewImg {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  flex: 1;
}

/* ==========================================
   Method Selection
   ========================================== */

.method-selection {
  margin-top: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.method-label {
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 0.9rem;
  white-space: nowrap;
}

.toggle-group {
  display: flex;
  gap: 0.5rem;
  background: rgba(0,0,0,0.3);
  border-radius: 50px;
  padding: 0.25rem;
  border: 1px solid var(--border-color);
}

.toggle-option {
  cursor: pointer;
}

.toggle-option input[type="radio"] {
  display: none;
}

.toggle-btn {
  display: block;
  padding: 0.4rem 1rem;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition);
  white-space: nowrap;
}

.toggle-option input[type="radio"]:checked + .toggle-btn {
  background: var(--accent-gold);
  color: #0a0e1a;
  box-shadow: 0 2px 8px rgba(201,162,39,0.4);
}

.toggle-option:hover .toggle-btn {
  color: var(--text-primary);
}

.method-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  width: 100%;
  margin-top: 0.25rem;
}

/* ==========================================
   Buttons
   ========================================== */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  line-height: 1.4;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-gold), #a07c1e);
  color: #0a0e1a;
  box-shadow: 0 2px 12px rgba(201,162,39,0.3);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--accent-gold-light), var(--accent-gold));
  box-shadow: 0 4px 20px rgba(201,162,39,0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(201,162,39,0.1);
  color: var(--accent-gold-light);
  border: 1px solid rgba(201,162,39,0.3);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(201,162,39,0.2);
  border-color: var(--accent-gold);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-ghost:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-primary);
}

.btn-large {
  padding: 0.8rem 2rem;
  font-size: 1rem;
  margin-top: 1.5rem;
  width: 100%;
  justify-content: center;
  border-radius: 50px;
}

.btn-sm {
  padding: 0.3rem 0.75rem;
  font-size: 0.8rem;
}

/* ==========================================
   Loading
   ========================================== */

.loading-overlay {
  text-align: center;
  padding: 2.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-color);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* ==========================================
   Error Box
   ========================================== */

.error-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
}

.error-icon {
  flex-shrink: 0;
}

.error-msg {
  flex: 1;
  font-size: 0.9rem;
  color: #fca5a5;
}

/* ==========================================
   Results Section
   ========================================== */

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-color);
}

.results-summary {
  font-size: 1rem;
  color: var(--text-secondary);
}

.card-count {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent-gold-light);
}

.processing-time {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

/* ==========================================
   Card Table
   ========================================== */

.card-table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.card-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.card-table thead {
  background: rgba(0,0,0,0.3);
}

.card-table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.card-table td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid rgba(42,58,92,0.5);
  vertical-align: middle;
}

.card-table tbody tr:hover {
  background: var(--bg-card-hover);
}

.card-table tbody tr:last-child td {
  border-bottom: none;
}

/* Table cells */

.td-index {
  color: var(--text-muted);
  font-size: 0.8rem;
  width: 2.5rem;
  text-align: center;
}

.td-thumb {
  width: 48px;
}

.card-thumb {
  width: 40px;
  height: 58px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
}

.card-thumb-placeholder {
  width: 40px;
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  font-size: 1.2rem;
  color: var(--text-muted);
}

.td-name {
  min-width: 160px;
}

.card-name-ja {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.card-name-en {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.1rem;
}

.td-confidence {
  width: 90px;
  text-align: center;
}

.confidence-bar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.confidence-value {
  font-size: 0.85rem;
  font-weight: 700;
}

.confidence-bar {
  width: 64px;
  height: 5px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
}

.confidence-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s ease;
}

.conf-high { color: var(--success); }
.conf-high .confidence-fill { background: var(--success); }
.conf-mid  { color: var(--warning); }
.conf-mid  .confidence-fill { background: var(--warning); }
.conf-low  { color: var(--error); }
.conf-low  .confidence-fill { background: var(--error); }

.td-link {
  width: 72px;
  text-align: center;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  background: rgba(59,130,246,0.1);
  border: 1px solid rgba(59,130,246,0.3);
  border-radius: 50px;
  color: #93c5fd;
  transition: all var(--transition);
  white-space: nowrap;
}

.link-btn:hover {
  background: rgba(59,130,246,0.2);
  border-color: #3b82f6;
  color: #bfdbfe;
  text-decoration: none;
}

/* ==========================================
   Footer
   ========================================== */

.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 1.25rem 1rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.site-footer p {
  margin-bottom: 0.25rem;
}

.site-footer a {
  color: var(--accent-gold);
}

.footer-disclaimer {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* ==========================================
   Responsive
   ========================================== */

@media (max-width: 640px) {
  .main-content {
    margin: 1rem auto;
    padding: 0 0.75rem;
  }

  .card {
    padding: 1.25rem;
  }

  .drop-zone {
    padding: 1.75rem 0.75rem;
  }

  .method-selection {
    flex-direction: column;
    align-items: flex-start;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .card-table th:nth-child(2),
  .card-table td:nth-child(2) {
    display: none;
  }

  .card-table th,
  .card-table td {
    padding: 0.5rem 0.6rem;
  }

  .btn-large {
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
  }
}

@media (max-width: 400px) {
  .toggle-group {
    flex-direction: column;
    border-radius: var(--radius-sm);
    padding: 0.2rem;
  }

  .toggle-btn {
    text-align: center;
  }
}
