/*
 * shadcn/ui-inspired presentation layer for the simulator.
 * The existing Django markup and JavaScript behavior remain authoritative;
 * this file supplies the neutral tokens, compact controls, cards, tabs, and
 * focus treatment associated with the shadcn component system.
 */

body.material-theme.shadcn-simulator {
  --background: 210 40% 98%;
  --foreground: 222.2 47.4% 11.2%;
  --card: 0 0% 100%;
  --card-foreground: 222.2 47.4% 11.2%;
  --primary: 173 80% 24%;
  --primary-foreground: 210 40% 98%;
  --secondary: 210 40% 96.1%;
  --secondary-foreground: 222.2 47.4% 11.2%;
  --muted-ui: 210 40% 96.1%;
  --muted-ui-foreground: 215.4 16.3% 46.9%;
  --accent-ui: 166 36% 93%;
  --accent-ui-foreground: 173 80% 20%;
  --destructive: 0 72.2% 50.6%;
  --destructive-foreground: 210 40% 98%;
  --border-ui: 214 24% 79%;
  --input-ui: 214 24% 76%;
  --ring-ui: 173 80% 24%;
  --radius-ui: 0.75rem;

  --bg: hsl(var(--background));
  --panel: hsl(var(--card));
  --panel-soft: hsl(var(--muted-ui));
  --line: hsl(var(--border-ui));
  --text: hsl(var(--foreground));
  --muted: hsl(var(--muted-ui-foreground));
  --accent: hsl(var(--primary));
  --accent-strong: hsl(173 83% 18%);
  --danger: hsl(var(--destructive));
  --shadow: 0 1px 2px hsl(222 47% 11% / 0.06), 0 4px 12px hsl(222 47% 11% / 0.07);

  --md-primary: hsl(var(--primary));
  --md-on-primary: hsl(var(--primary-foreground));
  --md-primary-container: hsl(var(--accent-ui));
  --md-on-primary-container: hsl(var(--accent-ui-foreground));
  --md-secondary-container: hsl(var(--secondary));
  --md-on-secondary-container: hsl(var(--secondary-foreground));
  --md-surface: hsl(var(--background));
  --md-surface-container-low: hsl(var(--background));
  --md-surface-container: hsl(var(--secondary));
  --md-surface-container-high: hsl(210 40% 94%);
  --md-surface-container-highest: hsl(210 32% 91%);
  --md-surface-container-lowest: hsl(var(--card));
  --md-on-surface: hsl(var(--foreground));
  --md-on-surface-variant: hsl(var(--muted-ui-foreground));
  --md-outline: hsl(215 20% 65%);
  --md-outline-variant: hsl(var(--border-ui));
  --md-error: hsl(var(--destructive));
  --md-error-container: hsl(0 86% 97%);
  --md-elevation-1: var(--shadow);

  background:
    radial-gradient(circle at 50% -16rem, hsl(166 50% 91% / 0.7), transparent 38rem),
    hsl(var(--background));
  color: hsl(var(--foreground));
  font-family: Inter, "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
}

body.material-theme.shadcn-simulator :where(button, input, select, textarea) {
  font-family: inherit;
}

body.material-theme.shadcn-simulator .topbar {
  position: relative;
  z-index: 20;
  height: 76px;
  gap: 18px;
  padding: 12px 18px;
  border-bottom: 1px solid hsl(var(--border-ui));
  background: hsl(var(--card) / 0.94);
  color: hsl(var(--foreground));
  box-shadow: 0 1px 0 hsl(var(--foreground) / 0.02);
  backdrop-filter: blur(16px);
}

body.material-theme.shadcn-simulator .site-logo-link {
  border-radius: calc(var(--radius-ui) - 2px);
  box-shadow: 0 0 0 1px hsl(var(--border-ui));
}

body.material-theme.shadcn-simulator .top-nav {
  min-height: 44px;
  gap: 3px;
  padding: 4px;
  border: 1px solid hsl(var(--border-ui));
  border-radius: calc(var(--radius-ui) + 2px);
  background: hsl(var(--muted-ui));
}

