:root{
  --ms-thumb: 120px;
}

.media-studio {
  max-width: 720px;
  margin: 0 auto;
  animation: msFade 0.25s ease;
}

@keyframes msFade {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.ms-tabs {
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.sub-tab-bar {
  margin: 0 0 14px 0;
  flex-wrap: wrap;
}

.ms-body {
  padding: 4px 0;
}

/* Reference picker */
.ms-reference {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  flex-wrap: wrap;
}

.ms-ref-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.ms-ref-name {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.ms-ref-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Gallery */
.ms-gallery-controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.ms-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.ms-item {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.ms-item:hover {
  border-color: var(--lilu);
  transform: translateY(-2px);
}

.ms-preview-wrap {
  height: var(--ms-thumb);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.ms-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ms-thumb-audio {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.ms-meta {
  display: flex;
  justify-content: space-between;
  padding: 8px 10px 0;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ms-prompt {
  padding: 6px 10px;
  font-size: 12px;
  color: var(--fg);
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ms-actions {
  display: flex;
  gap: 4px;
  padding: 0 8px 8px;
  flex-wrap: wrap;
}

.ms-actions .btn {
  padding: 5px 8px;
  font-size: 11px;
  border-radius: 8px;
}

.ms-rating {
  position: absolute;
  top: 6px;
  right: 6px;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-weight: 700;
}

.ms-rating.pos { color: var(--ok); border-color: rgba(127, 220, 160, 0.4); }
.ms-rating.neg { color: var(--err); border-color: rgba(255, 154, 154, 0.4); }

/* Vision labels */
.ms-labels {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.ms-label {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 12px;
  color: var(--fg);
}

.ms-vision-file {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}

/* Prompt display under result */
.ms-result-prompt {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 760px) {
  .media-studio {
    padding: 0 4px;
  }

  .ms-gallery {
    grid-template-columns: repeat(2, 1fr);
  }

  .ms-actions .btn {
    padding: 5px 6px;
    font-size: 10px;
  }

  .ms-ref-name {
    max-width: 120px;
  }
}

@media (max-width: 420px) {
  .ms-gallery {
    grid-template-columns: 1fr;
  }
}

.ms-edit-desktop {
  display: none;
}

.ms-edit-mobile {
  display: block;
}

.ms-edit-left,
.ms-edit-right {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 220px;
  flex-shrink: 0;
}

.ms-edit-left {
  width: 120px;
}

.ms-edit-tools {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ms-tool {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ms-tool:hover,
.ms-tool:focus {
  border-color: var(--lilu);
  box-shadow: 0 0 0 2px var(--lilu-soft);
  outline: none;
}

.ms-tool.active {
  border-color: var(--lilu);
  background: var(--lilu-soft);
  color: var(--lilu);
}

.ms-edit-brush-size {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.ms-edit-brush-size label {
  font-size: 12px;
  color: var(--muted);
}

.ms-edit-brush-size input[type="range"] {
  width: 100%;
}

.ms-edit-canvas-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: auto;
  padding: 8px;
}

.ms-edit-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  border-radius: 8px;
  cursor: crosshair;
}

.ms-edit-ref {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
}

.ms-edit-ref-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.ms-edit-ref-name {
  flex: 1;
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

@media (min-width: 1024px) {
  .media-studio {
    max-width: none;
    margin: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  .ms-body {
    flex: 1;
    min-height: 0;
  }

  .ms-edit-desktop {
    display: flex;
    gap: 16px;
    min-height: 0;
    height: 100%;
  }

  .ms-edit-mobile {
    display: none;
  }

  .ms-edit-right {
    overflow-y: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .media-studio,
  .ms-item,
  .btn,
  .ms-tool {
    animation: none !important;
    transition: none !important;
  }
}
