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

html {
  font-family: -apple-system, 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  font-size: 16px;
  color: #2B2621;
  background: #fff;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior-x: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overscroll-behavior-x: none;
}

button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

/* ===== Header ===== */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 1px solid #eeece9;
}

.header-back {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  transition: background 0.15s;
}

.header-back:active {
  background: #f3f1ef;
}

@keyframes headerBackFlash {
  0% { background: transparent; }
  30% { background: #f3f1ef; }
  100% { background: transparent; }
}

.header-back.tap-flash {
  animation: headerBackFlash 0.25s ease;
}

.header-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-logo {
  height: 22px;
  width: auto;
}

.header-spacer {
  width: 44px;
  flex-shrink: 0;
}

/* ===== Playlist ===== */
.playlist {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  padding-top: 52px; /* ヘッダー固定分の余白 */
  padding-bottom: calc(260px + var(--track-image-height, 0px));
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid #f0eeec;
}

.playlist-chapter {
  padding: 20px 18px 12px;
  background: #fff;
  border-bottom: 1px solid #f3f1ef;
}

.playlist-chapter__label {
  display: flex;
  align-items: center;
  font-size: 18px;
  line-height: 1.35;
  font-weight: 700;
  color: #2B2621;
  letter-spacing: 0;
}

.playlist-chapter__no {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 500;
  color: #a86a04;
  padding-right: 12px;
  margin-right: 12px;
  border-right: 1px solid #e2dfdc;
  line-height: 1;
}

.playlist-item:last-child {
  border-bottom: none;
}

.playlist-item:active {
  background: #f9f8f6;
}

.playlist-item--playing {
  background: rgba(198, 126, 5, 0.06);
}

.playlist-item--played {
  color: #b2aba4;
}

.playlist-item__icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #eae7e4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: #99928b;
}

.playlist-item--played .playlist-item__icon {
  color: #c1bab4;
}

.playlist-item--playing .playlist-item__icon {
  background: #c67e05;
  border-color: #c67e05;
  color: #fff;
}

.playlist-item__body {
  flex: 1;
  min-width: 0;
}

.playlist-item__title {
  font-size: 15px;
  line-height: 1.4;
  color: #2B2621;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-item--played .playlist-item__title {
  color: #b2aba4;
}

.playlist-item--playing .playlist-item__title {
  color: #a86a04;
  font-weight: 600;
}

.playlist-item__duration {
  font-size: 12.5px;
  color: #99928b;
  flex-shrink: 0;
}

/* ===== Player (Fixed Footer) ===== */
.player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: #fff;
  border-top: 1px solid #eeece9;
  padding: 12px 16px max(36px, env(safe-area-inset-bottom));
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
}

.player-info {
  text-align: center;
  margin-bottom: 8px;
}

.player-track-number {
  font-size: 12px;
  color: #b2aba4;
  display: block;
  margin-bottom: 2px;
}

.player-info__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-track-title {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Progress Bar ===== */
.progress-container {
  position: relative;
  height: 20px;
  display: flex;
  align-items: center;
  margin-bottom: 2px;
}

.progress-bar {
  width: 100%;
  height: 4px;
  background: #eae7e4;
  border-radius: 2px;
}

.progress-fill {
  height: 100%;
  background: #c67e05;
  border-radius: 2px;
  width: 0%;
  position: relative;
}

.progress-fill::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 12px;
  background: #c67e05;
  border-radius: 50%;
  transition: width 0.15s ease, height 0.15s ease, right 0.15s ease;
}

.progress-container:active .progress-fill {
  transition: none;
}

.progress-container:active .progress-fill::after {
  width: 18px;
  height: 18px;
  right: -9px;
}

.progress-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  touch-action: none;
}

/* ===== Seek Preview (thumbnail bubble) ===== */
.seek-preview {
  position: absolute;
  bottom: 28px;
  left: 0;
  transform: translateX(-50%) translateY(6px) scale(0.9);
  width: 96px;
  height: 96px;
  border-radius: 10px;
  overflow: hidden;
  background: #eae7e4;
  border: 2px solid #fff;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease, transform 0.12s ease;
  z-index: 5;
}

.seek-preview::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid #fff;
}

.seek-preview--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

.seek-preview__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.player-time {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #99928b;
  margin-bottom: 8px;
}

/* ===== Controls ===== */
.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.control-btn {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  position: relative;
  flex-shrink: 0;
}

.control-btn:active {
  background: #f3f1ef;
}

.control-btn--rewind {
  width: 58px;
  height: 58px;
}

.control-btn--rewind .skip-label {
  font-size: 10px;
}

.control-btn--skip3 {
  width: 42px;
  height: 42px;
  margin: 0 -8px;
}

#prevBtn {
  width: 40px;
  height: 40px;
  margin-right: 1px;
}

#nextBtn {
  width: 40px;
  height: 40px;
  margin-left: 1px;
}

#rewindBtn {
  width: 52px;
  height: 52px;
  margin-left: 1px;
}

#forwardBtn {
  width: 52px;
  height: 52px;
  margin-right: 1px;
}

/* フレーズモード時は3秒ボタン追加前の見た目に戻す（10秒モードとは独立して調整可能） */
.player-controls.is-phrase-mode {
  gap: 10px;
}

.player-controls.is-phrase-mode #prevBtn,
.player-controls.is-phrase-mode #nextBtn {
  width: 48px;
  height: 48px;
  margin: 0;
}

