*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:         #1a1a2e;
  --bg2:        #16213e;
  --bg3:        #0f3460;
  --surface:    #1e2a3a;
  --surface2:   #253447;
  --accent:     #e94560;
  --accent2:    #0f8eff;
  --accent-fg:  #ffffff;
  --text:       #e0e0e0;
  --text-muted: #8899aa;
  --text-dim:   #aab8c8;
  --border:     #2a3f5a;
  --border-strong: #3b5274;
  --danger:     #e94560;
  --warn:       #f0a000;
  --ok:         #4ec07a;
  --radius:     6px;
  --radius-lg:  10px;
  --shadow:     0 2px 12px rgba(0,0,0,0.5);
  --font:       'Segoe UI', 'Hiragino Sans', 'Meiryo', 'Noto Sans JP', sans-serif;
  --font-mono:  ui-monospace, SFMono-Regular, 'JetBrains Mono', Menlo, Consolas, 'Noto Sans Mono CJK JP', monospace;
}

[data-theme="light"] {
  --bg:         #f4f6fb;
  --bg2:        #e9eef7;
  --bg3:        #dfe7f2;
  --surface:    #ffffff;
  --surface2:   #eef2f9;
  --accent:     #d72d4e;
  --accent2:    #1972dd;
  --accent-fg:  #ffffff;
  --text:       #1c2233;
  --text-muted: #6a7689;
  --text-dim:   #4a566c;
  --border:     #cdd5e3;
  --border-strong: #aeb9cd;
  --shadow:     0 2px 12px rgba(20,28,55,0.10);
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== TOP BAR ===== */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px;
  height: 44px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .05em;
  white-space: nowrap;
}
.logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff; font-weight: 800; font-size: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
}
.top-spacer { flex: 1; }
.topbar-actions { display: flex; gap: 6px; }

/* ===== BUTTONS ===== */
button {
  font-family: inherit;
}
.btn, .ghost-btn, .about-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 12px; font-weight: 600;
  font-family: inherit;
  transition: background .12s, border-color .12s, color .12s, filter .15s;
  white-space: nowrap; user-select: none;
}
.btn:hover, .ghost-btn:hover, .about-btn:hover {
  background: var(--surface2); border-color: var(--accent2);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary, .btn:not(.btn-secondary):not(.btn-danger):not(.btn-accent):not(.ghost-btn):not(.about-btn) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover, .btn:not(.btn-secondary):not(.btn-danger):not(.btn-accent):not(.ghost-btn):not(.about-btn):hover {
  filter: brightness(1.15);
  background: var(--accent);
  border-color: var(--accent);
}

.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.15); }

.btn-secondary {
  background: var(--surface); border-color: var(--border); color: var(--text);
}
.btn-secondary:hover { background: var(--surface2); border-color: var(--accent2); }

.btn-danger { background: #b03030; border-color: #b03030; color: #fff; }
.btn-danger:hover { filter: brightness(1.15); background: #b03030; }

.about-btn {
  padding: 4px 10px; font-size: 11px;
  color: var(--text-muted); letter-spacing: .04em;
  background: var(--surface);
}
.about-btn:hover { color: var(--text); }

.ghost-btn { padding: 4px 8px; font-size: 11px; min-width: 32px; color: var(--text-muted); }
.ghost-btn:hover { color: var(--text); }

/* ===== PRIVACY BANNER ===== */
.privacy-banner {
  margin: 0; padding: 6px 14px;
  background: rgba(15,142,255,0.08);
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  letter-spacing: .02em;
}

/* ===== TABS ===== */
.tabs {
  display: flex; gap: 2px;
  padding: 6px 12px 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky; top: 44px; z-index: 25;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--text-muted);
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: color .12s, background .12s;
}
.tab:hover { color: var(--text); background: var(--surface); }
.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  border-bottom-color: var(--surface);
  margin-bottom: -1px;
}
.tab-icon { font-size: 13px; line-height: 1; }

/* ===== PANELS / CARDS ===== */
#panels { padding: 14px 14px 60px; max-width: 1200px; margin: 0 auto; }
.panel { animation: fade .15s ease; }
@keyframes fade { from { opacity:0; transform: translateY(2px); } to { opacity:1; transform:none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card h2 {
  margin: 0 0 4px;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
  color: var(--text);
}
.card .desc {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0 0 12px;
}
.section-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  margin: 14px 0 6px;
}

/* ===== SUBTABS ===== */
.subtabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  padding: 3px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}
.subtab {
  flex: 1 1 auto;
  padding: 6px 10px;
  background: transparent; color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 11px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, color .12s, border-color .12s;
}
.subtab:hover { color: var(--text); }
.subtab[aria-selected="true"] {
  background: var(--surface); color: var(--text);
  border-color: var(--border);
}

