:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --border: #e3e7f1;
  --text: #1c2233;
  --muted: #667089;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eceafd;
  --danger: #d1344b;
  --danger-soft: #fdecef;
  --shadow: 0 1px 2px rgba(20, 28, 58, 0.06), 0 4px 14px rgba(20, 28, 58, 0.06);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151f;
    --surface: #1b2030;
    --surface-2: #232940;
    --border: #2d3550;
    --text: #e8ebf5;
    --muted: #97a1bd;
    --accent: #7b74ff;
    --accent-hover: #918bff;
    --accent-soft: #272a52;
    --danger: #ff6b7f;
    --danger-soft: #3a2029;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

/* ズームを無効化(ダブルタップ・ピンチ)。縦横のスクロール(パン)だけを許可します */
html, body, * { touch-action: pan-x pan-y; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body.no-scroll { overflow: hidden; }

.hidden { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

.muted { color: var(--muted); }

/* ---------- ボタン・入力 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-icon { padding: 0; width: 40px; }
.btn-block { width: 100%; }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger-soft); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

input[type="password"], input[type="search"], select {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  /* iPhoneは16px未満の入力欄をタップすると画面を自動で拡大するため、16pxにしています */
  font-size: 16px;
}
input:focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--accent); }

/* ---------- ログイン ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-card .logo { color: var(--accent); display: flex; justify-content: center; }
.login-card h1 { margin: 8px 0 24px; font-size: 24px; }
.field { display: block; text-align: left; }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.form-error { min-height: 22px; margin: 10px 0 12px; color: var(--danger); font-size: 14px; font-weight: 600; }

/* ---------- 画面上部 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--accent); white-space: nowrap; }
.brand span { color: var(--text); }
.search { flex: 1; max-width: 520px; margin: 0 auto 0 12px; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 80px; }

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-spacer { flex: 1; }
.select-wrap select { min-height: 40px; width: auto; }

/* ---------- アップロード状態 ---------- */
.upload-status {
  margin-bottom: 16px;
  padding: 14px 16px;
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.upload-line { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.upload-line .muted { overflow-wrap: anywhere; }
progress { width: 100%; height: 10px; accent-color: var(--accent); }

.list-message { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- ファイル一覧 ---------- */
.file-list.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(176px, 1fr));
  gap: 14px;
}
.file-list.list { display: flex; flex-direction: column; gap: 8px; }

.card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 0;
}

.thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  padding: 0;
  border: 0;
  background: var(--surface-2);
  cursor: pointer;
  overflow: hidden;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .file-icon { width: 56px; }
.play-badge {
  position: absolute;
  right: 8px; bottom: 8px;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
}

.card-body { padding: 10px 12px 4px; min-width: 0; flex: 1; }
.file-name {
  margin: 0 0 2px;
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.file-meta { margin: 0; font-size: 12px; color: var(--muted); }

.card-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 8px 8px; }
.card-actions .btn { flex: 1 1 calc(50% - 3px); min-height: 34px; padding: 0 8px; font-size: 13px; }

/* リスト表示 */
.file-list.list .card { flex-direction: row; align-items: center; }
.file-list.list .thumb { width: 72px; aspect-ratio: 1; flex: none; }
.file-list.list .thumb .file-icon { width: 34px; }
.file-list.list .card-body { padding: 8px 12px; }
.file-list.list .file-name { -webkit-line-clamp: 1; }
.file-list.list .card-actions { padding: 8px 10px; flex: none; flex-wrap: nowrap; }
.file-list.list .card-actions .btn { flex: none; }

