/* frank pro — 基本スタイル
   方針: Apple Human Interface Guidelines の考え方を参考にする（配布リソースは使わない）。
   フォントは -apple-system 指定。アイコンは Lucide（SF Symbolsは使わない）。
   docs/frank-pro-handoff.md 6章 / docs/security-design.md
*/

:root {
  color-scheme: light dark;

  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --border: rgba(0, 0, 0, 0.08);
  --accent: #0071e3;
  --accent-contrast: #ffffff;
  --star-filled: #ff9f0a;
  --star-empty: #d2d2d7;
  --danger: #ff3b30;
  --overlay: rgba(0, 0, 0, 0.4);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 8px 24px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-elevated: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #0a84ff;
    --star-empty: #48484a;
    --overlay: rgba(0, 0, 0, 0.6);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

img { max-width: 100%; display: block; }

.icon {
  width: 1em;
  height: 1em;
  stroke: currentColor;
  fill: none;
  vertical-align: -0.15em;
}

/* ============ ヘッダー ============ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 999px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
}
.btn-icon {
  padding: 8px;
  border-radius: 999px;
  aspect-ratio: 1;
}

/* ============ 並べ替えタブ ============ */

.sort-tabs {
  display: flex;
  gap: 8px;
  padding: 12px max(16px, env(safe-area-inset-left));
  overflow-x: auto;
  scrollbar-width: none;
}
.sort-tabs::-webkit-scrollbar { display: none; }

.sort-tab {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
}
.sort-tab[aria-selected="true"] {
  background: var(--text);
  color: var(--bg);
  border-color: transparent;
}

/* ============ グリッド一覧 ============ */

.work-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  padding: 8px max(16px, env(safe-area-inset-left)) 48px;
  max-width: 1200px;
  margin: 0 auto;
}

.work-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform 0.2s ease;
}
.work-card:hover { transform: translateY(-2px); }
.work-card:active { transform: scale(0.98); }

.work-thumb-wrap {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--surface-elevated);
  /* タイルを小さなブラウザ窓の見た目にする（mado.htmlデモを踏襲） */
  border-bottom: 1px solid var(--border);
}
.work-thumb-wrap::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.work-thumb-wrap::after {
  content: "● ● ●";
  position: absolute;
  top: 3px; left: 8px;
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--text-secondary);
  z-index: 2;
}
.work-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  padding-top: 20px;
  box-sizing: border-box;
  background: linear-gradient(135deg, #d1d1d6, #f5f5f7);
}
.played-badge {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 2;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 3px;
  backdrop-filter: blur(6px);
}

.work-meta {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.work-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.work-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
}
.work-stats .stars { color: var(--star-filled); }

.empty-state, .loading-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 64px 16px;
  color: var(--text-secondary);
}

/* ============ 作品プレイヤー（モーダル） ============ */

.player-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 100;
  display: flex;
  flex-direction: column;
}
.player-overlay[hidden] { display: none; }

.player-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px max(12px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.player-title {
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-frame-wrap {
  flex: 1;
  background: #000;
  position: relative;
}
.player-frame-wrap iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.player-sheet {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-bottom));
  max-height: 40vh;
  overflow-y: auto;
}

/* ============ 星評価 ============ */

.rating-widget {
  display: flex;
  align-items: center;
  gap: 4px;
}
.rating-widget button {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  color: var(--star-empty);
}
.rating-widget button.filled { color: var(--star-filled); }
.rating-summary {
  font-size: 13px;
  color: var(--text-secondary);
  margin-left: 8px;
}

/* ============ コメント ============ */

.comment-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 16px 0;
}
.comment-form input[type="text"],
.comment-form textarea {
  font: inherit;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  color: var(--text);
  resize: vertical;
}
.comment-form textarea { min-height: 64px; }

.comment-list { display: flex; flex-direction: column; gap: 12px; }
.comment-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
}
.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.comment-name { font-weight: 700; color: var(--text); }
.comment-body { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.comment-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
  font-size: 11px;
}
.comment-actions button {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: underline;
}

/* ============ フォーム全般（投稿画面など） ============ */

.form-page {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-left)) 64px;
}
.form-field { margin-bottom: 20px; }
.form-field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
}
.form-field input[type="text"],
.form-field textarea {
  width: 100%;
  font: inherit;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.form-hint { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.form-hint.warn { color: #ff9f0a; }
.form-hint.error { color: var(--danger); }

/* 縦持ちプレビュー枠（投稿ガイドライン 1-5節） */
.mobile-preview {
  width: 100%;
  max-width: 300px;
  aspect-ratio: 375 / 667;
  margin: 0 auto 12px;
  border-radius: 24px;
  overflow: hidden;
  border: 6px solid var(--text);
  background: #000;
  position: relative;
}
.mobile-preview iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.checklist { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.checklist label { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; }
.checklist input[type="checkbox"] { margin-top: 3px; }

/* ============ 静的ページ（規約・ガイドライン） ============ */

.doc-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px max(16px, env(safe-area-inset-left)) 64px;
  line-height: 1.8;
}
.doc-page h1 { font-size: 26px; margin-bottom: 8px; }
.doc-page h2 { font-size: 18px; margin-top: 32px; }
.doc-page table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; }
.doc-page th, .doc-page td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.doc-page code { background: var(--surface-elevated); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; }
.doc-page pre { background: var(--surface-elevated); padding: 12px; border-radius: var(--radius-sm); overflow-x: auto; }
.doc-note {
  background: var(--surface-elevated);
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  margin: 16px 0;
}

footer.site-footer {
  text-align: center;
  padding: 32px 16px 64px;
  font-size: 12px;
  color: var(--text-secondary);
}
footer.site-footer a { margin: 0 8px; }