/* ===== DROPZONE ===== */
.dropzone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg2);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color .12s, background .12s, color .12s;
  position: relative;
}
.dropzone:hover, .dropzone.is-drag {
  border-color: var(--accent2);
  color: var(--text);
  background: var(--surface);
}
.dropzone .dz-icon { font-size: 22px; margin-bottom: 6px; color: var(--accent2); }
.dropzone strong { color: var(--text); font-weight: 600; }
.dropzone input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer;
}

/* ===== FILE LIST ===== */
.filelist {
  list-style: none; padding: 0; margin: 10px 0 0;
  display: flex; flex-direction: column; gap: 4px;
}
.filelist li {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  gap: 8px;
}
.filelist .fl-name { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filelist .fl-meta { color: var(--text-muted); font-size: 11px; flex-shrink: 0; }
.filelist .fl-remove {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 2px 6px; border-radius: 3px; font-size: 14px; line-height: 1;
  transition: color .12s;
}
.filelist .fl-remove:hover { color: var(--accent); background: rgba(233,69,96,.12); }

/* ===== FORM CONTROLS ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin: 8px 0;
}
.form-grid label, .form-row label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; color: var(--text-muted); font-weight: 600;
  letter-spacing: .02em;
}
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin: 6px 0; }

select, input[type=text], input[type=number], input[type=password], input[type=url], input[type=search], textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  font-size: 12px;
  font-family: inherit;
  transition: border-color .12s, box-shadow .12s;
}
textarea {
  font-family: var(--font-mono);
  min-height: 130px; resize: vertical;
  line-height: 1.5;
}
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent2);
  box-shadow: 0 0 0 2px rgba(15,142,255,.25);
}
input[type=color] {
  width: 36px; height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer; background: none; padding: 1px;
}
input[type=range] { flex: 1; accent-color: var(--accent2); }
input[type=checkbox] { accent-color: var(--accent2); cursor: pointer; }

.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text); font-weight: 500;
  cursor: pointer; user-select: none;
}
.checkbox-row input[type=checkbox] { width: 14px; height: 14px; }

.range-with-value { display: flex; align-items: center; gap: 8px; }
.range-with-value output {
  min-width: 44px; text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted); font-size: 11px;
}

/* ===== ACTIONS ===== */
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }

/* ===== PROGRESS ===== */
.progress { margin-top: 12px; display: none; }
.progress.active { display: block; }
.progress-bar {
  height: 6px; background: var(--bg2);
  border-radius: 999px; overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar > span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width .2s;
}
.progress-bar.indeterminate > span {
  width: 30% !important;
  animation: indet 1.4s infinite ease-in-out;
}
@keyframes indet {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
.progress-label {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-muted);
  margin-top: 5px;
}