/* ---------- ファイルの種類アイコン ---------- */
.file-icon { display: block; width: 100%; }
.file-icon svg { display: block; width: 100%; height: auto; }
.ic-page { fill: var(--surface); stroke: var(--icon-color); stroke-width: 2.5; }
.ic-fold { fill: var(--icon-color); opacity: 0.35; }
.ic-band { fill: var(--icon-color); }
.icon-label { fill: #fff; font-size: 13px; font-weight: 800; font-family: system-ui, sans-serif; letter-spacing: 0.3px; }
.ic-glyph { fill: var(--icon-color); stroke: var(--icon-color); stroke-linejoin: round; }

/* ---------- ドラッグ&ドロップ ---------- */
.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-overlay div {
  padding: 28px 36px;
  border: 3px dashed var(--accent);
  border-radius: 20px;
  background: var(--surface);
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

/* ---------- プレビュー ---------- */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: rgba(10, 12, 20, 0.92);
  color: #fff;
}
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; }
.viewer-title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-actions { display: flex; gap: 8px; }
.viewer .btn-ghost { color: #fff; border-color: rgba(255, 255, 255, 0.3); }
.viewer .btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
.viewer .btn-ghost.btn-danger { color: #ff8a98; border-color: rgba(255, 138, 152, 0.5); }
.viewer .btn-ghost.btn-danger:hover:not(:disabled) { background: rgba(255, 138, 152, 0.15); }
.viewer-body {
  flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 12px 8px;
  /* 行・列を表示領域の大きさに固定する(これがないと中身の高さまで伸びてスクロールできない) */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  /* はみ出した分はこの中でスクロール。背景のページにはスクロールを伝えない */
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; border-radius: 8px; background: #000; }
.viewer-body audio { width: min(560px, 100%); }
.viewer-body .loading { color: rgba(255, 255, 255, 0.8); }

.pdf-wrap { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 8px; }
.pdf-wrap iframe { flex: 1; min-height: 0; width: 100%; border: 0; border-radius: 8px; background: #fff; }
.pdf-wrap .code-scroll { flex: 1; min-height: 0; height: auto; }
.viewer-note { margin: 0; font-size: 13px; opacity: 0.8; text-align: center; }

.viewer-info {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px calc(10px + env(safe-area-inset-bottom));
  font-size: 13px; color: rgba(255, 255, 255, 0.8);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.viewer-info #viewer-info-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.viewer-wrap { min-height: 34px; padding: 0 12px; font-size: 13px; }

/* コード表示(行番号つき・横スクロール) */
.code-scroll {
  width: 100%; height: 100%;
  overflow: auto;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, "Courier New", monospace;
  tab-size: 4;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.code { counter-reset: line; min-width: max-content; padding: 10px 0; }
.code-line { display: flex; min-height: 1.6em; }
.code-line::before {
  counter-increment: line;
  content: counter(line);
  position: sticky; left: 0;
  flex: none;
  min-width: 3.6em;
  padding: 0 12px 0 8px;
  text-align: right;
  color: var(--muted);
  background: var(--surface);
  user-select: none;
  -webkit-user-select: none;
}
.code-text { flex: 1; padding-right: 16px; white-space: pre; }
.code.wrap { min-width: 0; }
.code.wrap .code-text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.tok-c { color: #6a7a94; font-style: italic; }
.tok-s { color: #b4531a; }
.tok-n { color: #0f7b6c; }
.tok-k { color: #6d4cd8; font-weight: 600; }
.tok-t { color: #1f6fb8; }
.tok-p { color: #1f6fb8; }
@media (prefers-color-scheme: dark) {
  .tok-c { color: #8190aa; }
  .tok-s { color: #f2a56b; }
  .tok-n { color: #5fd1bd; }
  .tok-k { color: #b2a2ff; }
  .tok-t { color: #7cb7f2; }
  .tok-p { color: #7cb7f2; }
}

/* プレビューできないファイルの詳細カード */
.detail-card {
  width: min(480px, 100%);
  padding: 24px 20px;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  text-align: center;
}
.detail-card .file-icon { width: 72px; margin: 0 auto 12px; }
.detail-card h3 { margin: 0 0 12px; font-size: 17px; overflow-wrap: anywhere; }
.detail-message { margin: 0 0 14px; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.detail-card dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0 0 18px; text-align: left; font-size: 14px; }
.detail-card dt { color: var(--muted); }
.detail-card dd { margin: 0; overflow-wrap: anywhere; }
.detail-card .btn { width: 100%; }
.viewer-body:has(.detail-card) { overflow: auto; align-items: start; padding-top: 12px; }

/* ---------- 通知 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #1c2233;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}
.toast.error { background: var(--danger); }

/* ---------- スマホ ---------- */
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; padding: 10px 12px; }
  .brand { flex: 1; }
  .search { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  .container { padding: 14px 12px 80px; }
  .file-list.grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .toolbar .btn-primary { flex: 1 1 100%; }
  #new-folder-button { flex: 1 1 100%; }
  .toolbar-spacer { display: none; }
  .select-wrap { flex: 1; }
  .select-wrap select { width: 100%; }
  .file-list.list .card { flex-wrap: wrap; }
  .file-list.list .card-body { flex-basis: calc(100% - 100px); }
  .file-list.list .card-actions { width: 100%; padding-top: 0; flex-wrap: wrap; }
  .file-list.list .card-actions .btn { flex: 1 1 calc(25% - 6px); padding: 0 4px; }

  /* プレビュー画面: 1行目「← 戻る + ファイル名」、2行目「ダウンロード / 削除」 */
  .viewer-bar { flex-wrap: wrap; padding: 10px 12px; }
  .viewer-title { order: 2; }
  .viewer-actions { order: 3; width: 100%; }
  .viewer-actions .btn { flex: 1; min-height: 44px; padding: 0 6px; }
  .viewer-back { order: 1; }
  .viewer-body { padding: 0 8px 6px; }
}

/* ---------- 音声プレーヤー ---------- */
.ap {
  width: min(480px, 100%);
  padding: 22px 18px 18px;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}

/* 波形バー: 再生中だけ動き、一時停止で止まります */
.ap-eq {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 96px;
  margin-bottom: 14px;
  padding: 0 4px;
}
.ap-bar {
  flex: 1;
  height: 100%;
  min-width: 2px;
  border-radius: 99px;
  background: linear-gradient(to top, var(--accent), color-mix(in srgb, var(--accent) 45%, #ff7ab6));
  transform-origin: center;
  transform: scaleY(var(--lo));
  animation: ap-eq var(--d) ease-in-out var(--delay) infinite alternate;
  animation-play-state: paused;
  opacity: 0.55;
  transition: opacity 0.4s;
}
.ap.is-playing .ap-bar { animation-play-state: running; opacity: 1; }
@keyframes ap-eq {
  from { transform: scaleY(var(--lo)); }
  to { transform: scaleY(var(--hi)); }
}

.ap-seek { padding: 0 2px; }
.ap-times { display: flex; justify-content: space-between; margin-top: -2px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

.ap-range {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none; /* 横ドラッグをスクロールではなくスライダー操作として扱う */
  --p: 0%;
}
.ap-range:disabled { cursor: default; opacity: 0.5; }
.ap-range::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--border) var(--p));
}
.ap-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px; height: 18px;
  margin-top: -6px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s;
}
.ap-range:active::-webkit-slider-thumb { transform: scale(1.25); }
.ap-range::-moz-range-track { height: 6px; border-radius: 99px; background: var(--border); }
.ap-range::-moz-range-progress { height: 6px; border-radius: 99px; background: var(--accent); }
.ap-range::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: var(--accent); }

.ap-controls { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 10px; }
.ap-btn {
  display: grid; place-items: center;
  min-width: 46px; height: 46px;
  padding: 0 6px;
  border: 0; border-radius: 50%;
  background: transparent;
  color: var(--text);
  font: inherit; font-size: 14px; font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.ap-btn svg { width: 28px; height: 28px; }
.ap-btn:hover { background: var(--surface-2); }
.ap-btn:active { transform: scale(0.9); }
.ap-speed { font-size: 15px; font-variant-numeric: tabular-nums; }

/* 再生/一時停止ボタン: アイコンが回転しながら入れ替わり、再生中は光が脈打ちます */
.ap-play {
  position: relative;
  flex: none;
  width: 68px; height: 68px;
  border: 0; border-radius: 50%;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform 0.12s, background 0.15s;
}
.ap-play:hover { background: var(--accent-hover); }
.ap-play:active { transform: scale(0.92); }
.ap-play::after {
  content: '';
  position: absolute; inset: 0;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}
.ap.is-playing .ap-play::after { animation: ap-pulse 1.6s ease-out infinite; }
@keyframes ap-pulse {
  from { transform: scale(1); opacity: 0.6; }
  to { transform: scale(1.5); opacity: 0; }
}
.ap-ic {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  transition: opacity 0.2s, transform 0.25s;
}
.ap-ic svg { width: 32px; height: 32px; }
.ap-ic-pause { opacity: 0; transform: scale(0.4) rotate(-90deg); }
.ap.is-playing .ap-ic-play { opacity: 0; transform: scale(0.4) rotate(90deg); }
.ap.is-playing .ap-ic-pause { opacity: 1; transform: scale(1) rotate(0); }
.ap.is-loading .ap-play { animation: ap-breathe 0.9s ease-in-out infinite alternate; }
@keyframes ap-breathe { from { opacity: 1; } to { opacity: 0.55; } }

.ap-volume { margin-top: 6px; padding: 0 6px; }
.ap-volume[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .ap-bar { animation: none; transform: scaleY(0.5); }
  .ap.is-playing .ap-play::after { animation: none; }
  .ap-ic { transition: opacity 0.1s; }
}

/* ---------- フォルダ ---------- */
.breadcrumb {
  display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px;
  margin: 0 0 14px; font-size: 14px;
}
.crumb {
  padding: 4px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--accent);
  font: inherit; font-weight: 600; cursor: pointer;
}
.crumb:hover { background: var(--accent-soft); }
.crumb-sep { color: var(--muted); }
.crumb-current { padding: 4px 8px; font-weight: 700; overflow-wrap: anywhere; }

.ic-folder { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.folder-card .thumb .file-icon { width: 64px; }
.file-list.list .folder-card .thumb .file-icon { width: 38px; }
.file-place { overflow-wrap: anywhere; }

/* 移動先の選択ダイアログ */
.modal {
  position: fixed; inset: 0; z-index: 60;
  display: grid; place-items: center; padding: 16px;
  background: rgba(10, 14, 28, 0.55);
}
.modal-card {
  display: flex; flex-direction: column; gap: 12px;
  width: min(420px, 100%); max-height: min(80vh, 560px);
  padding: 18px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
}
.modal-title { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.move-list {
  display: flex; flex-direction: column; gap: 2px;
  min-height: 0; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 10px; padding: 4px;
}
.move-item {
  min-height: 42px; padding: 0 14px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text);
  font: inherit; text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
.move-item:hover:not(:disabled) { background: var(--accent-soft); }
.move-item:disabled { color: var(--muted); cursor: not-allowed; }

/* ---------- 操作メニュー(カードの「…」) ---------- */
.card-actions .btn:not(.menu-anchor) { flex: 1 1 0; }
.card-actions .menu-anchor { flex: none; width: 44px; min-width: 44px; padding: 0; font-size: 18px; line-height: 1; }
.menu {
  position: fixed; z-index: 55;
  display: flex; flex-direction: column;
  min-width: 168px; padding: 6px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
}
.menu-item {
  display: flex; align-items: center;
  min-height: 42px; padding: 0 12px;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--text);
  font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline-offset: -2px; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--danger-soft); }

/* ---------- 複数選択 ---------- */
.card { position: relative; }
.select-check { display: none; }
body.selecting .select-check {
  display: block; position: absolute; top: 10px; left: 10px; z-index: 2;
  width: 24px; height: 24px; margin: 0;
  accent-color: var(--accent); cursor: pointer;
}
body.selecting .card { cursor: pointer; }
body.selecting .card-actions { display: none; }
body.selecting .thumb { pointer-events: none; }
.card.is-selected { outline: 3px solid var(--accent); outline-offset: -3px; background: var(--accent-soft); }
.select-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--surface);
  box-shadow: 0 -6px 20px rgba(20, 28, 58, 0.12);
}
.select-count { flex: 1 1 120px; font-weight: 700; }
body.selecting .container { padding-bottom: 130px; }
body.selecting .toast { bottom: 96px; }
@media (max-width: 640px) {
  .select-bar .btn { flex: 1 1 auto; padding: 0 10px; }
  .select-count { flex-basis: 100%; }
}

/* ---------- 共有ダイアログ・共有管理 ---------- */
.modal-card { overflow-y: auto; }
.modal-wide { width: min(680px, 100%); max-height: min(86vh, 720px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }
.modal-card .form-error { min-height: 0; margin: 0; }
.modal-card .form-error:empty { display: none; }

.copy-row { display: flex; gap: 8px; }
.copy-row input[type="text"] { flex: 1; min-width: 0; font-size: 14px; }
.share-status { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.share-status.is-inactive { color: var(--danger); font-weight: 600; }
.share-hint { margin: -4px 0 0; font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.check input { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
input:disabled { opacity: 0.55; cursor: not-allowed; }

.shares-list { display: flex; flex-direction: column; gap: 10px; min-height: 0; overflow-y: auto; }
.share-row {
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2);
}
.share-row-main { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.share-row-main .file-name { margin: 0; -webkit-line-clamp: 1; }
.share-row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.share-row-actions .btn { min-height: 34px; padding: 0 12px; font-size: 13px; }

.badge {
  flex: none; padding: 2px 10px; border-radius: 99px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge-active { border-color: transparent; background: rgba(31, 157, 85, 0.14); color: #1a7f45; }
.badge-expired { border-color: transparent; background: rgba(224, 138, 0, 0.16); color: #a35f00; }
.badge-missing { border-color: transparent; background: var(--danger-soft); color: var(--danger); }
@media (prefers-color-scheme: dark) {
  .badge-active { color: #4ade80; }
  .badge-expired { color: #fbbf24; }
}

/* ---------- Markdown(記号なしの整形表示) ---------- */
.md-scroll {
  width: 100%; height: 100%; overflow: auto;
  padding: 18px 22px; border-radius: 8px;
  background: var(--surface); color: var(--text);
  overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
}
.pdf-wrap .md-scroll { flex: 1; min-height: 0; height: auto; }
.md { max-width: 760px; margin: 0 auto; line-height: 1.75; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.5em 0 0.5em; line-height: 1.35; }
.md h1 { font-size: 1.7em; padding-bottom: 0.25em; border-bottom: 1px solid var(--border); }
.md h2 { font-size: 1.4em; padding-bottom: 0.2em; border-bottom: 1px solid var(--border); }
.md h3 { font-size: 1.2em; }
.md h4, .md h5, .md h6 { font-size: 1em; }
.md h6 { color: var(--muted); }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .md-table { margin: 0 0 1em; }
.md ul, .md ol { padding-left: 1.6em; }
.md li > ul, .md li > ol { margin: 0.25em 0 0; }
.md li input[type="checkbox"] { margin: 0 0.3em 0 -1.2em; vertical-align: middle; }
.md blockquote { padding: 0.2em 1em; border-left: 4px solid var(--accent); color: var(--muted); background: var(--surface-2); border-radius: 0 8px 8px 0; }
.md blockquote > :last-child { margin-bottom: 0; }
.md code { padding: 0.15em 0.4em; border-radius: 6px; background: var(--surface-2); font: 0.9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.md pre { padding: 12px 14px; overflow: auto; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.md pre code { padding: 0; background: transparent; white-space: pre; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md del { color: var(--muted); }
.md .md-table { overflow-x: auto; }
.md table { border-collapse: collapse; min-width: 50%; }
.md th, .md td { padding: 6px 12px; border: 1px solid var(--border); text-align: left; }
.md th { background: var(--surface-2); font-weight: 700; }
.md-toolbar { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.md-toolbar .btn { min-height: 34px; padding: 0 12px; font-size: 13px; }

/* ---------- 共有ページ(/s/...) ---------- */
.share-page { max-width: 900px; }
.share-card {
  padding: 22px;
  border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); box-shadow: var(--shadow);
}
.share-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 16px; }
.share-head .file-icon { flex: none; width: 52px; }
.share-head-text { flex: 1; min-width: 200px; }
.share-title { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.share-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.share-notice { margin: 14px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 14px; }
.share-preview {
  display: flex; align-items: center; justify-content: center;
  height: min(70vh, 640px); margin-top: 16px; padding: 8px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); overflow: hidden;
}
.share-preview img, .share-preview video { max-width: 100%; max-height: 100%; border-radius: 8px; background: #000; }
.share-preview iframe { width: 100%; height: 100%; border: 0; border-radius: 8px; background: #fff; }
.share-preview audio { width: min(560px, 100%); }
.share-preview .pdf-wrap { height: 100%; }
.share-preview .detail-card { box-shadow: none; }
.share-preview .loading { color: var(--muted); }

.share-list { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.share-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
}
.share-item-open { flex: 1; min-width: 0; padding: 0; border: 0; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.share-item-open .file-name { margin: 0; -webkit-line-clamp: 1; }
.share-item .btn { flex: none; min-height: 34px; padding: 0 12px; font-size: 13px; }
.share-item-icon { flex: none; width: 28px; color: var(--accent); }
.share-item-icon.is-file { color: var(--muted); }
.share-item-icon svg { display: block; width: 100%; height: auto; }
.share-foot { margin: 18px 0 0; text-align: center; font-size: 12px; color: var(--muted); }
.share-center { margin: 48px auto 0; text-align: center; }
.detail-card.share-center { box-shadow: var(--shadow); }
.share-error-icon { color: var(--muted); display: flex; justify-content: center; margin-bottom: 8px; }
@media (max-width: 640px) {
  .share-card { padding: 16px; }
  .share-actions { width: 100%; }
  .share-actions .btn { flex: 1; }
  .share-preview { height: 60vh; }
  .share-item .btn { padding: 0 8px; }
  .md-scroll { padding: 14px 14px; }
}
.pdf-wrap > .md-holder { flex: 1; min-height: 0; height: auto; }

/* チェックリストの項目は、箇条書きの点を出さない */
.md li:has(> input[type="checkbox"]) { list-style: none; }
.md li input[type="checkbox"] { margin: 0 0.4em 0 -1.4em; }
/* タップしたときの青いハイライトを消す(選択状態は枠と背景で示す) */
.card, .menu-item, .share-item-open { -webkit-tap-highlight-color: transparent; }
@media (max-width: 640px) {
  #select-button, #shares-button { flex: 1 1 calc(50% - 5px); }
  .toolbar .select-wrap { flex: 1 1 0; min-width: 0; }
}

/* 共有: URLの合言葉入力 */
.slug-row { display: flex; align-items: stretch; border: 1px solid var(--border, #ccc); border-radius: 10px; overflow: hidden; }
.slug-row:focus-within { outline: 2px solid var(--accent, #2563eb); outline-offset: 1px; }
.slug-prefix { display: flex; align-items: center; padding: 0 8px 0 12px; font-size: 13px; opacity: .7; white-space: nowrap; max-width: 50%; overflow: hidden; text-overflow: ellipsis; background: rgba(127,127,127,.1); }
.slug-row input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; padding: 10px 12px; font: inherit; color: inherit; }

/* ゲスト(閲覧のみ)・アカウント */
body.is-guest .owner-only { display: none !important; }
.role-badge { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--accent-soft); color: var(--accent); max-width: 40vw; overflow: hidden; text-overflow: ellipsis; }
.account-section { padding: 14px 0 6px; border-top: 1px solid var(--border); }
.account-section:first-of-type { border-top: 0; padding-top: 4px; }
.account-heading { margin: 0 0 10px; font-size: 15px; }
.guest-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 8px 0 4px; }
.guest-form input[type="text"] { flex: 1 1 200px; min-width: 0; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: inherit; font: inherit; }
.guest-secret { margin: 10px 0; padding: 12px; border-radius: 12px; background: var(--accent-soft); }
.guest-secret input { font-size: 18px; letter-spacing: .06em; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.guest-secret .share-hint { margin-top: 8px; }

/* =====================================================================
   画面サイズ別の見やすさ調整(スマホ / タブレット / PC)
   ===================================================================== */

/* 共通: プレビューの背景は不透明に(後ろのヘッダーが透けて見えていた) */
.viewer { background: #0d1019; }

/* 共通: アカウントなどのフォームは、入力欄どうしに間隔をあける */
#pw-form, .account-section > form { display: flex; flex-direction: column; gap: 12px; }
.account-section > .guest-form { flex-direction: row; flex-wrap: wrap; gap: 10px; }
.account-section { display: flex; flex-direction: column; gap: 10px; }
.account-section > * { margin-top: 0; margin-bottom: 0; }
.account-section .share-hint { margin: 0; }
.account-section .btn-primary { align-self: flex-start; }

/* ---------- PC(広い画面) ---------- */
@media (min-width: 900px) {
  .container { max-width: 1360px; padding: 24px 28px 96px; }
  .topbar { padding-inline: max(20px, calc((100vw - 1360px) / 2 + 28px)); }
  .file-list.grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px; }
  .file-list.list { max-width: 980px; }
  .card { transition: box-shadow 0.15s, transform 0.15s; }
  .card:hover { box-shadow: 0 8px 22px rgba(20, 28, 58, 0.14); }
  /* Markdown: 画面いっぱいに白い板を広げず、読みやすい幅にまとめる */
  .viewer .md-scroll { max-width: 980px; margin-inline: auto; padding: 28px 40px; }
  .viewer-body { padding: 0 24px 12px; }
  .viewer-bar, .viewer-info { padding-inline: 24px; }
  .select-bar { justify-content: center; }
  .select-count { flex: 0 0 auto; margin-right: 16px; }
}
@media (hover: none) { .card:hover { box-shadow: none; transform: none; } }

/* ---------- タブレット ---------- */
@media (min-width: 641px) and (max-width: 899px) {
  .container { padding: 20px 20px 96px; }
  .file-list.grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
  .topbar { padding-inline: 20px; }
}

/* タッチ操作(スマホ・タブレット): 押しやすい大きさに */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .card-actions .btn { min-height: 42px; }
  .menu-item { min-height: 46px; }
  .select-bar .btn { min-height: 44px; }
}

/* ---------- スマホ ---------- */
@media (max-width: 640px) {
  /* 上部: 1行目「ロゴ + アカウント + ログアウト」、2行目「検索」 */
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar .btn { min-height: 38px; padding: 0 10px; font-size: 13px; }
  .brand { font-size: 16px; min-width: 0; }
  .brand span { overflow: hidden; text-overflow: ellipsis; }
  .role-badge { max-width: 34vw; }

  /* ボタン類: 「新フォルダ / 選択 / 共有」を1行に。並び替えは次の行 */
  .toolbar { gap: 8px; margin-bottom: 12px; }
  .toolbar .btn { min-height: 42px; padding: 0 8px; font-size: 13px; gap: 6px; }
  #new-folder-button, #select-button, #shares-button { flex: 1 1 calc(33.3% - 8px); min-width: 0; white-space: nowrap; }
  #new-folder-button svg, #select-button svg, #shares-button svg { display: none; }
  .toolbar .select-wrap { flex: 1 1 calc(100% - 100px); min-width: 0; }
  .toolbar .select-wrap select { width: 100%; }
  .toolbar-spacer { display: none; }

  /* アップロードは、親指で届く右下の丸いボタンに */
  #upload-button {
    position: fixed; z-index: 20;
    right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
    width: 58px; height: 58px; min-height: 58px; padding: 0; border-radius: 50%;
    box-shadow: 0 8px 22px rgba(60, 50, 180, 0.4);
  }
  #upload-button svg { width: 26px; height: 26px; }
  #upload-button .btn-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  body.selecting #upload-button, body.is-guest #upload-button { display: none; }
  .container { padding-bottom: calc(100px + env(safe-area-inset-bottom)); }

  /* プレビュー: ボタンが折り返さないように */
  .viewer-actions { gap: 6px; }
  .viewer-actions .btn { white-space: nowrap; font-size: 13px; padding: 0 4px; min-width: 0; }
  .viewer-info { gap: 8px; }

  /* ダイアログは、画面の下から出るシート型に(親指で操作しやすい) */
  .modal { align-items: end; padding: 0; }
  .modal-card, .modal-wide {
    width: 100%; max-height: 92dvh;
    border-radius: 20px 20px 0 0;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }
  .account-section .btn-primary { align-self: stretch; }
  .guest-form .btn { flex: 1 1 100%; }
}
