:root {
  --bg: #f7f4ec;
  --surface: #ffffff;
  --navy: #0f172a;
  --teal: #2f7f8a;
  --coral: #e0624d;
  --muted: #64748b;
  --border: #e2dfd5;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--navy);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 54px;
  padding: 0 16px;
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: 0.05em; }
.brand-sub { color: #5eead4; font-weight: 700; }
.top-actions { display: flex; align-items: center; gap: 8px; }

.badge {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #1e293b;
  color: #cbd5e1;
}
.badge.ok { background: #134e4a; color: #5eead4; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--navy);
  padding: 7px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.lg { padding: 11px 20px; font-size: 15px; }
.icon-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.mobile-only { display: none; }

.shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-head h2 { margin: 0; font-size: 14px; color: var(--muted); }
.episode-list { flex: 1; overflow-y: auto; padding: 8px; }
.ep-item {
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 6px;
  border: 1px solid transparent;
}
.ep-item:hover { background: var(--bg); }
.ep-item.active { background: #e6f3f5; border-color: var(--teal); }
.ep-item-title { font-weight: 700; font-size: 14px; margin-bottom: 3px; }
.ep-item-sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.pill {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--navy);
}
.pill.short { background: #fcece9; color: var(--coral); }
.empty-hint { padding: 16px; font-size: 13px; color: var(--muted); line-height: 1.6; }

.workspace { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.welcome {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.welcome-card {
  max-width: 540px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
}
.welcome-card h1 { margin: 0 0 12px; font-size: 22px; }
.welcome-card p { color: #334155; line-height: 1.7; font-size: 14px; }
.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.small-note { font-size: 12px; color: var(--muted); margin-top: 14px; }

.episode-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ep-header {
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.ep-header h1 { margin: 0; font-size: 18px; }
.ep-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tabs { display: flex; gap: 6px; }
.tab {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--navy);
  padding: 6px 12px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.tab.active { background: var(--navy); border-color: var(--navy); color: #fff; }

.loading-bar {
  padding: 8px 18px;
  background: #e6f3f5;
  color: var(--teal);
  font-size: 13px;
  font-weight: 600;
}

.tab-panel { display: none; flex: 1; min-height: 0; }
.tab-panel.active { display: flex; flex-direction: column; }

.sb-frame { flex: 1; width: 100%; border: none; background: #111; }

.video-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: #0f172a;
}
.video-container video,
.video-container iframe {
  max-width: 100%;
  max-height: 100%;
  border-radius: 12px;
  border: none;
}

.script-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
}
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.panel-card h3 { margin: 0; font-size: 15px; }
.script-line {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
  line-height: 1.6;
}
.script-line .spk { font-weight: 700; color: var(--teal); margin-right: 6px; }
.script-line .spk.saaya { color: var(--coral); }

.memo-form { display: flex; flex-direction: column; gap: 8px; }
.memo-form input, .memo-form textarea, .modal-card input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-size: 13px;
}
.memo-item {
  padding: 10px;
  border-radius: 8px;
  background: var(--bg);
  font-size: 13px;
}
.memo-item-head { font-size: 11px; color: var(--muted); margin-bottom: 4px; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h2 { margin: 0; font-size: 18px; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.hidden { display: none !important; }

@media (max-width: 820px) {
  .mobile-only { display: inline-block; }
  .sidebar {
    position: fixed;
    top: 54px;
    bottom: 0;
    left: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .script-grid { grid-template-columns: 1fr; }
}