body.material-theme.shadcn-simulator .top-link {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: calc(var(--radius-ui) - 3px);
  background: transparent;
  color: hsl(var(--muted-ui-foreground));
  font-size: 13px;
  font-weight: 600;
}

body.material-theme.shadcn-simulator .top-link:hover {
  background: hsl(var(--card) / 0.7);
  color: hsl(var(--foreground));
}

body.material-theme.shadcn-simulator .top-link.active {
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: var(--shadow);
}

body.material-theme.shadcn-simulator .top-link.active::after {
  display: none;
}

body.material-theme.shadcn-simulator .top-link.disabled {
  color: hsl(var(--muted-ui-foreground) / 0.55);
}

body.material-theme.shadcn-simulator .run-actions {
  gap: 8px;
}

body.material-theme.shadcn-simulator .button-leading-icon {
  display: inline-grid;
  width: 18px;
  height: 18px;
  place-items: center;
  font-size: 10px;
  line-height: 1;
}

body.material-theme.shadcn-simulator :where(.primary-button, .ghost-button, .icon-button) {
  min-height: 38px;
  border-radius: calc(var(--radius-ui) - 3px);
  font-size: 13px;
  font-weight: 600;
  box-shadow: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

body.material-theme.shadcn-simulator .primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid hsl(var(--primary));
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: 0 1px 2px hsl(var(--primary) / 0.25);
}

body.material-theme.shadcn-simulator .primary-button:hover {
  border-color: hsl(173 83% 19%);
  background: hsl(173 83% 19%);
  box-shadow: 0 2px 5px hsl(var(--primary) / 0.22);
}

body.material-theme.shadcn-simulator .ghost-button {
  border: 1px solid hsl(var(--border-ui));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
}

body.material-theme.shadcn-simulator .ghost-button:hover {
  border-color: hsl(var(--border-ui));
  background: hsl(var(--muted-ui));
}

body.material-theme.shadcn-simulator .danger-button {
  border-color: hsl(var(--destructive) / 0.28);
  background: hsl(var(--card));
  color: hsl(var(--destructive));
}

body.material-theme.shadcn-simulator .danger-button:hover {
  border-color: hsl(var(--destructive) / 0.4);
  background: hsl(0 86% 97%);
  color: hsl(0 72% 43%);
}

body.material-theme.shadcn-simulator :where(button, input, select, textarea):focus-visible {
  outline: 2px solid hsl(var(--ring-ui));
  outline-offset: 2px;
}

body.material-theme.shadcn-simulator :where(input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea) {
  min-height: 38px;
  border: 1px solid hsl(var(--input-ui));
  border-radius: calc(var(--radius-ui) - 3px);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px hsl(var(--foreground) / 0.025);
}

body.material-theme.shadcn-simulator :where(input, textarea)::placeholder {
  color: hsl(var(--muted-ui-foreground) / 0.7);
}

body.material-theme.shadcn-simulator :where(input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), select, textarea):focus {
  border-color: hsl(var(--ring-ui));
  outline: 0;
  box-shadow: 0 0 0 3px hsl(var(--ring-ui) / 0.14);
}

/* Bulma wraps selects in .ui-bulma-select. Keep the wrapper and its control
   on the same row height as number inputs in every training editor. */
body.material-theme.shadcn-simulator :where(.slot-status-grid, .formation-editor-compact-grid) > label {
  grid-template-rows: minmax(22px, auto) 38px;
  align-content: start;
}

body.material-theme.shadcn-simulator :where(
  .slot-status-grid,
  .slot-equipment-grid,
  .formation-editor-compact-grid,
  .formation-editor-compact-equipment
) .ui-bulma-select,
body.material-theme.shadcn-simulator :where(.slot-status-grid, .formation-editor-compact-grid) .cube-field-row {
  width: 100%;
  min-width: 0;
  height: 38px;
  min-height: 38px;
  align-self: center;
}

body.material-theme.shadcn-simulator :where(
  .slot-status-grid,
  .slot-equipment-grid,
  .formation-editor-compact-grid,
  .formation-editor-compact-equipment
) .ui-bulma-select > select {
  height: 38px;
  min-height: 38px;
}

