/* ===== CSS Variables ===== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --bg-tertiary: #1e1e2e;
  --accent-primary: #ff6b9d;
  --accent-secondary: #c44569;
  --accent-gradient: linear-gradient(135deg, #ff6b9d 0%, #c44569 100%);
  --text-primary: #ffffff;
  --text-secondary: #a0a0b0;
  --text-muted: #606070;
  --border-color: rgba(255, 255, 255, 0.1);
  --shadow-glow: 0 0 30px rgba(255, 107, 157, 0.3);
  --font-main: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== Reset & Base ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* ===== App Container ===== */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

/* ===== Header ===== */
.header {
  text-align: center;
  padding: 1.5rem 1rem;
  background: linear-gradient(180deg, var(--bg-secondary) 0%, transparent 100%);
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.25rem;
}

.tagline {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  padding: 0 1rem 1rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* ===== Input Section ===== */
.input-section {
  margin-bottom: 1.5rem;
}

.input-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tab-btn.active {
  background: var(--accent-gradient);
  color: white;
  border-color: transparent;
  box-shadow: var(--shadow-glow);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

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

.file-input-label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--bg-tertiary);
  border: 2px dashed var(--border-color);
  border-radius: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.file-input-label:hover {
  border-color: var(--accent-primary);
  background: rgba(255, 107, 157, 0.05);
}

.file-input-label input {
  display: none;
}

.file-input-text {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary);
  font-size: 1rem;
}

.gdrive-input {
  display: flex;
  gap: 0.75rem;
}

.gdrive-input input {
  flex: 1;
  padding: 0.875rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.3s ease;
}

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

.btn-primary {
  padding: 0.875rem 1.5rem;
  background: var(--accent-gradient);
  border: none;
  border-radius: 0.75rem;
  color: white;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.3s ease;
  white-space: nowrap;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

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

.hint {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ===== Player Section ===== */
.player-section {
  margin-bottom: 1.5rem;
}

.video-container {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  /* Safari fix for overflow hidden with transforms */
  transform: translateZ(0);
  -webkit-mask-image: -webkit-radial-gradient(white, black);
  mask-image: radial-gradient(white, black);
}

#video-player {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.video-placeholder.hidden {
  display: none;
}

.video-placeholder svg {
  opacity: 0.3;
}

/* ===== Comment Overlay ===== */
.comment-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 10;
}

.comment {
  position: absolute;
  white-space: nowrap;
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
  text-shadow:
    2px 2px 0 #000,
    -2px 2px 0 #000,
    2px -2px 0 #000,
    -2px -2px 0 #000,
    0 2px 0 #000,
    0 -2px 0 #000,
    2px 0 0 #000,
    -2px 0 0 #000;
  will-change: transform;
  animation-timing-function: linear;
  animation-fill-mode: forwards;
  /* Hardware acceleration */
  transform: translate3d(0, 0, 0);
}

/* AI Comment Style */
.comment.ai {
  color: #ff6b9d;
  /* Pink for AI */
  z-index: 11;
  /* Above normal comments */
  font-size: 1.8rem;
  text-shadow:
    2px 2px 0 rgba(0, 0, 0, 0.8),
    -2px 2px 0 rgba(0, 0, 0, 0.8),
    2px -2px 0 rgba(0, 0, 0, 0.8),
    -2px -2px 0 rgba(0, 0, 0, 0.8),
    0 2px 0 rgba(0, 0, 0, 0.8),
    0 -2px 0 rgba(0, 0, 0, 0.8),
    2px 0 0 rgba(0, 0, 0, 0.8),
    -2px 0 0 rgba(0, 0, 0, 0.8);
}

@keyframes slideComment {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(calc(-100% - 100vw));
  }
}

/* Pause all comments when body has is-paused class */
body.is-paused .comment {
  -webkit-animation-play-state: paused !important;
  animation-play-state: paused !important;
}

/* ===== Controls ===== */
.controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  padding: 0.75rem;
  background: var(--bg-secondary);
  border-radius: 0.75rem;
}

.control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s ease;
}

.control-btn:hover:not(:disabled) {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.control-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.progress-bar {
  flex: 1;
  height: 6px;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg-tertiary);
  border-radius: 3px;
  cursor: pointer;
}

.progress-bar::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent-primary);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.progress-bar::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.progress-bar:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.time-display {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 90px;
  text-align: center;
}

/* ===== Settings Section ===== */
.settings-section {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: 1rem;
  margin-bottom: 1.5rem;
}

.setting-item {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.setting-item label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.setting-item select,
.setting-item input {
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.3s ease;
}

.setting-item select:focus,
.setting-item input:focus {
  border-color: var(--accent-primary);
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .header {
    padding: 1rem;
  }

  .logo {
    font-size: 1.25rem;
  }

  .comment {
    font-size: 1rem;
  }

  .comment.ai {
    font-size: 1.2rem;
  }

  .settings-section {
    grid-template-columns: 1fr;
  }

  .gdrive-input {
    flex-direction: column;
  }

  .controls {
    flex-wrap: wrap;
  }

  .progress-bar {
    order: -1;
    width: 100%;
    flex: none;
  }

  .time-display {
    flex: 1;
    text-align: left;
  }
}

/* ===== Loading State ===== */
.loading {
  position: relative;
}

.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
}

/* ===== Toast Notification ===== */
.toast {
  position: fixed;
  bottom: calc(1rem + var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  padding: 0.875rem 1.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  color: var(--text-primary);
  font-size: 0.875rem;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.error {
  border-color: #e74c3c;
  background: rgba(231, 76, 60, 0.2);
}