@import url('../vendor/fonts/google-sans.css');
:root {
  font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  color: #1f2328;
  background: #f1f3f6;
  font-synthesis: none;
  --panel: #ffffff;
  --surface: #f7f8fa;
  --surface-hover: #eef1f5;
  --line: #e4e7ec;
  --border: #d0d5dd;
  --muted: #5f6672;
  --accent: #1a73e8;
  --accent-ink: #ffffff;
  --pill-active: #ffffff;
  --badge-current: #1a73e8;
}
* { box-sizing: border-box; }
body { margin: 0; height: 100dvh; overflow: hidden; background: #f1f3f6; color: #1f2328; }
button, input, select, textarea { font: inherit; }
button, select, input[type=range] { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--surface);
  color: #1f2328;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, border-color .15s;
}
button:hover:not(:disabled) { background: var(--surface-hover); border-color: #b8c0cc; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary-btn, #export, #confirm-preset {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
  font-weight: 500;
}
button.primary-btn:hover:not(:disabled), #export:hover:not(:disabled), #confirm-preset:hover:not(:disabled) {
  background: #155fc8;
}
input, select, textarea {
  color: #1f2328;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  font-size: 13px;
}
input:hover, select:hover, textarea:hover { border-color: #b0b7c3; }
input[type=range] { padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
textarea { resize: vertical; min-height: 68px; line-height: 1.45; }
label { display: block; font-size: 12px; color: #4b5563; margin-bottom: 7px; }

#app { height: 100%; display: flex; padding: 12px; gap: 12px; }
aside {
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(16, 24, 40, .06);
  overflow: hidden;
}
.brand {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  width: 30px;
  height: 30px;
  padding: 5px;
  border-radius: 50%;
  background: #f8f9fb;
  border: 1px solid var(--line);
  object-fit: contain;
}
.brand strong { display: block; font-size: 15px; font-weight: 500; letter-spacing: -.01em; color: #111827; }
.brand small { font-size: 11px; color: var(--muted); }

.settings {
  overflow-y: auto;
  padding: 0 18px;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: #cfd5e0 transparent;
}
.section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; padding-bottom: 22px; }
.section h2 {
  font-weight: 500;
  font-size: 13px;
  color: #111827;
  margin: 0 0 14px;
  letter-spacing: -.01em;
}
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-title-row h2 {
  margin: 0;
}
.field { margin-top: 14px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

/* Layout Card */
.layout-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
}
.ratio-box {
  width: 44px;
  height: 26px;
  background: #e4e7ec;
  border: 1px solid #98a2b3;
  border-radius: 3px;
  flex-shrink: 0;
  transition: width .15s, height .15s;
}
.layout-select-wrap { flex: 1; min-width: 0; }
.layout-select-wrap select {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: 13px;
  font-weight: 500;
  color: #111827;
}
.layout-select-wrap select:focus-visible { outline: none; }
.layout-select-wrap small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* Pill Segmented Control */
.segmented {
  display: flex;
  gap: 3px;
  background: #eef1f5;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.segmented button {
  flex: 1;
  border: 0;
  border-radius: 999px;
  font-size: 12px;
  padding: 7px 6px;
  background: transparent;
  color: #4b5563;
}
.segmented button:hover:not(:disabled) { color: #111827; background: transparent; }
.segmented button[aria-pressed=true] {
  background: var(--pill-active);
  color: #111827;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}
.segmented.segmented-sm {
  padding: 2px;
  gap: 2px;
}
.segmented.segmented-sm button {
  font-size: 11px;
  padding: 3px 8px;
  font-weight: 500;
}

/* Preset Card Trigger */
.preset-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  text-align: left;
}
.preset-trigger img {
  width: 68px;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 4px;
  background: #ffffff;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.preset-trigger strong { display: block; font-size: 13px; font-weight: 500; color: #111827; }
.preset-trigger small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.hint { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 8px 0 0; }
.hint:empty { display: none; }
.check { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: #374151; gap: 10px; }
.check input { flex: none; }
.full { width: 100%; margin-top: 10px; }
.footer-aside {
  font-size: 11px;
  color: var(--muted);
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 7px;
  background: #fafbfc;
}
.info-dot { font-size: 12px; color: #6b7280; }
summary { font-size: 13px; font-weight: 500; cursor: pointer; color: #111827; }
details .field { margin-top: 12px; }

#workspace {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: #f5f6f8;
  border: 1px solid var(--line);
  overflow: hidden;
}
.topbar {
  height: 58px;
  flex-shrink: 0;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}
.topbar strong { font-size: 13px; font-weight: 500; color: #111827; }
.topbar small { display: block; margin-top: 2px; font-size: 11px; color: var(--muted); }
.badge {
  font-size: 10px;
  letter-spacing: .08em;
  color: #374151;
  background: #f1f3f6;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px;
}
#canvas-container {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 36px;
  overflow: hidden;
  background: #eef0f4;
}
#canvas-container canvas {
  display: block;
  object-fit: contain;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 8px 28px rgba(16, 24, 40, .12), 0 1px 4px rgba(16, 24, 40, .08);
  touch-action: none;
}
.bottom-bar {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  background: #ffffff;
}
.bottom-bar .actions { display: flex; gap: 8px; align-items: center; }
.bottom-bar select { width: auto; max-width: 245px; }
#status { font-size: 11px; color: #374151; line-height: 1.45; max-width: 500px; }
.warning { color: #b45309 !important; }
#toast {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, .96);
  padding: 11px 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  color: #111827;
  max-width: 85%;
  z-index: 5;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .14);
}
#toast:empty { display: none; }
.hidden { display: none !important; }
.inline-editor, .rich-text-toolbar, #mode-toggle, .google-sans-enforcer { display: none !important; }
.lil-gui { display: none !important; }
#custom-size { margin-top: 10px; }
#export-info { font-size: 10px; color: var(--muted); margin-top: 3px; }
a { color: #1a73e8; }
#load-error { padding: 30px; max-width: 500px; font-size: 14px; color: #b45309; }
.subhead { display: flex; justify-content: space-between; align-items: center; margin: 16px 0 8px; }
.subhead label { margin: 0; }
#text-info { margin-top: 10px; }
#media-label { display: block; margin-top: 8px; overflow-wrap: anywhere; }
#download-area a { display: inline-block; font-size: 11px; margin: 3px 0 4px; color: #1a73e8; }
.exporting #canvas-container canvas { pointer-events: none; }
input[readonly] { opacity: .6; cursor: default; }

/* Preset Dialog */
dialog {
  color: #111827;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(980px, 94vw);
  max-height: 90dvh;
  padding: 24px 28px;
  box-shadow: 0 24px 64px rgba(16, 24, 40, .22);
}
dialog::backdrop { background: rgba(16, 24, 40, .35); backdrop-filter: blur(4px); }
.dialog-heading {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 22px;
}
.dialog-heading h2 { margin: 0; font-size: 18px; font-weight: 500; color: #111827; }
.text-close {
  background: transparent;
  border: 0;
  color: #4b5563;
  font-size: 13px;
  padding: 6px 10px;
}
.text-close:hover { color: #111827; background: var(--surface); }
.preset-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.preset-card {
  position: relative;
  text-align: center;
  padding: 12px 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.preset-card:hover { border-color: #b0b7c3; background: var(--surface-hover); }
.preset-card[aria-pressed=true] {
  border-color: var(--accent);
  background: #f0f6ff;
  box-shadow: 0 0 0 1px var(--accent);
}
.preset-card img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: contain;
  border-radius: 4px;
  background: #ffffff;
  border: 1px solid var(--line);
}
.preset-card strong { font-size: 13px; font-weight: 500; color: #111827; margin-top: 2px; }
.preset-card small { font-size: 11px; color: var(--muted); }
.preset-tag {
  position: absolute;
  top: 18px;
  right: 18px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .06em;
  padding: 3px 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, .9);
  color: #374151;
}
.preset-card.is-current { border-color: var(--badge-current); }
.preset-card.is-current .preset-tag {
  background: var(--badge-current);
  color: #ffffff;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* Video Editor Dialog */
#video-editor-dialog {
  width: min(680px, 94vw);
}
.video-editor-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.video-editor-preview-wrap {
  width: 100%;
  height: 320px;
  background: #101218;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
}
.video-editor-preview-wrap video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.video-timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  color: #374151;
  margin-bottom: 8px;
}
.video-timeline-track {
  position: relative;
  height: 54px;
  background: #e4e7ec;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  user-select: none;
  touch-action: none;
  cursor: pointer;
}
.video-timeline-thumbs {
  position: absolute;
  inset: 0;
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
.video-timeline-thumbs canvas,
.video-timeline-thumbs img {
  flex: 1;
  height: 100%;
  object-fit: cover;
  min-width: 0;
  pointer-events: none;
}
.video-timeline-dim {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(16, 24, 40, .58);
  pointer-events: none;
  z-index: 1;
}
.video-timeline-dim.left { left: 0; }
.video-timeline-dim.right { right: 0; }
.video-timeline-window {
  position: absolute;
  top: 0;
  bottom: 0;
  border: 3px solid var(--accent);
  border-radius: 7px;
  background: rgba(26, 115, 232, .12);
  box-shadow: 0 2px 10px rgba(16, 24, 40, .24);
  z-index: 2;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 5px;
}
.video-timeline-window:active { cursor: grabbing; }
.video-window-grip {
  width: 3px;
  height: 22px;
  border-radius: 99px;
  background: var(--accent);
  opacity: .85;
}
.video-window-duration {
  font-size: 11px;
  font-weight: 600;
  color: #ffffff;
  background: rgba(16, 24, 40, .72);
  padding: 2px 7px;
  border-radius: 999px;
  pointer-events: none;
}

@media(max-width: 1000px) {
  aside { width: 290px; }
  .topbar { padding: 0 18px; }
  .bottom-bar { padding: 12px 18px; flex-wrap: wrap; }
  #canvas-container { padding: 24px; }
  .bottom-bar .actions { margin-left: auto; }
}
@media(max-width: 700px) {
  body { overflow: auto; height: auto; }
  #app { flex-direction: column-reverse; height: auto; padding: 8px; }
  aside { width: 100%; max-height: none; }
  #workspace { height: 62dvh; min-height: 400px; position: sticky; top: 0; z-index: 2; }
  .preset-cards { grid-template-columns: 1fr; }
  dialog { padding: 18px; }
}