body.material-theme.shadcn-simulator :where(.additional-buff-row, .buff-add-controls) .ui-bulma-select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  height: 38px;
  min-height: 38px;
}

body.material-theme.shadcn-simulator :where(.additional-buff-row, .buff-add-controls) .ui-bulma-select > select {
  width: 100%;
  min-width: 0;
  height: 38px;
  min-height: 38px;
}

body.material-theme.shadcn-simulator .app-shell {
  gap: 16px;
  padding: 16px;
  background: transparent;
}

body.material-theme.shadcn-simulator :where(.library-pane, .setup-pane, .results-pane) {
  border: 1px solid hsl(var(--border-ui));
  border-radius: var(--radius-ui);
  background: hsl(var(--card));
  box-shadow: var(--shadow);
}

body.material-theme.shadcn-simulator .pane-head {
  min-height: 58px;
  padding: 12px 16px;
  border-bottom: 1px solid hsl(var(--border-ui));
  background: hsl(var(--card));
}

body.material-theme.shadcn-simulator .pane-head h2 {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

body.material-theme.shadcn-simulator .library-tabs {
  gap: 4px;
  margin: 12px 12px 0;
  padding: 4px;
  border: 0;
  border-radius: calc(var(--radius-ui) - 1px);
  background: hsl(var(--muted-ui));
}

body.material-theme.shadcn-simulator .library-tab {
  min-height: 36px;
  border: 0;
  border-radius: calc(var(--radius-ui) - 4px);
  background: transparent;
  color: hsl(var(--muted-ui-foreground));
  font-size: 13px;
  font-weight: 600;
}

body.material-theme.shadcn-simulator .library-tab.active {
  border: 0;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: var(--shadow);
}

body.material-theme.shadcn-simulator .unified-filter-accordion {
  margin: 10px 12px 0;
  overflow: hidden;
  border: 1px solid hsl(var(--border-ui));
  border-left: 1px solid hsl(var(--border-ui));
  border-radius: calc(var(--radius-ui) - 1px);
  background: hsl(var(--card));
  box-shadow: none;
}

body.material-theme.shadcn-simulator .unified-filter-accordion .filter-panel-toggle,
body.material-theme.shadcn-simulator .unified-filter-accordion .filter-panel-toggle.active,
body.material-theme.shadcn-simulator .unified-filter-accordion .filter-panel-toggle[aria-expanded="true"] {
  min-height: 40px;
  padding: 0 12px;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font-size: 13px;
  font-weight: 600;
}

body.material-theme.shadcn-simulator .unified-filter-accordion .filter-panel-toggle:hover {
  background: hsl(var(--muted-ui));
}

body.material-theme.shadcn-simulator .filter-panel-body {
  margin-inline: 12px;
  overflow: hidden;
  border: 1px solid hsl(var(--border-ui));
  border-top: 0;
  border-radius: 0 0 calc(var(--radius-ui) - 1px) calc(var(--radius-ui) - 1px);
}

body.material-theme.shadcn-simulator .catalog-search-row,
body.material-theme.shadcn-simulator .catalog-option-row {
  border-color: hsl(var(--border-ui));
  background: hsl(var(--card));
}

body.material-theme.shadcn-simulator .filter-row {
  border-color: hsl(var(--border-ui));
  background: hsl(var(--card));
}

body.material-theme.shadcn-simulator :where(.filter-button, .catalog-filter-icon) {
  border-color: transparent;
  border-radius: 999px;
  background: hsl(var(--muted-ui));
  color: hsl(var(--muted-ui-foreground));
  box-shadow: none;
}

body.material-theme.shadcn-simulator :where(.filter-button, .catalog-filter-icon):hover {
  border-color: hsl(var(--border-ui));
  background: hsl(var(--secondary));
  color: hsl(var(--foreground));
}

body.material-theme.shadcn-simulator :where(.filter-button, .catalog-filter-icon).active {
  border-color: hsl(var(--primary) / 0.3);
  background: hsl(var(--accent-ui));
  color: hsl(var(--accent-ui-foreground));
  box-shadow: none;
}

body.material-theme.shadcn-simulator .character-list {
  gap: 9px;
  padding: 12px;
}

body.material-theme.shadcn-simulator .character-item {
  height: auto !important;
  min-height: 0;
  overflow: hidden;
  border: 1px solid hsl(var(--border-ui));
  border-radius: calc(var(--radius-ui) - 2px);
  background: hsl(var(--card));
  box-shadow: none;
  grid-template-rows: auto 30px;
  aspect-ratio: auto !important;
  transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
}

body.material-theme.shadcn-simulator .character-icon,
body.material-theme.shadcn-simulator .slot-icon,
body.material-theme.shadcn-simulator .overload-icon,
body.material-theme.shadcn-simulator .cube-icon,
body.material-theme.shadcn-simulator .rotation-icon,
body.material-theme.shadcn-simulator .saved-formation-icon,
body.material-theme.shadcn-simulator .b3-thumb,
body.material-theme.shadcn-simulator .b3-mini-thumb {
  flex: 0 0 auto;
  aspect-ratio: 1 / 1;
}

body.material-theme.shadcn-simulator .character-item .character-icon {
  display: block;
  width: 100%;
  height: auto !important;
  min-height: 0;
  aspect-ratio: 1 / 1 !important;
}

/*
 * responsive.css used to stretch the icon into the remaining row height on
 * tablet-sized screens. Keep the card content-sized and give the thumbnail an
 * explicit square row so button/control defaults cannot collapse it.
 */
body.material-theme.shadcn-simulator .library-pane button.character-item,
body.material-theme.shadcn-simulator .b3-library-pane button.character-item {
  height: auto !important;
  min-height: 0 !important;
  grid-template-rows: auto 30px !important;
  aspect-ratio: auto !important;
  align-self: start;
}

body.material-theme.shadcn-simulator .library-pane button.character-item .character-icon,
body.material-theme.shadcn-simulator .b3-library-pane button.character-item .character-icon {
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  aspect-ratio: 1 / 1 !important;
}

body.material-theme.shadcn-simulator :where(.character-icon, .slot-icon, .overload-icon, .cube-icon, .rotation-icon, .saved-formation-icon, .b3-thumb, .b3-mini-thumb) img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

body.material-theme.shadcn-simulator .character-item .character-name {
  width: 100%;
  height: 30px;
  min-height: 30px;
  overflow: hidden;
}

body.material-theme.shadcn-simulator .character-item:hover {
  border-color: hsl(var(--primary) / 0.55);
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.08);
  transform: translateY(-1px);
}

