.side-tab,
.btn,
.icon-btn { min-height: 44px; }

.side-tab svg,
.btn svg,
.icon-btn svg { flex: none; }

.tool-section,
.panel-content,
.status-line { min-width: 0; }

.status-line { gap: 8px; }
.status-line code { overflow: hidden; text-overflow: ellipsis; }
.member-row { min-height: 56px; overflow: hidden; }
.member-row strong,
.member-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.canvas-wrap { overflow: hidden; }
.canvas-wrap canvas { user-select: none; -webkit-user-select: none; }
.form-actions { padding-bottom: env(safe-area-inset-bottom); }

.feature-group {
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.feature-group-head { display: flex; align-items: flex-start; gap: 11px; margin-bottom: 14px; }
.feature-group-head > svg { width: 19px; height: 19px; margin-top: 1px; color: var(--accent); flex: none; }
.feature-group-head h4 { margin: 0 0 2px; font-size: 14px; }
.feature-group-head p { margin: 0; color: var(--muted); font-size: 12px; }
.status-list { display: grid; gap: 1px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.status-list > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--panel-2); font-size: 13px; }
.status-list span { color: var(--muted); }
.setting-note { display: block; margin: -5px 0 12px; color: #838b9d; font-size: 11px; line-height: 1.45; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.panel-actions .btn:disabled { opacity: .42; cursor: not-allowed; }
.danger-zone { border-color: rgba(237, 66, 69, .35); }
.danger-note { display: flex; gap: 8px; align-items: center; margin: 4px 0 14px; color: #ffb3b5; font-size: 12px; }
.danger-note svg { width: 16px; height: 16px; flex: none; }
.card-carousel { display: grid; grid-template-columns: 44px minmax(150px, auto) 44px; align-items: center; gap: 8px; }
.card-carousel strong { text-align: center; font-size: 13px; }
.studio-controls { align-content: start; }
.studio-controls > section { padding-bottom: 12px; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.studio-controls h4 { margin: 0 0 10px; font-size: 13px; }
.upload-grid { display: grid; gap: 8px; }
.upload-drop {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 68px;
  margin: 0;
  padding: 11px 12px;
  border: 1px dashed #454d5f;
  border-radius: 7px;
  background: #20242d;
  color: var(--ink);
  cursor: pointer;
  transition: border-color .16s ease, background-color .16s ease, box-shadow .16s ease;
}
.upload-drop:hover,
.upload-drop.dragging,
.upload-drop:focus-within { border-color: #7c86ff; background: #252a36; box-shadow: 0 0 0 3px rgba(88, 101, 242, .14); }
.upload-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-drop > svg { width: 22px; height: 22px; flex: none; color: #aeb5ff; }
.upload-drop > span { display: grid; min-width: 0; gap: 2px; }
.upload-drop strong { font-size: 12px; }
.upload-drop small { color: var(--muted); font-size: 11px; line-height: 1.35; }
.upload-note { margin: 8px 2px 0; color: #838b9d; font-size: 10px; }
.frame-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.frame-preset { display: grid; place-items: center; gap: 4px; min-height: 72px; padding: 6px; border: 1px solid var(--line); border-radius: 7px; background: #20242d; color: var(--muted); cursor: pointer; font: 600 11px inherit; }
.frame-preset:hover { border-color: #50596d; color: var(--ink); }
.frame-preset.active { border-color: #7c86ff; background: #282d3c; color: #fff; box-shadow: 0 0 0 2px rgba(88, 101, 242, .16); }
.frame-preset img { width: 42px; height: 42px; object-fit: contain; }
.frame-preset svg { width: 27px; height: 27px; }
.frame-position-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 9px; }
.frame-position-actions .btn { justify-content: center; padding-inline: 8px; }
.role-frame-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 14px; }
.role-frame-head > div { display: grid; gap: 1px; }
.role-frame-head strong { font-size: 12px; }
.role-frame-head small { color: var(--muted); font-size: 10px; }
.role-frame-list { display: grid; gap: 7px; margin-top: 8px; }
.role-frame-row { display: grid; grid-template-columns: minmax(0, 1fr) 92px 44px; gap: 7px; align-items: center; }
.role-frame-row select { min-width: 0; margin: 0; font-size: 12px; }
.role-frame-empty { margin: 8px 0 0; }
.inline-add { display: grid; grid-template-columns: 1fr 44px; gap: 8px; }
.inline-add input { margin: 0; }
.element-controls { min-height: 100px; }

@media (min-width: 981px) {
  body.visuals-active main { max-width: 1500px; padding-left: 28px; padding-right: 28px; }
  body.visuals-active .studio-layout { grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; }
  body.visuals-active .studio-canvas { min-height: 590px; padding: 18px; }
  body.visuals-active .studio-canvas canvas { width: 100%; max-height: none; }
  body.visuals-active .studio-controls { padding: 16px; }
}

/* Unified form controls and animated switches. */
select,
textarea,
input[type="text"],
input[type="number"],
input[type="search"],
input:not([type]) {
  min-height: 42px;
  width: 100%;
  margin-top: 6px;
  padding: 9px 11px;
  border: 1px solid #343946;
  border-radius: 7px;
  background: #20242d;
  color: var(--ink);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Noto Sans", sans-serif;
  font-variant-ligatures: normal;
  text-transform: none;
  transition: border-color .16s ease, background-color .16s ease, box-shadow .16s ease;
}
textarea { min-height: 112px; line-height: 1.55; resize: vertical; }
select:hover,
textarea:hover,
input:hover { border-color: #444b5c; }
select:focus,
textarea:focus,
input:focus {
  outline: 0;
  border-color: #7c86ff;
  background: #242935;
  box-shadow: 0 0 0 3px rgba(88, 101, 242, .2);
}
input::placeholder,
textarea::placeholder { color: #737b8d; opacity: 1; }
select option { font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Apple Color Emoji", "Noto Sans", sans-serif; }

.toggle-line input[type="checkbox"] {
  position: relative;
  width: 46px;
  height: 26px;
  flex: 0 0 46px;
  margin: 0;
  border: 1px solid #3a404d;
  border-radius: 13px;
  appearance: none;
  -webkit-appearance: none;
  background: #2a2f39;
  cursor: pointer;
  transition: background-color .2s ease, border-color .2s ease;
}
.toggle-line input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #c6cad3;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  transition: transform .2s cubic-bezier(.2, .8, .2, 1), background-color .2s ease;
}
.toggle-line input[type="checkbox"]:checked { border-color: #6672f5; background: #5865f2; }
.toggle-line input[type="checkbox"]:checked::after { transform: translateX(20px); background: #fff; }
.toggle-line input[type="checkbox"]:focus-visible { outline: 3px solid rgba(88, 101, 242, .3); outline-offset: 2px; }

.field-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.help-btn {
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-2);
  color: var(--muted);
  font: 700 13px/1 inherit;
  cursor: pointer;
}
.help-btn:hover { border-color: var(--accent); color: var(--ink); }
.help-dialog { width: min(420px, calc(100vw - 28px)); padding: 0; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); }
.help-dialog::backdrop { background: rgba(3, 5, 8, .72); backdrop-filter: blur(3px); }
.help-dialog header { display: flex; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line); }
.help-dialog h4,.help-dialog p { margin: 0; }
.help-dialog p { color: var(--muted); font-size: 12px; }
.help-dialog dl { margin: 0; padding: 8px 16px 16px; }
.help-dialog dl > div { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.help-dialog dt { color: #aeb5ff; font: 600 13px ui-monospace, SFMono-Regular, Menlo, monospace; }
.help-dialog dd { margin: 0; color: var(--muted); font-size: 13px; }

@media (max-width: 980px) {
  .workspace { grid-template-columns: 150px minmax(0, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .editor-controls .btn,
  .editor-controls #elementControls { grid-column: 1 / -1; }
}

@media (max-width: 680px) {
  .workspace { display: block; }
  .side-tabs {
    position: sticky;
    top: 63px;
    z-index: 4;
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    margin: 0 -12px 14px;
    padding: 6px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
    -webkit-overflow-scrolling: touch;
  }
  .side-tabs::-webkit-scrollbar { display: none; }
  .side-tab { flex: 0 0 auto; padding: 0 11px; }
  .editor-controls { display: block; }
  .action-grid .wide { grid-column: auto; }
  .topbar { padding: calc(8px + env(safe-area-inset-top)) 12px 8px; }
  .userbox > span { display: none; }
  main { padding: 12px 12px calc(70px + env(safe-area-inset-bottom)); }
  .tool-section { padding: 14px; }
  .btn { justify-content: center; }
  .form-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    padding-top: 24px;
    background: linear-gradient(transparent, var(--bg) 28%);
  }
  .form-actions .btn { width: 100%; }
  .canvas-wrap { min-height: 220px; padding: 6px; }
  .upload-drop { min-height: 62px; }
  .frame-position-actions { grid-template-columns: 1fr; }
  .role-frame-row { grid-template-columns: minmax(0, 1fr) 88px 44px; }
  .toast {
    max-width: calc(100vw - 24px);
    bottom: calc(16px + env(safe-area-inset-bottom));
    text-align: center;
  }
}
@font-face { font-family: "Inter"; src: url("/fonts/Inter.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "Lora"; src: url("/fonts/Lora.ttf") format("truetype"); font-display: swap; }
@font-face { font-family: "Space Mono"; src: url("/fonts/SpaceMono.ttf") format("truetype"); font-display: swap; }
