:root {
  --primary: #ff0033;
  --primary-hover: #cc0029;
  --bg: #0f0f0f;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #272727;
  --text: #f1f1f1;
  --text-secondary: #aaaaaa;
  --border: #333333;
  --success: #2ba640;
  --error: #cc0000;
  --radius: 8px;
}

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

html {
  font-size: clamp(14px, 4.5vw, 16px);
}

body {
  font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

.container {
  max-width: 800px;
  margin: 0 auto;
  padding: clamp(20px, 5vw, 40px) clamp(12px, 4vw, 20px);
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.lang-toggle {
  display: flex;
  gap: 4px;
}

.lang-btn {
  padding: clamp(4px, 1.5vw, 8px) clamp(8px, 2vw, 12px);
  font-size: clamp(0.7rem, 2.5vw, 0.8rem);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn.active {
  color: var(--primary);
  border-color: var(--primary);
}

.visitor-badge {
  font-size: clamp(0.65rem, 2vw, 0.75rem);
  color: var(--text-secondary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px clamp(8px, 2vw, 14px);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.share-btn {
  padding: 4px 10px;
  font-size: 1rem;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.share-btn:hover {
  color: var(--text);
  border-color: var(--primary);
}

.counter-drum {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-family: 'Courier New', Consolas, monospace;
  font-weight: 700;
  font-size: clamp(0.75rem, 2.5vw, 0.85rem);
  color: var(--text);
  letter-spacing: 1px;
}

.drum-digit {
  display: inline-block;
  width: clamp(12px, 3.5vw, 14px);
  height: clamp(16px, 4.5vw, 18px);
  line-height: clamp(16px, 4.5vw, 18px);
  text-align: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  transition: transform 0.4s ease;
}

.drum-digit span {
  display: block;
  width: 100%;
  height: 100%;
}

header {
  text-align: center;
  margin-bottom: clamp(24px, 5vw, 40px);
}

header h1 {
  font-size: clamp(1.5rem, 6vw, 2rem);
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: clamp(0.85rem, 3vw, 1rem);
}

.input-section {
  background: var(--bg-secondary);
  padding: clamp(16px, 3vw, 24px);
  border-radius: var(--radius);
  margin-bottom: 24px;
}

.input-section label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: clamp(0.85rem, 3vw, 1rem);
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input {
  flex: 1;
  min-width: 0;
  padding: clamp(10px, 2.5vw, 12px) clamp(12px, 3vw, 16px);
  font-size: clamp(0.85rem, 3vw, 1rem);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.input-row input:focus {
  border-color: var(--primary);
}

.input-row input::placeholder {
  color: var(--text-secondary);
}

.icon-btn {
  padding: clamp(8px, 2vw, 12px);
  min-width: 44px;
  min-height: 44px;
  font-size: clamp(0.85rem, 3vw, 1rem);
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.icon-btn:hover {
  background: var(--border);
}

#fetch-btn {
  padding: clamp(10px, 2.5vw, 12px) clamp(16px, 4vw, 24px);
  font-size: clamp(0.85rem, 3vw, 1rem);
  font-weight: 600;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#fetch-btn:hover {
  background: var(--primary-hover);
}

#fetch-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.loading {
  text-align: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error {
  background: var(--error);
  color: white;
  padding: 16px;
  border-radius: var(--radius);
  text-align: center;
  font-size: clamp(0.85rem, 3vw, 1rem);
}

.result {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
}

.video-info {
  padding: clamp(16px, 3vw, 24px);
  border-bottom: 1px solid var(--border);
}

.video-info h2 {
  font-size: clamp(1rem, 4vw, 1.2rem);
  margin-bottom: 8px;
  line-height: 1.4;
  word-break: break-word;
}

.meta {
  display: flex;
  gap: 16px;
  color: var(--text-secondary);
  font-size: clamp(0.8rem, 2.5vw, 0.9rem);
  flex-wrap: wrap;
}

.subtitle-lang-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  font-size: clamp(0.8rem, 2.5vw, 0.85rem);
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.subtitle-lang-row select {
  padding: 4px 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: clamp(0.8rem, 2.5vw, 0.85rem);
  cursor: pointer;
  max-width: 100%;
}

.transcript-section {
  padding: clamp(16px, 3vw, 24px);
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  padding: clamp(6px, 2vw, 8px) clamp(12px, 3vw, 16px);
  font-size: clamp(0.8rem, 2.5vw, 0.9rem);
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-content pre {
  background: var(--bg-tertiary);
  padding: clamp(12px, 2.5vw, 16px);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: 'Courier New', Consolas, monospace;
  font-size: clamp(0.8rem, 2.5vw, 0.9rem);
  line-height: 1.8;
  max-height: min(500px, 60vh);
  overflow-y: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.full-description {
  margin-bottom: 16px;
}

.desc-section {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: clamp(12px, 2.5vw, 16px);
  margin-bottom: 12px;
}

.desc-label {
  font-size: clamp(0.7rem, 2vw, 0.8rem);
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.desc-text {
  font-size: clamp(0.85rem, 3vw, 1rem);
  line-height: 1.7;
  color: var(--text);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.export-section {
  padding: clamp(12px, 3vw, 16px) clamp(16px, 3vw, 24px);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.export-btn,
.copy-btn {
  padding: clamp(6px, 2vw, 8px) clamp(12px, 3vw, 16px);
  min-height: 44px;
  font-size: clamp(0.8rem, 2.5vw, 0.9rem);
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.export-btn:hover,
.copy-btn:hover {
  background: var(--border);
}

.copy-btn {
  margin-left: auto;
}

.copy-btn.copied {
  background: var(--success);
  border-color: var(--success);
}

footer {
  text-align: center;
  margin-top: clamp(24px, 5vw, 40px);
  color: var(--text-secondary);
  font-size: clamp(0.75rem, 2.5vw, 0.85rem);
}

.note {
  margin-top: 4px;
  font-size: clamp(0.7rem, 2.5vw, 0.8rem);
}

.hidden {
  display: none !important;
}

@media (max-width: 480px) {
  .top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .visitor-badge {
    align-self: flex-end;
  }

  .input-row {
    flex-wrap: wrap;
  }

  .input-row input {
    width: 100%;
    flex: none;
    order: -1;
  }

  .icon-btn {
    flex: 1;
  }

  #fetch-btn {
    width: 100%;
  }

  .export-section {
    flex-direction: column;
  }

  .export-btn,
  .copy-btn {
    width: 100%;
    margin-left: 0;
  }

  .subtitle-lang-row select {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 380px) {
  .container {
    padding: 12px 8px;
  }

  .input-section {
    padding: 12px;
  }

  .video-info {
    padding: 12px;
  }

  .transcript-section {
    padding: 12px;
  }
}
