/* === リセット・ベース === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-card: #0f3460;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --border: #2a2a4a;
  --radius: 8px;
  --header-height: 56px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* === スクリーン管理 === */
.screen {
  display: none;
  min-height: 100vh;
  animation: fadeIn 0.2s ease-out;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === ログイン画面 === */
.login-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
}

.login-container h1 {
  font-size: 2rem;
  margin-bottom: 8px;
  color: var(--accent);
}

.login-description {
  color: var(--text-secondary);
  margin-bottom: 40px;
  font-size: 0.95rem;
}

/* === ボタン === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-icon {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
}

.google-icon {
  flex-shrink: 0;
}

/* === ヘッダー === */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h2 {
  flex: 1;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === フォルダ設定画面 === */
.settings-container {
  flex: 1;
  padding: 24px;
  max-width: 500px;
  margin: 0 auto;
  width: 100%;
}

.settings-container p {
  margin-bottom: 12px;
  line-height: 1.6;
}

.settings-hint {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.input-group {
  margin: 24px 0;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

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

.input-group input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

/* フォルダ選択済み表示 */
.folder-selected {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  margin: 20px 0;
}

.folder-selected-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.settings-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 20px 0;
}

.settings-advanced {
  margin-top: 16px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.settings-advanced summary {
  cursor: pointer;
  padding: 8px 0;
}

.settings-advanced summary:hover {
  color: var(--text-primary);
}

/* === 作品一覧 (ライブラリ) === */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  padding: 16px;
  flex: 1;
}

.work-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.work-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.work-card:active {
  transform: scale(0.97);
}

.work-card-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  color: var(--text-secondary);
}

.work-card-name {
  padding: 10px;
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* === 巻一覧 === */
.volumes-list {
  padding: 8px 16px;
  flex: 1;
}

.volume-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.volume-item:hover {
  background: var(--bg-card);
}

.volume-item:active {
  background: var(--border);
}

.volume-icon {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  background: var(--bg-card);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.volume-info {
  flex: 1;
  min-width: 0;
}

.volume-name {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.volume-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.volume-badge {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
}

/* === ローディング === */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-secondary);
}

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

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

/* === エラー・空メッセージ === */
.error-message {
  color: var(--accent);
  font-size: 0.9rem;
  margin-top: 16px;
  text-align: center;
}

.empty-message {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* === ビューア画面 === */
.viewer-screen {
  background: #000;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 200;
  min-height: 0;
  overflow: hidden;
  align-items: center;
  justify-content: center;
}

.viewer-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-height);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 210;
  opacity: 0;
  transform: translateY(-100%);
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
}

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

.viewer-header .btn-icon {
  color: #fff;
}

.viewer-title {
  flex: 1;
  font-size: 0.95rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  transition: transform 0.15s ease-out;
  will-change: transform;
}

.viewer-page-info {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 4px 14px;
  border-radius: 16px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.5s;
  pointer-events: none;
  z-index: 205;
}

.viewer-page-info.visible {
  opacity: 1;
}

.viewer-loading {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  z-index: 220;
  color: var(--text-secondary);
}

/* === ビューア終端オーバーレイ === */
.viewer-end-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  background: rgba(0, 0, 0, 0.85);
  z-index: 215;
  color: #fff;
  font-size: 1.1rem;
  animation: fadeIn 0.3s ease-out;
}

/* === トースト通知 === */
.app-toast {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

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

/* === ユーティリティ === */
.hidden {
  display: none !important;
}

/* === スクロールバー === */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}