body.material-theme.shadcn-simulator .options-band {
  margin: 12px;
  border: 0;
  background: transparent;
}

body.material-theme.shadcn-simulator .setup-accordion {
  overflow: hidden;
  border: 1px solid hsl(var(--border-ui));
  border-radius: var(--radius-ui);
  background: hsl(var(--card));
  box-shadow: var(--shadow);
}

body.material-theme.shadcn-simulator .unified-accordion {
  border-left: 1px solid hsl(var(--border-ui));
}

body.material-theme.shadcn-simulator .unified-accordion > summary,
body.material-theme.shadcn-simulator .unified-accordion[open] > summary {
  min-height: 54px;
  padding: 0 16px;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  font-size: 14px;
  font-weight: 650;
}

body.material-theme.shadcn-simulator .unified-accordion > summary:hover,
body.material-theme.shadcn-simulator .unified-accordion[open] > summary {
  background: hsl(var(--muted-ui));
}

body.material-theme.shadcn-simulator .setup-accordion-body {
  border-top-color: hsl(var(--border-ui));
  background: hsl(var(--card));
}

body.material-theme.shadcn-simulator .formation-pane-head {
  margin: 0 12px;
  padding: 4px 0 12px;
  border-bottom: 0;
  background: transparent;
}

body.material-theme.shadcn-simulator .formation-tabs-row {
  margin: 0 12px;
  padding: 4px;
  border: 1px solid hsl(var(--border-ui));
  border-radius: calc(var(--radius-ui) - 1px);
  background: hsl(var(--muted-ui));
}