.player-controls.is-phrase-mode #rewindBtn,
.player-controls.is-phrase-mode #forwardBtn {
  width: 52px;
  height: 52px;
  margin: 0;
}

.player-controls.is-phrase-mode .control-btn--play {
  width: 60px;
  height: 60px;
  margin: 0;
}

.control-btn--play {
  width: 60px;
  height: 60px;
  margin: 0 -5px;
  background: #2B2621;
  color: #fff;
}

.control-btn--play:active {
  background: #444;
}

.control-btn--speed {
  font-size: 20px;
  font-weight: 500;
  width: auto;
  min-width: 48px;
  height: auto;
  border-radius: 0;
  flex-shrink: 0;
  background: none;
}

.skip-label {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* ===== Track Image ===== */
.track-image {
  position: fixed;
  left: 0;
  right: 0;
  z-index: 19;
  pointer-events: none;
  display: flex;
  justify-content: center;
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.track-image--visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.track-image__img {
  width: 100%;
  max-width: 480px;
  max-height: 45vh;
  object-fit: contain;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
  display: block;
  background: #000;
}

/* ===== Bookmark List ===== */
.bookmark-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 1px solid #f0eeec;
}

.bookmark-item:active {
  opacity: 0.6;
}

.bookmark-item__icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #b2aba4;
}

.bookmark-item__body {
  flex: 1;
  min-width: 0;
}

.bookmark-item__title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bookmark-item__time {
  font-size: 12px;
  color: #99928b;
}

.bookmark-item__delete {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ccc;
  border-radius: 50%;
}

.bookmark-item__delete:active {
  background: #f0f0f0;
  color: #999;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 50%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
}

.toast--visible {
  opacity: 1;
}

/* ===== Bookmark Button ===== */
.control-btn--bookmark {
  flex-shrink: 0;
  width: 48px;
  height: auto;
  border-radius: 0;
  background: none;
}

/* フレーズ送りモードON中の表示（吹き出しボタン） */
.control-btn--bookmark.is-active {
  color: #a86a04;
}

.control-btn--bookmark.is-active svg {
  fill: #c67e05;
}

/* ===== Gallery (画像一覧) ===== */
.gallery {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: #fff;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
}

.gallery--visible {
  transform: translateX(0);
}

.gallery-content {
  flex: 1;
  overflow-y: auto;
  padding-top: 52px;
}

.gallery-chapter {
  display: flex;
  align-items: center;
  padding: 14px 18px 4px;
}

.gallery-chapter__no {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 500;
  color: #a86a04;
  padding-right: 8px;
  margin-right: 8px;
  border-right: 1px solid #e2dfdc;
  line-height: 1;
}

.gallery-chapter__title {
  font-size: 15px;
  font-weight: 700;
  color: #2B2621;
}

.gallery-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px 8px;
}

.gallery-heading__no {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  font-weight: 600;
  color: #99928b;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid #eae7e4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.gallery-heading__title {
  font-size: 14px;
  color: #2B2621;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0 4px 8px;
}

.gallery-thumb {
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 4px;
  cursor: pointer;
  background: #eeece9;
  transition: opacity 0.15s;
}

.gallery-thumb:active {
  opacity: 0.6;
}

@keyframes galleryThumbFlash {
  0% { opacity: 1; }
  30% { opacity: 0.6; }
  100% { opacity: 1; }
}

.gallery-thumb.tap-flash {
  animation: galleryThumbFlash 0.25s ease;
}

.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-empty {
  padding: 60px 20px;
  text-align: center;
  color: #b2aba4;
  font-size: 14px;
}

/* ===== Viewer (拡大表示) ===== */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  touch-action: none;
}

.viewer--visible {
  opacity: 1;
  pointer-events: auto;
}

.viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: 12px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  z-index: 1;
  border-radius: 50%;
  transition: background 0.15s;
}

.viewer-close:active {
  background: rgba(255, 255, 255, 0.3);
}

@keyframes viewerCloseFlash {
  0% { background: transparent; }
  30% { background: rgba(255, 255, 255, 0.3); }
  100% { background: transparent; }
}

.viewer-close.tap-flash {
  animation: viewerCloseFlash 0.25s ease;
}

.viewer-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  z-index: 1;
  border-radius: 50%;
  transition: background 0.15s;
}

.viewer-nav:active {
  background: rgba(255, 255, 255, 0.3);
}

.viewer-nav--prev { left: 4px; }
.viewer-nav--next { right: 4px; }

.viewer-nav:disabled {
  opacity: 0.25;
  pointer-events: none;
}

.viewer-info {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: #fff;
  text-align: center;
  padding: 0 60px;
}

.viewer-info__title {
  font-size: 13px;
  opacity: 0.85;
}

.viewer-info__time {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.15);
  padding: 6px 16px 6px 6px;
  border-radius: 20px;
  transition: background 0.15s, transform 0.15s;
}

.viewer-info__time:active {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(0.95);
}

.viewer-info__time-icon {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #c67e05;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.viewer-info__time-text {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}

.viewer-hint {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.75);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.viewer-hint--visible {
  opacity: 1;
}

/* ===== Loading / Error ===== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: #b2aba4;
  font-size: 14px;
}

.error-message {
  padding: 24px 16px;
  text-align: center;
  color: #c00;
  font-size: 14px;
}
