:root {
  color-scheme: light;
  --bg: #f8fafc;
  --panel: #ffffff;
  --panel-2: #f1f5f9;
  --line: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
  --accent-light: #eff6ff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.02);
  --shadow: 0 4px 15px rgba(29, 48, 82, 0.06), 0 2px 4px rgba(29, 48, 82, 0.04);
  --shadow-lg: 0 10px 25px rgba(29, 48, 82, 0.08), 0 4px 10px rgba(29, 48, 82, 0.04);
  --radius-sm: 8px;
  --radius: 16px;
  --radius-lg: 24px;
}
* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(circle at top right, #dbeafe 0, transparent 400px),
                    radial-gradient(circle at bottom left, #e0e7ff 0, transparent 400px);
  background-attachment: fixed;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

header, main { width: min(1200px, calc(100% - 32px)); margin: auto; }
header { display: flex; justify-content: space-between; align-items: end; padding: 48px 0 28px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(28px, 4vw, 42px); font-weight: 800; letter-spacing: -0.04em; }
.eyebrow { margin-bottom: 8px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: 0.16em; }
.summary, .count span { color: var(--muted); }
.header-actions { display: flex; gap: 12px; }
.count, .playlist-link { display: grid; padding: 14px 20px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(12px); box-shadow: var(--shadow-sm); text-align: right; text-decoration: none; transition: transform 0.2s, box-shadow 0.2s; }
.count:hover, .playlist-link:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.count strong, .playlist-link strong { font-size: 32px; color: var(--text); }
.playlist-link { border-color: #bfdbfe; color: var(--accent); background: rgba(239, 246, 255, 0.8); }

input[type="search"], input[type="text"], button { font: inherit; border: 1px solid var(--line); border-radius: 999px; min-height: 44px; padding: 0 18px; outline: none; transition: all 0.2s; }
input[type="search"]:focus, input[type="text"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }

.filters { margin-bottom: 32px; padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: rgba(255, 255, 255, 0.7); backdrop-filter: blur(16px); box-shadow: var(--shadow); }
.search-bar input { width: 100%; min-height: 52px; font-size: 16px; border-radius: var(--radius-sm); }
.filter-options { margin-top: 16px; }
.filter-options summary { display: inline-block; cursor: pointer; color: var(--accent); font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.filter-options-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 20px; }
.filter-group { display: flex; flex-direction: column; gap: 8px; }
.filter-group > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.filter-divider { margin: 24px 0 16px; color: var(--accent); font-size: 14px; font-weight: 800; border-top: 1px solid var(--line); padding-top: 16px; }

.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-group.scrollable { max-height: 120px; overflow-y: auto; align-content: flex-start; padding-right: 8px; }
.chip { display: inline-flex; }
.chip input { display: none; }
.chip span { padding: 6px 14px; border-radius: 999px; background: var(--panel-2); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid transparent; transition: all 0.2s; }
.chip:hover span { background: #e2e8f0; }
.chip input:checked + span { background: var(--accent); color: #fff; box-shadow: var(--shadow-sm); }
.exclude .chip input:checked + span { background: #ef4444; color: #fff; }

.filter-actions { display: flex; gap: 12px; margin-top: 24px; justify-content: flex-end; }
button { cursor: pointer; background: var(--panel); color: var(--text); font-weight: 600; }
button:hover { background: var(--panel-2); }
button[type="submit"] { background: var(--accent); color: #fff; border: none; }
button[type="submit"]:hover { background: var(--accent-dark); }
.reset { background: transparent; border: 1px solid transparent; color: var(--muted); }
.reset:hover { background: var(--panel-2); color: var(--text); }

.character-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 20px; margin-bottom: 48px; align-items: stretch; }
.character-card { display: flex; flex-direction: column; height: 100%; min-width: 0; max-width: 100%; overflow: hidden; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); transition: transform 0.2s, box-shadow 0.2s; }
.character-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: #bfdbfe; }
.card-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 16px; min-width: 0; max-width: 100%; }
.character-icon { width: 72px; height: 72px; flex-shrink: 0; border-radius: 14px; object-fit: contain; background: var(--panel-2); }
.card-info { flex: 1; min-width: 0; max-width: 100%; }
.card-info h2 { font-size: 18px; margin: 6px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.card-info p { margin: 0; font-size: 13px; color: var(--muted); }
.badge { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 800; letter-spacing: 0.05em; }
.attribute-赤 { color: #b91c1c; background: #fee2e2; }
.attribute-青 { color: #1d4ed8; background: #dbeafe; }
.attribute-緑 { color: #15803d; background: #dcfce7; }
.attribute-白 { color: #475569; background: #f1f5f9; border: 1px solid #cbd5e1; }
.attribute-黒 { color: #fff; background: #334155; }
.tags-container { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; min-width: 0; max-width: 100%; }
.tag-badge { padding: 3px 8px; border-radius: 6px; background: var(--accent-light); color: var(--accent-dark); font-size: 11px; font-weight: 700; white-space: nowrap; }

.card-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; min-width: 0; max-width: 100%; }
.save-form { display: flex; gap: 8px; width: 100%; min-width: 0; }
.save-form select { flex: 1; min-width: 0; width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--line); padding: 0 10px; font-size: 13px; outline: none; text-overflow: ellipsis; }
.save-form button, .detail-button, .remove-button { padding: 8px 16px; border-radius: var(--radius-sm); font-size: 13px; min-height: 38px; }
.save-form button { flex: 0 0 auto; white-space: nowrap; width: auto; }
.detail-button, .remove-button { width: 100%; }
.detail-button { background: var(--panel-2); border: 1px solid var(--line); }
.detail-button:hover { background: #e2e8f0; }
.remove-button, .danger-button { color: #ef4444; background: #fee2e2; border: none; }
.remove-button:hover { background: #fecaca; }

dialog { width: min(800px, calc(100% - 32px)); max-height: calc(100vh - 40px); overflow-y: auto; padding: 32px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(15, 23, 42, 0.4); backdrop-filter: blur(8px); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.dialog-character { display: flex; gap: 16px; align-items: center; }
.detail-icon { width: 80px; height: 80px; border-radius: 16px; }
.dialog-character h2 { margin: 0; font-size: 24px; }
.close-button { width: 40px; height: 40px; min-height: 40px; border-radius: 50%; padding: 0; display: grid; place-items: center; border: none; background: var(--panel-2); font-size: 20px; color: var(--muted); }
.close-button:hover { background: #e2e8f0; color: var(--text); }
.details { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.details section { padding: 20px; border-radius: var(--radius); background: var(--panel-2); border: 1px solid #e2e8f0; }
.details h3 { margin-bottom: 12px; color: var(--accent); font-size: 14px; }
.details p, .structured-list { margin: 0; color: var(--text); font-size: 14px; line-height: 1.6; word-break: break-word; }
.section-label, .skill-title { font-weight: 700; margin-bottom: 4px; color: var(--text); }
.section-label { color: var(--accent); font-size: 13px; margin-top: 12px; }
.dialog-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
.source { color: var(--accent); font-weight: 600; text-decoration: none; }
.source:hover { text-decoration: underline; }

.empty { text-align: center; padding: 64px 20px; background: rgba(255, 255, 255, 0.5); border-radius: var(--radius-lg); border: 2px dashed var(--line); }
.playlist-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 20px; margin-top: 24px; }
.playlist-card { display: flex; gap: 16px; align-items: center; padding: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); text-decoration: none; transition: transform 0.2s; }
.playlist-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: var(--accent); }
.playlist-card > button:first-child { display: flex; flex: 1; gap: 16px; align-items: center; padding: 0; border: 0; color: var(--text); background: transparent; text-align: left; }
.playlist-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--accent-light); color: var(--accent); font-weight: 800; }
.playlist-card div { flex: 1; }
.playlist-card h2 { margin: 0 0 4px; font-size: 18px; }
.playlist-card p { margin: 0; color: var(--muted); font-size: 14px; }

.playlist-toolbar, .share-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 16px; padding: 20px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.playlist-toolbar div, .share-toolbar div:first-child { display: flex; flex-direction: column; gap: 4px; }
.playlist-toolbar span, .share-toolbar span { color: var(--muted); font-size: 13px; word-break: break-word; }
.playlist-toolbar form, .share-actions { display: flex; gap: 8px; width: 100%; max-width: 400px; }
.playlist-toolbar form input { flex: 1; min-width: 0; border-radius: var(--radius-sm); }
.import-button { display: grid; place-items: center; border: 1px solid var(--accent); border-radius: 999px; color: var(--accent); background: transparent; font-size: 14px; font-weight: 600; cursor: pointer; padding: 0 16px; min-height: 44px; }
.import-button input { display: none; }
.import-button:hover { background: var(--accent-light); }
.share-message { margin: 0 0 16px; color: #15803d; font-size: 13px; font-weight: 700; }
.share-message.error { color: #ef4444; }

body.playlist-index .filters { display: none; }
body:not(.playlist-mode) .share-toolbar, body:not(.playlist-mode) .share-message, body:not(.playlist-mode) main > .playlist-toolbar { display: none; }

.mobile-nav { display: none; }
@media (max-width: 768px) {
  body { padding-bottom: 80px; }
  header, main { width: 100%; padding: 0 16px; }
  header { padding: 32px 16px 24px; flex-direction: column; align-items: stretch; gap: 16px; }
  .header-actions { display: flex; gap: 12px; }
  .count, .playlist-link { flex: 1; text-align: center; padding: 12px; }
  .count strong, .playlist-link strong { font-size: 24px; }
  .filters { margin: 0 -16px 24px; border-radius: 0; border-left: none; border-right: none; position: sticky; top: 0; z-index: 10; padding: 16px; max-height: 100vh; overflow-y: auto; }
  .character-grid { grid-template-columns: 1fr; gap: 16px; }
  .dialog-character { flex-direction: column; align-items: flex-start; gap: 12px; }
  .playlist-toolbar, .share-toolbar { flex-direction: column; align-items: stretch; }
  .playlist-toolbar form, .share-actions { max-width: none; }
  .mobile-nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; padding: 12px 24px calc(12px + env(safe-area-inset-bottom)); background: rgba(255, 255, 255, 0.9); backdrop-filter: blur(16px); border-top: 1px solid var(--line); gap: 16px; }
  .mobile-nav button { flex: 1; min-height: 48px; border-radius: 999px; border: none; background: transparent; color: var(--muted); font-weight: 700; font-size: 14px; }
  .mobile-nav button.active { background: var(--accent-light); color: var(--accent-dark); }
}
