/* ============================================================
   セルフホスト CAPTCHA Solver — モバイルPWA スタイル
   ============================================================ */

:root {
  --bg-primary: #0a0a1a;
  --bg-secondary: #12122a;
  --bg-card: #1a1a3e;
  --bg-card-hover: #222255;
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.4);
  --accent-light: #a29bfe;
  --success: #00e676;
  --success-bg: rgba(0, 230, 118, 0.12);
  --warning: #ffd600;
  --warning-bg: rgba(255, 214, 0, 0.12);
  --danger: #ff5252;
  --danger-bg: rgba(255, 82, 82, 0.12);
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(108, 92, 231, 0.3);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ============================================================
   ヘッダー
   ============================================================ */

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-card) 100%);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-size: 28px;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.header-info h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  transition: var(--transition);
}

.status.connected .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-dot 2s infinite;
}

.status.disconnected .status-dot {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
}

.status.connected .status-text { color: var(--success); }
.status.disconnected .status-text { color: var(--danger); }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:active {
  transform: scale(0.92);
  background: var(--bg-card-hover);
}

.icon-btn.muted {
  opacity: 0.4;
}

/* ============================================================
   統計バー
   ============================================================ */

#stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  border-bottom: 1px solid var(--border);
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  background: var(--bg-secondary);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-light);
  line-height: 1;
}

.stat-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* ============================================================
   メインコンテンツ
   ============================================================ */

#main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
}

.screen.active {
  display: flex;
}

/* 待機画面 */
#idle-screen {
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.idle-animation {
  position: relative;
  width: 140px;
  height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 30px;
}

.pulse-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  animation: pulse-ring 3s infinite ease-out;
}

.pulse-ring.delay-1 { animation-delay: 1s; }
.pulse-ring.delay-2 { animation-delay: 2s; }

@keyframes pulse-ring {
  0% { transform: scale(0.5); opacity: 0.6; }
  100% { transform: scale(1.4); opacity: 0; }
}

.idle-icon {
  font-size: 56px;
  animation: idle-float 4s infinite ease-in-out;
  filter: drop-shadow(0 0 20px var(--accent-glow));
}

@keyframes idle-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}

.idle-text {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.idle-subtext {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* CAPTCHA解答画面 */
#solve-screen {
  padding: 0;
}

.task-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.task-badge {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  background: var(--accent);
  color: white;
  padding: 4px 10px;
  border-radius: 20px;
}

.task-timer {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 600;
  color: var(--warning);
}

#captcha-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  min-height: 200px;
}

#captcha-image {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-accent);
  box-shadow: 0 4px 24px rgba(108, 92, 231, 0.15);
  object-fit: contain;
  background: #ffffff;
  image-rendering: -webkit-optimize-contrast;
}

#solve-form {
  padding: 16px 18px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.input-group {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

#captcha-input {
  flex: 1;
  height: 52px;
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 2px;
  text-align: center;
  background: var(--bg-primary);
  border: 2px solid var(--border-accent);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  outline: none;
  transition: var(--transition);
  caret-color: var(--accent-light);
}

#captcha-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#captcha-input::placeholder {
  color: var(--text-muted);
  font-size: 14px;
  letter-spacing: 0;
}

.btn-primary {
  height: 52px;
  padding: 0 22px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary:active {
  transform: scale(0.96);
  filter: brightness(0.9);
}

.action-buttons {
  display: flex;
  gap: 10px;
}

.btn-secondary {
  flex: 1;
  height: 40px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:active {
  transform: scale(0.97);
  background: var(--bg-card-hover);
}

/* ============================================================
   タスクキュー
   ============================================================ */

#task-queue {
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
  max-height: 40vh;
  overflow-y: auto;
}

#task-queue.hidden {
  display: none;
}

.queue-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
}

#queue-list {
  display: flex;
  flex-direction: column;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
}

.queue-item:active {
  background: var(--bg-card);
}

.queue-item.active {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
}

.queue-thumb {
  width: 48px;
  height: 32px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  background: white;
  border: 1px solid var(--border);
}

.queue-info {
  flex: 1;
}

.queue-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.queue-time {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ============================================================
   アニメーション
   ============================================================ */

@keyframes slide-up {
  from {
    transform: translateY(20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
  20%, 40%, 60%, 80% { transform: translateX(4px); }
}

.animate-in {
  animation: slide-up 0.3s ease-out;
}

.shake {
  animation: shake 0.5s ease-out;
}

/* 新タスク到着フラッシュ */
.flash-border {
  animation: flash-border 0.6s ease-out;
}

@keyframes flash-border {
  0% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 8px var(--accent-glow); }
  100% { box-shadow: 0 0 0 0 var(--accent-glow); }
}

/* ============================================================
   スクロールバー
   ============================================================ */

::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 2px;
}

/* ============================================================
   レスポンシブ（タブレット以上）
   ============================================================ */

@media (min-width: 768px) {
  body {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }

  #captcha-image {
    max-height: 400px;
  }
}