/* ===== RESULT LIST ===== */
.results { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.result-item {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  gap: 8px;
}
.result-item .ri-info { min-width: 0; }
.result-item .ri-name { font-weight: 600; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.result-item .ri-meta { color: var(--text-muted); font-size: 11px; }
.result-item .ri-actions { display: flex; gap: 6px; flex-shrink: 0; }

.preview-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  min-height: 80px;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
}
.preview-box img, .preview-box video, .preview-box canvas {
  max-width: 100%; max-height: 480px;
  border-radius: 4px;
  background: repeating-conic-gradient(#3a4862 0% 25%, #2a3242 0% 50%) 0 0/16px 16px;
}
[data-theme="light"] .preview-box img,
[data-theme="light"] .preview-box video,
[data-theme="light"] .preview-box canvas {
  background: repeating-conic-gradient(#cdd5e3 0% 25%, #ecf0f7 0% 50%) 0 0/16px 16px;
}

/* ===== TOAST ===== */
#toast-host {
  position: fixed; bottom: 18px; right: 18px; z-index: 100;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 12px;
  pointer-events: auto;
  animation: slideIn .2s ease;
}
.toast.error { border-color: var(--accent); }
.toast.ok    { border-color: var(--ok); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}

/* ===== FOOTER ===== */
.footer {
  text-align: center;
  color: var(--text-muted);
  padding: 18px 14px 28px;
  font-size: 11px;
}
.footer .dot { margin: 0 5px; opacity: .5; }

/* ===== TWO-COLUMN TEXTAREA ===== */
.text-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.text-cols textarea { min-height: 220px; }
@media (max-width: 720px) { .text-cols { grid-template-columns: 1fr; } }

/* ===== PILL / MISC ===== */
.pill {
  display: inline-block;
  padding: 1px 7px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10px; font-weight: 600;
  color: var(--text-muted);
}
.pill.beta { color: var(--warn); border-color: var(--warn); }

/* ===== SPINNER ===== */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--text-muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== HELPERS ===== */
.hidden { display: none !important; }
.muted  { color: var(--text-muted); }
.mono   { font-family: var(--font-mono); font-size: 11px; }

/* ===== VIDEO TRIMMER ===== */
.trimmer { margin-top: 8px; }
.tl-wrap { margin-top: 12px; padding: 12px 4px 6px; }
.tl-track {
  position: relative;
  height: 32px;
  background: linear-gradient(180deg, var(--bg2) 0%, var(--bg) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  touch-action: none;
}
.tl-track:focus { outline: 2px solid var(--accent2); outline-offset: 2px; }
.tl-fill {
  position: absolute; top: 0; bottom: 0;
  background: rgba(15,142,255,0.22);
  border-left: 2px solid var(--accent2);
  border-right: 2px solid var(--accent2);
  pointer-events: none;
}
.tl-handle {
  position: absolute;
  top: -7px; bottom: -7px;
  width: 12px;
  margin-left: -6px;
  background: var(--accent2);
  border: 1px solid #094a85;
  border-radius: 3px;
  cursor: ew-resize;
  box-shadow: 0 2px 6px rgba(0,0,0,.45);
  z-index: 2;
  touch-action: none;
}
.tl-handle:hover, .tl-handle:focus { background: #34a4ff; outline: none; }
.tl-handle::before {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 2px; height: 14px;
  background: rgba(255,255,255,.9);
  border-radius: 1px;
}
.tl-handle.tl-start::after,
.tl-handle.tl-end::after {
  content: '';
  position: absolute;
  bottom: 100%; left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-bottom-color: var(--accent2);
}
.tl-playhead {
  position: absolute; top: -5px; bottom: -5px;
  width: 2px; margin-left: -1px;
  background: var(--accent);
  pointer-events: none;
  z-index: 3;
  box-shadow: 0 0 4px rgba(0,0,0,.7);
}
.tl-playhead::before {
  content: '';
  position: absolute;
  top: -5px; left: 50%;
  transform: translateX(-50%);
  width: 9px; height: 9px;
  background: var(--accent);
  border: 1px solid #6a0a1f;
  border-radius: 50%;
}
.tl-time-row {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
  letter-spacing: .02em;
}
.tl-actions { flex-wrap: wrap; }
.tl-actions .btn { padding: 5px 9px; font-size: 11px; font-weight: 600; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 200;
  align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeOverlay .15s ease;
}
.modal-overlay.is-open { display: flex; }
@keyframes fadeOverlay { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  width: min(580px, 95vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
  animation: popIn .18s ease;
}
@keyframes popIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }

.modal-box h2 {
  font-size: 16px;
  color: var(--accent2);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin: 0;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: auto;
}

/* ===== WELCOME / ABOUT MODAL ===== */
.welcome-box { width: min(620px, 95vw); }

.welcome-header {
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.welcome-title {
  font-size: 28px; font-weight: 800;
  color: var(--accent);
  letter-spacing: .04em;
  margin-bottom: 2px;
}
.welcome-version { font-size: 11px; color: var(--text-muted); }

.welcome-section { display: flex; flex-direction: column; gap: 8px; }
.welcome-section h3 {
  font-size: 12px; font-weight: 700;
  color: var(--accent2);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  text-transform: uppercase; letter-spacing: .04em;
  margin: 0;
}
.welcome-howto {
  list-style: none;
  display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; color: var(--text);
  padding-left: 4px;
  line-height: 1.55;
}
.welcome-howto li::before { content: '▸ '; color: var(--accent2); }
.welcome-howto b { color: var(--accent2); font-weight: 700; }

.welcome-shortcuts {
  border-collapse: collapse;
  font-size: 12px; width: 100%; margin-top: 4px;
}
.welcome-shortcuts td {
  padding: 3px 10px 3px 0;
  color: var(--text); vertical-align: middle;
}
.welcome-shortcuts td:first-child { white-space: nowrap; width: 180px; }

kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px; font-family: inherit;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
}

/* Author cards */
.author-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.author-card {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  flex: 1; min-width: 180px;
}
.author-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface2);
}
.author-info  { display: flex; flex-direction: column; gap: 4px; }
.author-name  { font-size: 13px; font-weight: 700; color: var(--text); }
.author-link  { font-size: 11px; color: var(--accent2); text-decoration: none; }
.author-link:hover { text-decoration: underline; }

/* ===== SCROLLBARS ===== */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar       { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