body.material-theme.shadcn-simulator .formation-tab {
  min-height: 34px;
  border: 0;
  border-radius: calc(var(--radius-ui) - 4px);
  background: transparent;
  color: hsl(var(--muted-ui-foreground));
  font-weight: 600;
}

body.material-theme.shadcn-simulator .formation-tab.active {
  border: 0;
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  box-shadow: var(--shadow);
}

body.material-theme.shadcn-simulator .formation-tab-actions {
  gap: 4px;
}

body.material-theme.shadcn-simulator .formation-tab-actions > button {
  min-height: 32px;
  background: hsl(var(--card));
}

body.material-theme.shadcn-simulator .formation-name-row {
  gap: 10px;
  margin: 12px;
  padding: 14px;
  border: 1px solid hsl(var(--border-ui));
  border-radius: var(--radius-ui);
  background: hsl(var(--card));
}

body.material-theme.shadcn-simulator .formation-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  padding-inline: 12px;
  overflow-x: hidden;
}

body.material-theme.shadcn-simulator .formation-slot-row {
  min-width: 0;
}

body.material-theme.shadcn-simulator .slot {
  border: 1px solid hsl(var(--border-ui));
  border-radius: var(--radius-ui);
  background: hsl(var(--card));
  box-shadow: none;
}

body.material-theme.shadcn-simulator .slot:hover {
  border-color: hsl(var(--primary) / 0.45);
  background: hsl(var(--card));
  box-shadow: 0 0 0 3px hsl(var(--primary) / 0.07);
}

body.material-theme.shadcn-simulator .slot.active {
  border-color: hsl(var(--primary));
  background: hsl(var(--accent-ui));
  color: hsl(var(--foreground));
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.18);
}

