:root {
  --bg-app: #f5f5f7;
  --bg-panel: #ffffff;
  --border-subtle: rgba(15, 23, 42, 0.08);
  --text-main: #111827;
  --text-sub: #4b5563;
  --text-muted: #9ca3af;
  --primary: #3b5bdb;
  --primary-hover: #364fc7;
  --primary-soft: rgba(59, 91, 219, 0.09);
  --radius-md: 12px;
  --radius-lg: 16px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-app);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.topbar-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-sub);
}

.url-form {
  flex: 1;
  max-width: 680px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.url-input-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  background: #f3f4f6;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 3px 6px 3px 12px;
  transition: border-color 0.15s, background 0.15s;
}

.url-input-wrap:focus-within {
  background: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.url-input-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 13.5px;
  color: var(--text-main);
  padding: 6px 0;
  min-width: 0;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.15s ease;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  white-space: nowrap;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #f3f4f6;
  color: var(--text-main);
  font-size: 13.5px;
  font-weight: 500;
  padding: 9px 14px;
  border-radius: 10px;
  white-space: nowrap;
}

.btn-secondary:hover:not(:disabled) {
  background: #e5e7eb;
}

.btn-ghost-sm {
  background: #ffffff;
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-subtle);
}

.btn-ghost-sm:hover {
  color: var(--text-main);
}

.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #f3f4f6;
  color: var(--text-sub);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}

.btn-icon:hover {
  background: #e5e7eb;
  color: var(--text-main);
}

.btn-link {
  background: transparent;
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
  padding: 2px 4px;
}

.btn-link:hover {
  text-decoration: underline;
}

/* Help banner */
.help-banner {
  background: #eef2ff;
  border-bottom: 1px solid rgba(59, 91, 219, 0.16);
  padding: 12px 24px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
  color: #1e293b;
  line-height: 1.6;
}

.help-banner p {
  margin: 4px 0 0 0;
}

.bookmarklet-pill {
  display: inline-block;
  background: #3b5bdb;
  color: #ffffff;
  text-decoration: none;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 999px;
  margin: 0 3px;
}

.btn-close {
  background: transparent;
  color: var(--text-sub);
  font-size: 15px;
  padding: 4px 8px;
}

/* Toast */
.status-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #111827;
  color: #ffffff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
}

.status-toast.error {
  background: #dc2626;
}

/* Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 20px;
  max-width: 1340px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 40px;
  align-items: start;
}

/* Controls Panel */
.controls-panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 98px);
  overflow-y: auto;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.control-group:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.group-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.group-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-sub);
  letter-spacing: 0.03em;
}

.group-hint {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Theme Grid */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.theme-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: #fafafa;
  text-align: left;
}

.theme-option:last-child:nth-child(odd) {
  grid-column: 1 / -1;
  flex-direction: row;
  align-items: center;
}

.theme-option:hover {
  background: #f3f4f6;
}

.theme-option.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.theme-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.theme-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
}

.theme-desc {
  display: none;
}

.theme-swatches {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}

.swatch-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.14);
}

/* Segmented */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: #f3f4f6;
  padding: 3px;
  border-radius: 9px;
  gap: 2px;
}

.segmented.compact {
  min-width: 140px;
}

.seg-btn {
  background: transparent;
  color: var(--text-sub);
  font-size: 12.5px;
  font-weight: 500;
  padding: 6px 8px;
  border-radius: 7px;
}

.seg-btn.active {
  background: #ffffff;
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.row-label {
  font-size: 13px;
  color: var(--text-main);
}

/* Toggles */
.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.toggle-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-main);
  cursor: pointer;
}

.toggle-item.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.toggle-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Turns list */
.turns-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 170px;
  overflow-y: auto;
}

.turn-check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  color: var(--text-sub);
  padding: 7px 9px;
  background: #f9fafb;
  border-radius: 8px;
  cursor: pointer;
}

.turn-check input {
  margin-top: 2px;
  accent-color: var(--primary);
}

.turn-check-text {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

/* Fields */
.field-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--text-sub);
}

.field-item input {
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  color: var(--text-main);
  outline: none;
  background: #fafafa;
}

.field-item input:focus {
  border-color: var(--primary);
  background: #ffffff;
}

/* Preview Stage */
.preview-stage {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.action-bar {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.action-meta {
  font-size: 12.5px;
  color: var(--text-sub);
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.preview-viewport {
  background: #e5e7eb;
  background-image: radial-gradient(rgba(15, 23, 42, 0.07) 1px, transparent 1px);
  background-size: 18px 18px;
  border-radius: var(--radius-lg);
  padding: 28px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 520px;
  overflow-x: auto;
}

.shadow-host {
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.14);
}

/* Paged preview */
.paged-preview-host {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}

.paged-card-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.paged-card-item img {
  width: 280px;
  height: auto;
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
}

.paged-card-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--text-sub);
}

/* Responsive */
@media (max-width: 920px) {
  .workspace {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .controls-panel {
    position: static;
    max-height: none;
  }

  .topbar {
    padding: 12px 14px;
  }
}