body.material-theme.shadcn-simulator .slot-index {
  border-radius: 6px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

body.material-theme.shadcn-simulator :where(.formation-edit-launch, .formation-status-accordion, .formation-rotation-panel) {
  width: auto;
  min-width: 0;
  max-width: none;
  margin-inline: 0;
  border-color: hsl(var(--border-ui));
  border-radius: var(--radius-ui);
  box-shadow: none;
}

body.material-theme.shadcn-simulator .formation-edit-launch {
  min-height: 42px;
  margin-bottom: 12px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

body.material-theme.shadcn-simulator .formation-edit-launch:hover {
  background: hsl(173 83% 19%);
}

body.material-theme.shadcn-simulator .summary-grid {
  padding: 14px;
}

body.material-theme.shadcn-simulator .summary-total {
  min-height: 92px;
  border: 1px solid hsl(var(--border-ui));
  border-radius: var(--radius-ui);
  background: linear-gradient(135deg, hsl(var(--card)), hsl(var(--accent-ui) / 0.58));
  box-shadow: none;
}

body.material-theme.shadcn-simulator .summary-total strong {
  color: hsl(var(--primary));
  font-size: clamp(24px, 2.4vw, 34px);
  font-variant-numeric: tabular-nums;
}

body.material-theme.shadcn-simulator .status-pill {
  border: 1px solid hsl(var(--primary) / 0.18);
  border-radius: 999px;
  background: hsl(var(--accent-ui));
  color: hsl(var(--accent-ui-foreground));
  font-weight: 600;
}

body.material-theme.shadcn-simulator .result-list {
  padding: 0 14px 14px;
}

body.material-theme.shadcn-simulator :where(.result-row, .normal-result-formation, .normal-result-character-row) {
  border-color: hsl(var(--border-ui));
  border-radius: var(--radius-ui);
  background: hsl(var(--card));
  box-shadow: none;
}

body.material-theme.shadcn-simulator :where(.b3-result-modal-panel, .detail-panel, .formation-picker-modal) {
  border: 1px solid hsl(var(--border-ui));
  border-radius: calc(var(--radius-ui) + 4px);
  background: hsl(var(--card));
  box-shadow: 0 24px 70px hsl(var(--foreground) / 0.22);
}

body.material-theme.shadcn-simulator :where(.b3-result-modal-head, .detail-head) {
  border-color: hsl(var(--border-ui));
  background: hsl(var(--card));
}

/* Match the buffer-template editor: keep formation switches readable and
   move them below the title when the modal header is narrow. */
body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-head {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
  min-height: 0;
  padding: 8px 12px;
  border-bottom: 1px solid hsl(var(--border-ui));
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tabs {
  min-width: 0;
  gap: 6px;
  max-height: 114px;
  padding: 0 2px;
  overflow-x: hidden;
  overflow-y: auto;
  align-content: flex-start;
  scrollbar-gutter: stable;
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tab-item {
  box-sizing: border-box;
  flex: 0 0 156px;
  width: 156px;
  min-width: 156px;
  max-width: 156px;
  height: 34px;
  min-height: 34px;
  margin: 0 !important;
  border: 1px solid hsl(var(--border-ui));
  border-radius: calc(var(--radius-ui) - 3px) !important;
  background: hsl(var(--card));
  box-shadow: none;
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tab-item:hover {
  border-color: hsl(var(--primary) / 0.55);
  background: hsl(var(--accent-ui) / 0.45);
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tab-item.active {
  border-color: hsl(var(--primary));
  background: hsl(var(--accent-ui));
  box-shadow: 0 0 0 2px hsl(var(--primary) / 0.12);
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tabs .formation-tab {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  max-width: none;
  height: 32px;
  min-height: 32px;
  margin: 0 !important;
  padding: 0 10px;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: hsl(var(--muted-ui-foreground));
  box-shadow: none !important;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  justify-content: flex-start;
  white-space: nowrap;
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tab-item.active .formation-tab,
body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tab-item:hover .formation-tab {
  color: hsl(var(--foreground));
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-add-formation,
body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-head > .icon-button:last-child {
  box-sizing: border-box;
  flex: 0 0 34px;
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  margin: 0 !important;
  border: 1px solid hsl(var(--border-ui));
  border-radius: calc(var(--radius-ui) - 3px) !important;
  background: hsl(var(--card));
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-add-formation {
  color: hsl(var(--primary));
}

body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-add-formation:hover {
  border-color: hsl(var(--primary) / 0.55);
  background: hsl(var(--accent-ui));
}

body.material-theme.shadcn-simulator .mobile-library-toggle {
  border: 1px solid hsl(var(--primary));
  border-radius: 999px;
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: 0 8px 24px hsl(var(--primary) / 0.28);
}

@media (max-width: 1180px) {
  body.material-theme.shadcn-simulator .top-link {
    padding-inline: 9px;
    font-size: 12px;
  }
}

@media (min-width: 768px) and (max-width: 1200px) {
  body.material-theme.shadcn-simulator .topbar {
    height: auto;
    min-height: 76px;
  }
}

@media (max-width: 767px) {
  body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-head {
    grid-template-columns: minmax(0, 1fr) 40px;
    grid-template-rows: auto auto;
    gap: 10px;
    padding: 12px;
  }

  body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-title {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
  }

  body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-tab-item {
    flex-basis: calc((100% - 6px) / 2);
    width: calc((100% - 6px) / 2);
    min-width: calc((100% - 6px) / 2);
    max-width: calc((100% - 6px) / 2);
  }

  body.material-theme.shadcn-simulator #bulkFormationModal .formation-editor-head > .icon-button:last-child {
    grid-column: 2;
    grid-row: 1;
  }

  body.material-theme.shadcn-simulator .topbar {
    height: auto;
    min-height: 0;
    gap: 8px;
    padding: 9px 10px 10px;
  }

  body.material-theme.shadcn-simulator .top-nav {
    margin: 0;
    padding: 3px;
  }

  body.material-theme.shadcn-simulator .top-link {
    min-height: 36px;
    height: 36px;
    padding-inline: 2px;
    font-size: clamp(9px, 2.7vw, 11px);
  }

  body.material-theme.shadcn-simulator .run-actions {
    gap: 8px;
  }

  body.material-theme.shadcn-simulator .run-actions .primary-button {
    min-height: 42px;
  }

  body.material-theme.shadcn-simulator .app-shell {
    gap: 12px;
    padding: 12px 10px 76px;
  }

  body.material-theme.shadcn-simulator .character-list {
    grid-auto-rows: max-content;
    align-items: start;
    gap: 8px;
  }

  body.material-theme.shadcn-simulator button.character-item {
    width: 100%;
    height: auto !important;
    min-height: 0;
    padding: 6px;
    display: grid;
    grid-template-rows: auto 30px !important;
    align-self: start;
    aspect-ratio: auto !important;
    overflow: hidden;
    white-space: normal;
  }

  body.material-theme.shadcn-simulator .character-item .character-icon {
    width: 100%;
    height: auto !important;
    min-height: 0;
    aspect-ratio: 1 / 1;
    align-self: start;
  }

  body.material-theme.shadcn-simulator .character-item .character-name {
    width: 100%;
    height: 30px;
    min-height: 30px;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    white-space: normal;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .slot-status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 10px;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .slot-status-grid > label {
    min-width: 0;
    grid-template-rows: auto 38px;
    align-content: stretch;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .slot-status-grid :where(input, select, .cube-field-row) {
    width: 100%;
    min-width: 0;
    height: 38px;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .cube-field-row {
    grid-template-columns: 34px minmax(0, 1fr);
  }

  body.material-theme.shadcn-simulator .formation-status-panel .cube-icon {
    width: 34px;
    height: 34px;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .slot-equipment-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    padding: 10px;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .slot-equipment-grid label {
    grid-template-columns: 58px 76px minmax(0, 1fr);
    gap: 7px;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .slot-equipment-grid :where(input, select) {
    width: 100%;
    min-width: 0;
    height: 38px;
  }

  body.material-theme.shadcn-simulator .formation-status-panel .slot-overload-grid,
  body.material-theme.shadcn-simulator .formation-editor-compact-overload-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  body.material-theme.shadcn-simulator :where(.formation-status-panel, .formation-editor-compact-overload-grid) .slot-overload-part {
    min-width: 0;
    gap: 9px;
    padding: 11px;
    border-radius: calc(var(--radius-ui) - 2px);
  }

  body.material-theme.shadcn-simulator .overload-part-head {
    min-width: 0;
    flex-wrap: wrap;
  }

  body.material-theme.shadcn-simulator .overload-copy-tools {
    margin-left: auto;
  }

  body.material-theme.shadcn-simulator .overload-copy-tools button {
    min-height: 32px;
    padding-inline: 9px;
    font-size: 11px;
  }

  body.material-theme.shadcn-simulator .overload-option-row {
    grid-template-columns: minmax(0, 1fr) minmax(84px, 0.7fr);
    gap: 8px;
  }

  body.material-theme.shadcn-simulator .overload-option-row select {
    width: 100%;
    min-width: 0;
    height: 38px;
  }

  body.material-theme.shadcn-simulator .formation-editor-compact-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  body.material-theme.shadcn-simulator .formation-editor-compact-grid :where(input, select) {
    height: 38px;
  }

  body.material-theme.shadcn-simulator .formation-editor-compact-equipment {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
  }

  body.material-theme.shadcn-simulator .formation-editor-compact-equipment > strong {
    grid-column: auto;
  }

  body.material-theme.shadcn-simulator .formation-editor-compact-equipment label {
    grid-template-columns: 58px 72px auto minmax(48px, 1fr);
    gap: 6px;
  }

  body.material-theme.shadcn-simulator .formation-editor-compact-equipment :where(input, select) {
    height: 38px;
  }

  body.material-theme.shadcn-simulator :where(.setup-pane, .results-pane) {
    border-radius: calc(var(--radius-ui) + 2px);
  }

  body.material-theme.shadcn-simulator .formation-name-row {
    grid-template-columns: 1fr;
  }

  body.material-theme.shadcn-simulator .mobile-library-drawer.library-pane {
    border: 0;
    border-right: 1px solid hsl(var(--border-ui));
    border-radius: 0 16px 16px 0;
    box-shadow: 12px 0 40px hsl(var(--foreground) / 0.2);
  }

  body.material-theme.shadcn-simulator .mobile-library-close {
    border-color: hsl(var(--border-ui));
    background: hsl(var(--card));
    color: hsl(var(--foreground));
    box-shadow: var(--shadow);
  }
}
